mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Partial fix and tests for 192412
This commit is contained in:
parent
2cb3239e88
commit
d5b6be5359
4 changed files with 117 additions and 7 deletions
|
@ -0,0 +1,85 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.text;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.source.LineRange;
|
||||
|
||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.formatter.DefaultCodeFormatterOptions;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CDocumentSetupParticipant;
|
||||
import org.eclipse.cdt.internal.ui.editor.IndentUtil;
|
||||
import org.eclipse.cdt.internal.ui.text.CHeuristicScanner;
|
||||
import org.eclipse.cdt.internal.ui.text.CIndenter;
|
||||
|
||||
/**
|
||||
* Tests for the CIndenter.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class CIndenterTest extends BaseUITestCase {
|
||||
|
||||
private Map fOptions;
|
||||
private Map fDefaultOptions;
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(CIndenterTest.class, "_");
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fDefaultOptions= DefaultCodeFormatterOptions.getDefaultSettings().getMap();
|
||||
fOptions= new HashMap(fDefaultOptions);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected void assertIndenterResult() throws Exception {
|
||||
StringBuffer[] contents= getContentsForTest(2);
|
||||
String before= contents[0].toString();
|
||||
IDocument document= new Document(before);
|
||||
String expected= contents[1].toString();
|
||||
new CDocumentSetupParticipant().setup(document);
|
||||
CIndenter indenter= new CIndenter(document, new CHeuristicScanner(document));
|
||||
IndentUtil.indentLines(document, new LineRange(0, document.getNumberOfLines()), null, null);
|
||||
assertEquals(expected, document.get());
|
||||
}
|
||||
|
||||
//foo(arg,
|
||||
//"string");
|
||||
|
||||
//foo(arg,
|
||||
// "string");
|
||||
public void testIndentationOfStringAsLastArgument_Bug192412() throws Exception {
|
||||
assertIndenterResult();
|
||||
}
|
||||
|
||||
//if (1)
|
||||
//foo->bar();
|
||||
//dontIndent();
|
||||
|
||||
//if (1)
|
||||
// foo->bar();
|
||||
//dontIndent();
|
||||
public void testIndentationAfterArrowOperator_Bug192412() throws Exception {
|
||||
assertIndenterResult();
|
||||
}
|
||||
}
|
|
@ -33,6 +33,7 @@ public class TextTestSuite extends TestSuite {
|
|||
addTest(IndentActionTest.suite());
|
||||
addTest(FormatActionTest.suite());
|
||||
addTest(CodeFormatterTest.suite());
|
||||
addTest(CIndenterTest.suite());
|
||||
|
||||
// Break iterator tests.
|
||||
addTest(CBreakIteratorTest.suite());
|
||||
|
|
|
@ -301,6 +301,16 @@ public final class CHeuristicScanner implements Symbols {
|
|||
* @return a constant from {@link Symbols} describing the next token
|
||||
*/
|
||||
public int nextToken(int start, int bound) {
|
||||
try {
|
||||
// check for string or char literal
|
||||
char ch = fDocument.getChar(start);
|
||||
if (ch == '"' || ch == '\'') {
|
||||
fChar= ch;
|
||||
fPos= fNonWSDefaultPart.nextPosition(start, true);
|
||||
return TokenOTHER;
|
||||
}
|
||||
} catch (BadLocationException exc) {
|
||||
}
|
||||
int pos= scanForward(start, bound, fNonWSDefaultPart);
|
||||
if (pos == NOT_FOUND)
|
||||
return TokenEOF;
|
||||
|
@ -331,11 +341,23 @@ public final class CHeuristicScanner implements Symbols {
|
|||
case LANGLE:
|
||||
return TokenLESSTHAN;
|
||||
case RANGLE:
|
||||
if (peekNextChar() == RANGLE) {
|
||||
switch (peekNextChar()) {
|
||||
case RANGLE:
|
||||
++fPos;
|
||||
return TokenSHIFTRIGHT;
|
||||
}
|
||||
return TokenGREATERTHAN;
|
||||
case DOT:
|
||||
return TokenDOT;
|
||||
case MINUS:
|
||||
switch (peekNextChar()) {
|
||||
case RANGLE:
|
||||
++fPos;
|
||||
return TokenARROW;
|
||||
}
|
||||
return TokenMINUS;
|
||||
case TILDE:
|
||||
return TokenTILDE;
|
||||
}
|
||||
|
||||
// else
|
||||
|
@ -407,9 +429,13 @@ public final class CHeuristicScanner implements Symbols {
|
|||
case LANGLE:
|
||||
return TokenLESSTHAN;
|
||||
case RANGLE:
|
||||
if (peekPreviousChar() == RANGLE) {
|
||||
switch (peekPreviousChar()) {
|
||||
case RANGLE:
|
||||
--fPos;
|
||||
return TokenSHIFTRIGHT;
|
||||
case MINUS:
|
||||
--fPos;
|
||||
return TokenARROW;
|
||||
}
|
||||
return TokenGREATERTHAN;
|
||||
case DOT:
|
||||
|
@ -966,11 +992,8 @@ public final class CHeuristicScanner implements Symbols {
|
|||
if (token == Symbols.TokenDOT) {
|
||||
return true;
|
||||
}
|
||||
if (token == Symbols.TokenGREATERTHAN) {
|
||||
token= previousToken(getPosition(), bound);
|
||||
if (token == Symbols.TokenMINUS) {
|
||||
return true;
|
||||
}
|
||||
if (token == Symbols.TokenARROW) {
|
||||
return true;
|
||||
} else if (token == Symbols.TokenCOLON) {
|
||||
token= previousToken(getPosition(), bound);
|
||||
if (token == Symbols.TokenCOLON) {
|
||||
|
|
|
@ -35,6 +35,7 @@ public interface Symbols {
|
|||
int TokenMINUS= 16;
|
||||
int TokenTILDE= 17;
|
||||
int TokenSHIFTRIGHT= 18;
|
||||
int TokenARROW= 19;
|
||||
int TokenIF= 109;
|
||||
int TokenDO= 1010;
|
||||
int TokenFOR= 1011;
|
||||
|
|
Loading…
Add table
Reference in a new issue