mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Cosmetics.
This commit is contained in:
parent
a85d7aea25
commit
c5bdc34618
19 changed files with 140 additions and 169 deletions
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite;
|
||||
|
||||
|
@ -27,7 +27,6 @@ import org.eclipse.jface.text.TextSelection;
|
|||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public abstract class RewriteBaseTest extends BaseTestFramework implements ILogListener{
|
||||
protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
|
||||
|
@ -49,37 +48,37 @@ public abstract class RewriteBaseTest extends BaseTestFramework implements ILogL
|
|||
|
||||
@Override
|
||||
protected abstract void runTest() throws Throwable;
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
for (TestSourceFile testFile : fileMap.values()) {
|
||||
if(testFile.getSource().length() > 0) {
|
||||
if (testFile.getSource().length() > 0) {
|
||||
importFile(testFile.getName(), testFile.getSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertEquals(TestSourceFile file, IFile file2) throws Exception {
|
||||
StringBuffer code = getCodeFromIFile(file2);
|
||||
StringBuilder code = getCodeFromFile(file2);
|
||||
assertEquals(file.getExpectedSource(), TestHelper.unifyNewLines(code.toString()));
|
||||
}
|
||||
|
||||
protected void compareFiles(Map<String,TestSourceFile> testResourceFiles) throws Exception {
|
||||
protected void compareFiles(Map<String, TestSourceFile> testResourceFiles) throws Exception {
|
||||
for (String fileName : testResourceFiles.keySet()) {
|
||||
TestSourceFile file = testResourceFiles.get(fileName);
|
||||
IFile iFile = project.getFile(new Path(fileName));
|
||||
StringBuffer code = getCodeFromIFile(iFile);
|
||||
assertEquals(TestHelper.unifyNewLines(file.getExpectedSource()), TestHelper.unifyNewLines(code.toString()));
|
||||
StringBuilder code = getCodeFromFile(iFile);
|
||||
assertEquals(TestHelper.unifyNewLines(file.getExpectedSource()),
|
||||
TestHelper.unifyNewLines(code.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
protected StringBuffer getCodeFromIFile(IFile file) throws Exception {
|
||||
protected StringBuilder getCodeFromFile(IFile file) throws Exception {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(file.getContents()));
|
||||
StringBuffer code = new StringBuffer();
|
||||
StringBuilder code = new StringBuilder();
|
||||
String line;
|
||||
while((line = br.readLine()) != null) {
|
||||
while ((line = br.readLine()) != null) {
|
||||
code.append(line);
|
||||
code.append('\n');
|
||||
}
|
||||
|
@ -96,10 +95,10 @@ public abstract class RewriteBaseTest extends BaseTestFramework implements ILogL
|
|||
|
||||
public void logging(IStatus status, String plugin) {
|
||||
Throwable ex = status.getException();
|
||||
StringBuffer stackTrace = new StringBuffer();
|
||||
if(ex != null) {
|
||||
StringBuilder stackTrace = new StringBuilder();
|
||||
if (ex != null) {
|
||||
stackTrace.append('\n');
|
||||
for(StackTraceElement ste : ex.getStackTrace()) {
|
||||
for (StackTraceElement ste : ex.getStackTrace()) {
|
||||
stackTrace.append(ste.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite;
|
||||
|
||||
|
@ -33,10 +33,8 @@ import org.osgi.framework.Bundle;
|
|||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class RewriteTester extends TestSuite{
|
||||
|
||||
public class RewriteTester extends TestSuite {
|
||||
enum MatcherState{skip, inTest, inSource, inExpectedResult}
|
||||
|
||||
private static final String classRegexp = "//#(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
|
||||
|
@ -44,7 +42,7 @@ public class RewriteTester extends TestSuite{
|
|||
private static final String fileRegexp = "//@(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
|
||||
private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$
|
||||
|
||||
public static Test suite(String name, String file)throws Exception {
|
||||
public static Test suite(String name, String file) throws Exception {
|
||||
BufferedReader in = createReader(file);
|
||||
|
||||
ArrayList<RewriteBaseTest> testCases = createTests(in);
|
||||
|
@ -60,7 +58,6 @@ public class RewriteTester extends TestSuite{
|
|||
}
|
||||
|
||||
private static ArrayList<RewriteBaseTest> createTests(BufferedReader inputReader) throws Exception {
|
||||
|
||||
String line;
|
||||
Vector<TestSourceFile> files = new Vector<TestSourceFile>();
|
||||
TestSourceFile actFile = null;
|
||||
|
@ -70,10 +67,9 @@ public class RewriteTester extends TestSuite{
|
|||
String className = null;
|
||||
boolean bevorFirstTest = true;
|
||||
|
||||
while ((line = inputReader.readLine()) != null){
|
||||
|
||||
if(lineMatchesBeginOfTest(line)) {
|
||||
if(!bevorFirstTest) {
|
||||
while ((line = inputReader.readLine()) != null) {
|
||||
if (lineMatchesBeginOfTest(line)) {
|
||||
if (!bevorFirstTest) {
|
||||
RewriteBaseTest test = createTestClass(className, testName, files);
|
||||
testCases.add(test);
|
||||
files = new Vector<TestSourceFile>();
|
||||
|
@ -84,27 +80,27 @@ public class RewriteTester extends TestSuite{
|
|||
testName = getNameOfTest(line);
|
||||
bevorFirstTest = false;
|
||||
continue;
|
||||
} else if (lineMatchesBeginOfResult(line)) {
|
||||
} else if (lineMatchesBeginOfResult(line)) {
|
||||
matcherState = MatcherState.inExpectedResult;
|
||||
continue;
|
||||
}else if (lineMatchesFileName(line)) {
|
||||
} else if (lineMatchesFileName(line)) {
|
||||
matcherState = MatcherState.inSource;
|
||||
actFile = new TestSourceFile(getFileName(line));
|
||||
files.add(actFile);
|
||||
continue;
|
||||
}else if(lineMatchesClassName(line)) {
|
||||
} else if (lineMatchesClassName(line)) {
|
||||
className = getNameOfClass(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(matcherState) {
|
||||
switch (matcherState) {
|
||||
case inSource:
|
||||
if(actFile != null) {
|
||||
if (actFile != null) {
|
||||
actFile.addLineToSource(line);
|
||||
}
|
||||
break;
|
||||
case inExpectedResult:
|
||||
if(actFile != null) {
|
||||
if (actFile != null) {
|
||||
actFile.addLineToExpectedSource(line);
|
||||
}
|
||||
break;
|
||||
|
@ -117,11 +113,8 @@ public class RewriteTester extends TestSuite{
|
|||
return testCases;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static RewriteBaseTest createTestClass(String className, String testName, Vector<TestSourceFile> files) throws Exception {
|
||||
|
||||
|
||||
private static RewriteBaseTest createTestClass(String className, String testName,
|
||||
Vector<TestSourceFile> files) throws Exception {
|
||||
try {
|
||||
Class<?> refClass = Class.forName(className);
|
||||
Class<?> paratypes[] = new Class[2];
|
||||
|
@ -134,7 +127,7 @@ public class RewriteTester extends TestSuite{
|
|||
RewriteBaseTest test = (RewriteBaseTest) ct.newInstance(arglist);
|
||||
for (TestSourceFile file : files) {
|
||||
TextSelection sel = file.getSelection();
|
||||
if(sel != null) {
|
||||
if (sel != null) {
|
||||
test.setFileWithSelection(file.getName());
|
||||
test.setSelection(sel);
|
||||
break;
|
||||
|
@ -142,7 +135,8 @@ public class RewriteTester extends TestSuite{
|
|||
}
|
||||
return test;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new Exception("Unknown TestClass: " + e.getMessage() + ". Make sure the test's sourcefile specifies a valid test class.");
|
||||
throw new Exception("Unknown TestClass: " + e.getMessage() +
|
||||
". Make sure the test's sourcefile specifies a valid test class.");
|
||||
} catch (SecurityException e) {
|
||||
throw new Exception("Security Exception during Test creation", e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
@ -160,18 +154,16 @@ public class RewriteTester extends TestSuite{
|
|||
|
||||
private static String getFileName(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(fileRegexp, line);
|
||||
if(matcherBeginOfTest.find())
|
||||
if (matcherBeginOfTest.find())
|
||||
return matcherBeginOfTest.group(1);
|
||||
else
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getNameOfClass(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(classRegexp, line);
|
||||
if(matcherBeginOfTest.find())
|
||||
if (matcherBeginOfTest.find())
|
||||
return matcherBeginOfTest.group(1);
|
||||
else
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean lineMatchesBeginOfTest(String line) {
|
||||
|
@ -192,10 +184,9 @@ public class RewriteTester extends TestSuite{
|
|||
|
||||
private static String getNameOfTest(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(testRegexp, line);
|
||||
if(matcherBeginOfTest.find())
|
||||
if (matcherBeginOfTest.find())
|
||||
return matcherBeginOfTest.group(1);
|
||||
else
|
||||
return "Not Named";
|
||||
return "Not Named";
|
||||
}
|
||||
|
||||
private static boolean lineMatchesBeginOfResult(String line) {
|
||||
|
@ -205,7 +196,7 @@ public class RewriteTester extends TestSuite{
|
|||
private static TestSuite createSuite(ArrayList<RewriteBaseTest> testCases, String name) {
|
||||
TestSuite suite = new TestSuite(name);
|
||||
Iterator<RewriteBaseTest> it = testCases.iterator();
|
||||
while(it.hasNext()) {
|
||||
while (it.hasNext()) {
|
||||
RewriteBaseTest subject =it.next();
|
||||
suite.addTest(subject);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite;
|
||||
|
||||
|
|
|
@ -18,10 +18,8 @@ import org.eclipse.jface.text.TextSelection;
|
|||
|
||||
/**
|
||||
* @author Emanuel Graf
|
||||
*
|
||||
*/
|
||||
public class TestSourceFile {
|
||||
|
||||
private static final String REPLACEMENT = ""; //$NON-NLS-1$
|
||||
private String name;
|
||||
private StringBuffer source = new StringBuffer();
|
||||
|
@ -39,29 +37,32 @@ public class TestSourceFile {
|
|||
super();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getExpectedSource() {
|
||||
String exp = expectedSource.toString();
|
||||
if(exp.length() == 0) {
|
||||
if (exp.length() == 0) {
|
||||
return getSource();
|
||||
}else {
|
||||
} else {
|
||||
return exp;
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source.toString();
|
||||
}
|
||||
|
||||
public void addLineToSource(String code) {
|
||||
Matcher start = createMatcherFromString(selectionStartLineRegex, code);
|
||||
if(start.matches()) {
|
||||
if (start.matches()) {
|
||||
selectionStart = start.start(2) + source.length();
|
||||
code = code.replaceAll(selectionStartRegex, REPLACEMENT);
|
||||
}
|
||||
Matcher end = createMatcherFromString(selectionEndLineRegex, code);
|
||||
if(end.matches()) {
|
||||
if (end.matches()) {
|
||||
selectionEnd = end.start(2) + source.length();
|
||||
code = code.replaceAll(selectionEndRegex, REPLACEMENT);
|
||||
}
|
||||
|
@ -75,11 +76,9 @@ public class TestSourceFile {
|
|||
}
|
||||
|
||||
public TextSelection getSelection() {
|
||||
if(selectionStart < 0 || selectionEnd <0 ) {
|
||||
if (selectionStart < 0 || selectionEnd <0 )
|
||||
return null;
|
||||
}else {
|
||||
return new TextSelection(selectionStart, selectionEnd -selectionStart);
|
||||
}
|
||||
return new TextSelection(selectionStart, selectionEnd -selectionStart);
|
||||
}
|
||||
|
||||
protected static Matcher createMatcherFromString(String pattern, String line) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite.astwriter;
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class ASTWriterTest extends RewriteBaseTest {
|
|||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
for (TestSourceFile testFile : fileMap.values()) {
|
||||
if(testFile.getSource().length() > 0) {
|
||||
if (testFile.getSource().length() > 0) {
|
||||
file = importFile(testFile.getName(), testFile.getSource());
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class ASTWriterTest extends RewriteBaseTest {
|
|||
ASTModificationMap map = new ASTModificationMap();
|
||||
map.getModificationsForNode(unit.getDeclarations()[0]);
|
||||
ASTWriter writer = new ASTWriter();
|
||||
return writer.write(unit, null, commentMap);
|
||||
return writer.write(unit, commentMap);
|
||||
}
|
||||
|
||||
protected ISourceCodeParser getParser(TestSourceFile testFile) throws Exception {
|
||||
|
@ -97,43 +97,37 @@ public class ASTWriterTest extends RewriteBaseTest {
|
|||
IScanner scanner = AST2BaseTest.createScanner(codeReader, language, ParserMode.COMPLETE_PARSE, scannerInfo);
|
||||
|
||||
ISourceCodeParser parser2 = null;
|
||||
if( language == ParserLanguage.CPP ) {
|
||||
if (language == ParserLanguage.CPP) {
|
||||
ICPPParserExtensionConfiguration config = null;
|
||||
if (useGNUExtensions){
|
||||
if (useGNUExtensions) {
|
||||
config = new GPPParserExtensionConfiguration();
|
||||
} else{
|
||||
} else {
|
||||
config = new ANSICPPParserExtensionConfiguration();
|
||||
}
|
||||
parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config );
|
||||
parser2 = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config);
|
||||
} else {
|
||||
ICParserExtensionConfiguration config = null;
|
||||
|
||||
if (useGNUExtensions){
|
||||
if (useGNUExtensions) {
|
||||
config = new GCCParserExtensionConfiguration();
|
||||
} else{
|
||||
} else {
|
||||
config = new ANSICParserExtensionConfiguration();
|
||||
}
|
||||
|
||||
parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config );
|
||||
parser2 = new GNUCSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config);
|
||||
}
|
||||
return parser2;
|
||||
}
|
||||
|
||||
private boolean getGNUExtension(TestSourceFile file) {
|
||||
if(file instanceof ASTWriterTestSourceFile) {
|
||||
return ((ASTWriterTestSourceFile)file).isUseGNUExtensions();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
if (file instanceof ASTWriterTestSourceFile)
|
||||
return ((ASTWriterTestSourceFile) file).isUseGNUExtensions();
|
||||
return false;
|
||||
}
|
||||
|
||||
private ParserLanguage getLanguage(TestSourceFile file) {
|
||||
if(file instanceof ASTWriterTestSourceFile) {
|
||||
return ((ASTWriterTestSourceFile)file).getParserLanguage();
|
||||
}
|
||||
else {
|
||||
return ParserLanguage.CPP;
|
||||
}
|
||||
if (file instanceof ASTWriterTestSourceFile)
|
||||
return ((ASTWriterTestSourceFile) file).getParserLanguage();
|
||||
return ParserLanguage.CPP;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite.astwriter;
|
||||
|
||||
|
@ -16,7 +16,6 @@ import org.eclipse.cdt.core.parser.tests.rewrite.TestSourceFile;
|
|||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public class ASTWriterTestSourceFile extends TestSourceFile {
|
||||
private ParserLanguage parserLanguage = ParserLanguage.CPP;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite.astwriter;
|
||||
|
||||
|
@ -17,35 +17,35 @@ import junit.framework.TestSuite;
|
|||
/**
|
||||
* @author Emanuel Graf
|
||||
*/
|
||||
public class AstWriterTestSuite{
|
||||
public class AstWriterTestSuite {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new TestSuite("AstWriterTests");
|
||||
suite.addTest(SourceRewriteTester.suite("ExpressionTests", "resources/rewrite/ASTWriterExpressionTestSource.awts"));
|
||||
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("DelcSpecifierTests", "resources/rewrite/ASTWriterDeclSpecTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester.suite("Commented DelcSpecifierTests",
|
||||
"resources/rewrite/ASTWriterCommentedDeclSpecTestSource.awts"));
|
||||
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("DeclaratorTests", "resources/rewrite/ASTWriterDeclaratorTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester.suite("Commented DeclaratorTests",
|
||||
"resources/rewrite/ASTWriterCommentedDeclaratorTestSource.awts"));
|
||||
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("StatementsTests", "resources/rewrite/ASTWriterStatementTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester.suite("Commented StatementsTests",
|
||||
"resources/rewrite/ASTWriterCommentedStatementTestSource.awts"));
|
||||
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("NameTests", "resources/rewrite/ASTWriterNameTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester.suite("Commented NameTests", "resources/rewrite/ASTWriterCommentedNameTestSource.awts"));
|
||||
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("InitializerTests", "resources/rewrite/ASTWriterInitializerTestSource.awts"));
|
||||
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("DeclarationTests", "resources/rewrite/ASTWriterDeclarationTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester.suite("Commented DeclarationTests",
|
||||
"resources/rewrite/ASTWriterCommentedDeclarationTestSource.awts"));
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("TemplatesTests", "resources/rewrite/ASTWriterTemplateTestSource.awts"));
|
||||
|
||||
|
||||
suite.addTest(SourceRewriteTester.suite("CommentTests", "resources/rewrite/ASTWriterCommentedTestSource.awts"));
|
||||
suite.addTest(SourceRewriteTester.suite("NewCommentTests", "resources/rewrite/ASTWriterCommentedTestSource2.awts"));
|
||||
suite.addTestSuite(ExpressionWriterTest.class);
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors: Pascal Kesseli (HSR) - Initial API and implementation
|
||||
* Contributors:
|
||||
* Pascal Kesseli (HSR) - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite.astwriter;
|
||||
|
||||
|
@ -182,8 +183,7 @@ public class ExpressionWriterTest extends TestCase {
|
|||
ICPPASTLambdaExpression lambda = new CPPASTLambdaExpression();
|
||||
CPPASTCompoundStatement stmt = new CPPASTCompoundStatement();
|
||||
stmt.addStatement(new CPPASTReturnStatement(new CPPASTLiteralExpression(
|
||||
IASTLiteralExpression.lk_integer_constant,
|
||||
new char[] { '7' })));
|
||||
IASTLiteralExpression.lk_integer_constant, new char[] { '7' })));
|
||||
lambda.setBody(stmt);
|
||||
return lambda;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite.astwriter;
|
||||
|
||||
|
@ -31,7 +31,6 @@ import org.eclipse.jface.text.TextSelection;
|
|||
import org.osgi.framework.Bundle;
|
||||
|
||||
public class SourceRewriteTester extends TestSuite {
|
||||
|
||||
private static final String testRegexp = "//!(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
|
||||
private static final String codeTypeRegexp = "//%(C|CPP)( GNU)?$"; //$NON-NLS-1$
|
||||
private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$
|
||||
|
@ -56,7 +55,7 @@ public class SourceRewriteTester extends TestSuite {
|
|||
private static TestSuite createSuite(ArrayList<RewriteBaseTest> testCases, String name) {
|
||||
TestSuite suite = new TestSuite(name);
|
||||
Iterator<RewriteBaseTest> it = testCases.iterator();
|
||||
while(it.hasNext()) {
|
||||
while (it.hasNext()) {
|
||||
RewriteBaseTest subject =it.next();
|
||||
suite.addTest(subject);
|
||||
}
|
||||
|
@ -77,10 +76,11 @@ public class SourceRewriteTester extends TestSuite {
|
|||
|
||||
protected static String getNameOfTest(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(testRegexp, line);
|
||||
if(matcherBeginOfTest.find())
|
||||
if (matcherBeginOfTest.find()) {
|
||||
return matcherBeginOfTest.group(1);
|
||||
else
|
||||
} else {
|
||||
return "Not Named";
|
||||
}
|
||||
}
|
||||
|
||||
protected static boolean lineMatchesBeginOfResult(String line) {
|
||||
|
@ -93,32 +93,32 @@ public class SourceRewriteTester extends TestSuite {
|
|||
MatcherState matcherState = MatcherState.skip;
|
||||
ArrayList<RewriteBaseTest> testCases = new ArrayList<RewriteBaseTest>();
|
||||
|
||||
while ((line = inputReader.readLine()) != null){
|
||||
if(lineMatchesBeginOfTest(line)) {
|
||||
while ((line = inputReader.readLine()) != null) {
|
||||
if (lineMatchesBeginOfTest(line)) {
|
||||
matcherState = MatcherState.inTest;
|
||||
file = new ASTWriterTestSourceFile("ASTWritterTest.h"); //$NON-NLS-1$
|
||||
testCases.add(createTestClass(getNameOfTest(line), file));
|
||||
continue;
|
||||
} else if (lineMatchesBeginOfResult(line)) {
|
||||
} else if (lineMatchesBeginOfResult(line)) {
|
||||
matcherState = MatcherState.inExpectedResult;
|
||||
continue;
|
||||
}else if (lineMatchesCodeType(line)) {
|
||||
} else if (lineMatchesCodeType(line)) {
|
||||
matcherState = MatcherState.inSource;
|
||||
if(file != null) {
|
||||
if (file != null) {
|
||||
file.setParserLanguage(getParserLanguage(line));
|
||||
file.setUseGNUExtensions(useGNUExtensions(line));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(matcherState) {
|
||||
switch (matcherState) {
|
||||
case inSource:
|
||||
if(file != null) {
|
||||
if (file != null) {
|
||||
file.addLineToSource(line);
|
||||
}
|
||||
break;
|
||||
case inExpectedResult:
|
||||
if(file != null) {
|
||||
if (file != null) {
|
||||
file.addLineToExpectedSource(line);
|
||||
}
|
||||
break;
|
||||
|
@ -131,11 +131,11 @@ public class SourceRewriteTester extends TestSuite {
|
|||
|
||||
protected static boolean useGNUExtensions(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(codeTypeRegexp, line);
|
||||
if(matcherBeginOfTest.find()) {
|
||||
if (matcherBeginOfTest.find()) {
|
||||
String codeType = matcherBeginOfTest.group(2);
|
||||
if(codeType == null) {
|
||||
if (codeType == null) {
|
||||
return false;
|
||||
}else {
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -144,11 +144,11 @@ public class SourceRewriteTester extends TestSuite {
|
|||
|
||||
protected static ParserLanguage getParserLanguage(String line) {
|
||||
Matcher matcherBeginOfTest = createMatcherFromString(codeTypeRegexp, line);
|
||||
if(matcherBeginOfTest.find()) {
|
||||
if (matcherBeginOfTest.find()) {
|
||||
String codeType = matcherBeginOfTest.group(1);
|
||||
if(codeType.equalsIgnoreCase("CPP")) { //$NON-NLS-1$
|
||||
if (codeType.equalsIgnoreCase("CPP")) { //$NON-NLS-1$
|
||||
return ParserLanguage.CPP;
|
||||
}else {
|
||||
} else {
|
||||
return ParserLanguage.C;
|
||||
}
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ public class SourceRewriteTester extends TestSuite {
|
|||
private static RewriteBaseTest createTestClass(String testName, ASTWriterTestSourceFile file) throws Exception {
|
||||
ASTWriterTest test = new ASTWriterTest(testName,file);
|
||||
TextSelection sel = file.getSelection();
|
||||
if(sel != null) {
|
||||
if (sel != null) {
|
||||
test.setFileWithSelection(file.getName());
|
||||
test.setSelection(sel);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,10 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
|
|||
super();
|
||||
}
|
||||
|
||||
public ChangeGeneratorTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, new NullProgressMonitor());
|
||||
|
@ -65,8 +69,7 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
|
|||
|
||||
changegenartor.generateChange(unit);
|
||||
Document doc = new Document(source);
|
||||
for (Change curChange : ((CompositeChange) changegenartor.getChange())
|
||||
.getChildren()) {
|
||||
for (Change curChange : ((CompositeChange) changegenartor.getChange()).getChildren()) {
|
||||
if (curChange instanceof TextFileChange) {
|
||||
TextFileChange textChange = (TextFileChange) curChange;
|
||||
textChange.getEdit().apply(doc);
|
||||
|
@ -77,10 +80,6 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
|
|||
|
||||
protected abstract ASTVisitor createModificator(ASTModificationStore modStore);
|
||||
|
||||
public ChangeGeneratorTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
System.gc();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator;
|
||||
|
||||
|
@ -21,7 +21,6 @@ import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.replace.Replace
|
|||
|
||||
/**
|
||||
* @author Thomas Corbat
|
||||
*
|
||||
*/
|
||||
public class ChangeGeneratorTestSuite{
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite.comenthandler;
|
||||
|
||||
|
@ -33,9 +33,12 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
* This test tests the behavoir of the class ASTCommenter. It checks if the ASTCommenter assigns the comments contained in an AST to the right ASTNodes.<br>
|
||||
* The source for the CommentHandling tests is located at /resources/rewrite/CommentHandlingTestSource.rts.<br>
|
||||
* This file contains the source code and the expected output for all the tests. Following a little example how such a test looks like:<br><br>
|
||||
* This test tests the behavior of the class ASTCommenter. It checks if the ASTCommenter assigns
|
||||
* the comments contained in an AST to the right ASTNodes.<br>
|
||||
* The source for the CommentHandling tests is located at
|
||||
* /resources/rewrite/CommentHandlingTestSource.rts.<br>
|
||||
* This file contains the source code and the expected output for all the tests.
|
||||
* Following a little example how such a test looks like:<br><br>
|
||||
*
|
||||
* <code><pre>
|
||||
* //!NameOfTheTest - will be used as JUnit test name
|
||||
|
@ -62,12 +65,13 @@ import org.eclipse.core.runtime.CoreException;
|
|||
*
|
||||
* The second line (//#org.eclipse.cdt...) indicates the test class (in this case this class).<br>
|
||||
* The "//=" indicates the beginning of the expected test result.<br>
|
||||
* The test result contains three sections (separated by "=>leading", "=>trailing" and "=>freestanding").<br>
|
||||
* Each section contains the raw signature of the node to which a comment is assigned plus " = " and the comment. If there are several comments
|
||||
* assigned to the same node they are concatenated with a " , ".
|
||||
* The test result contains three sections (separated by "=>leading", "=>trailing" and
|
||||
* "=>freestanding").<br>
|
||||
* Each section contains the raw signature of the node to which a comment is assigned plus " = "
|
||||
* and the comment. If there are several comments assigned to the same node they are concatenated
|
||||
* with a " , ".
|
||||
*
|
||||
* @author Guido Zgraggen IFS, Lukas Felber IFS
|
||||
*
|
||||
*/
|
||||
public class CommentHandlingTest extends RewriteBaseTest {
|
||||
|
||||
|
@ -88,12 +92,11 @@ public class CommentHandlingTest extends RewriteBaseTest {
|
|||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
|
||||
if (fileMap.size() == 0) {
|
||||
fail("No file for testing"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
for(String fileName : fileMap.keySet()) {
|
||||
for (String fileName : fileMap.keySet()) {
|
||||
TestSourceFile file = fileMap.get(fileName);
|
||||
NodeCommentMap nodeMap = ASTCommenter.getCommentedNodeMap(getUnit(fileName));
|
||||
|
||||
|
@ -105,8 +108,8 @@ public class CommentHandlingTest extends RewriteBaseTest {
|
|||
}
|
||||
|
||||
private StringBuilder buildExpectedResult(TestSourceFile file) {
|
||||
|
||||
Matcher matcher = Pattern.compile(CommentHandlingTest.getSeparatingRegexp(), Pattern.MULTILINE | Pattern.DOTALL).matcher(file.getExpectedSource());
|
||||
Matcher matcher = Pattern.compile(CommentHandlingTest.getSeparatingRegexp(),
|
||||
Pattern.MULTILINE | Pattern.DOTALL).matcher(file.getExpectedSource());
|
||||
if (!matcher.find()) {
|
||||
fail("Missing expected section. Expected result code must be of the following format:\n\"=>leading\n...\n=>trailing\n...\n=>freestanding\""); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -143,7 +146,6 @@ public class CommentHandlingTest extends RewriteBaseTest {
|
|||
StringBuilder output = new StringBuilder();
|
||||
for (IASTNode actNode : keyTree) {
|
||||
ArrayList<IASTComment> comments = map.get(actNode);
|
||||
|
||||
output.append(getSignature(actNode) + " = "); //$NON-NLS-1$
|
||||
boolean first = true;
|
||||
for (IASTComment actComment : comments) {
|
||||
|
@ -170,11 +172,13 @@ public class CommentHandlingTest extends RewriteBaseTest {
|
|||
}
|
||||
|
||||
private static String getSeparatingRegexp() {
|
||||
return LEADING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP + TRAILING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP + FREESTANDING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP;
|
||||
return LEADING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP + TRAILING_COMMENT_SEPARATOR +
|
||||
ANY_CHAR_REGEXP + FREESTANDING_COMMENT_SEPARATOR + ANY_CHAR_REGEXP;
|
||||
}
|
||||
|
||||
private IASTTranslationUnit getUnit(String fileName) throws CoreException {
|
||||
ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(project.getFile(fileName));
|
||||
ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(
|
||||
project.getFile(fileName));
|
||||
return tu.getAST();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite.comenthandler;
|
||||
|
||||
|
@ -18,18 +18,14 @@ import org.eclipse.cdt.core.parser.tests.rewrite.RewriteTester;
|
|||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public class CommentHandlingTestSuite extends TestSuite {
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
TestSuite suite = new TestSuite(CommentHandlingTestSuite.class.getName());
|
||||
|
||||
suite.addTest(RewriteTester.suite("CommentTests", "resources/rewrite/CommentHandlingTestSource.rts")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
suite.addTest(RewriteTester.suite("CommentTests",
|
||||
"resources/rewrite/CommentHandlingTestSource.rts")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
suite.addTestSuite(NodeCommentMapTest.class);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.rewrite.comenthandler;
|
||||
|
||||
|
@ -21,10 +21,8 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
|||
|
||||
/**
|
||||
* @author Guido Zgraggen IFS
|
||||
*
|
||||
*/
|
||||
public class NodeCommentMapTest extends TestCase {
|
||||
|
||||
private NodeCommentMap map;
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +37,6 @@ public class NodeCommentMapTest extends TestCase {
|
|||
|
||||
public void testNoComment(){
|
||||
ASTNode node = new CPPASTName();
|
||||
|
||||
assertEquals(0, map.getLeadingCommentsForNode(node).size());
|
||||
assertEquals(0, map.getTrailingCommentsForNode(node).size());
|
||||
assertEquals(0, map.getFreestandingCommentsForNode(node).size());
|
||||
|
@ -51,7 +48,6 @@ public class NodeCommentMapTest extends TestCase {
|
|||
IASTComment comm2 = new Comment();
|
||||
IASTComment comm3 = new Comment();
|
||||
|
||||
|
||||
map.addLeadingCommentToNode(node, comm1);
|
||||
map.addTrailingCommentToNode(node, comm2);
|
||||
map.addFreestandingCommentToNode(node, comm3);
|
||||
|
@ -88,8 +84,7 @@ public class NodeCommentMapTest extends TestCase {
|
|||
assertEquals(com1, map.getFreestandingCommentsForNode(node).get(0));
|
||||
assertEquals(com2, map.getFreestandingCommentsForNode(node).get(1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testCommentOnDifferentNodes(){
|
||||
ASTNode node1 = new CPPASTName();
|
||||
ASTNode node2 = new CPPASTName();
|
||||
|
@ -129,19 +124,22 @@ public class NodeCommentMapTest extends TestCase {
|
|||
assertEquals(com3, map.getFreestandingCommentsForNode(node1).get(1));
|
||||
}
|
||||
|
||||
|
||||
//=== InternalComment class for testing
|
||||
private class Comment extends ASTNode implements IASTComment{
|
||||
private class Comment extends ASTNode implements IASTComment {
|
||||
private char[] comment;
|
||||
|
||||
public char[] getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(char[] comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
//not used
|
||||
public boolean isBlockComment() {return false;}
|
||||
|
||||
// not used
|
||||
public boolean isBlockComment() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public IASTNode copy() {
|
||||
return null;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.togglefunction;
|
||||
|
||||
|
@ -21,8 +21,7 @@ import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleRefactoringC
|
|||
|
||||
public class MockToggleRefactoringTest extends ToggleRefactoring {
|
||||
|
||||
public MockToggleRefactoringTest(IFile file, TextSelection selection,
|
||||
ICProject proj) {
|
||||
public MockToggleRefactoringTest(IFile file, TextSelection selection, ICProject proj) {
|
||||
super(file, selection, proj);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,8 @@ import org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleNodeHelper;
|
|||
|
||||
/**
|
||||
* @author egraf
|
||||
*
|
||||
*/
|
||||
public class ToggleNodeHelperTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for {@link org.eclipse.cdt.internal.ui.refactoring.togglefunction.ToggleNodeHelper#getFilenameWithoutExtension(java.lang.String)}.
|
||||
*/
|
||||
|
@ -38,5 +36,4 @@ public class ToggleNodeHelperTest extends TestCase {
|
|||
public void testGetFilenameWithoutExtension2() {
|
||||
assertEquals("My.Class", ToggleNodeHelper.getFilenameWithoutExtension("My.Class.h"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.togglefunction;
|
||||
|
||||
|
@ -26,7 +26,6 @@ import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
|
|||
import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
|
||||
|
||||
public class ToggleRefactoringTest extends RefactoringTest {
|
||||
|
||||
private boolean fatalError;
|
||||
private boolean newFileCreation;
|
||||
private String[] newfiles;
|
||||
|
@ -117,5 +116,4 @@ public class ToggleRefactoringTest extends RefactoringTest {
|
|||
changes.perform(NULL_PROGRESS_MONITOR);
|
||||
compareFiles(fileMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Institute for Software - initial API and implementation
|
||||
* Institute for Software - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.refactoring.togglefunction;
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class ToggleRefactoringTestSuite extends TestSuite {
|
|||
"resources/refactoring/ToggleSimpleFunctionRefactoring.rts"));
|
||||
suite.addTest(RefactoringTester.suite("ToggleTemplateRefactoringTest",
|
||||
"resources/refactoring/ToggleTemplateRefactoring.rts"));
|
||||
suite.addTest(RefactoringTester.suite("ToggleNamespaceRefacotringTest",
|
||||
suite.addTest(RefactoringTester.suite("ToggleNamespaceRefactoringTest",
|
||||
"resources/refactoring/ToggleNamespaceRefactoring.rts"));
|
||||
suite.addTest(RefactoringTester.suite("ToggleTryCatchRefactoringTest",
|
||||
"resources/refactoring/ToggleTryCatchRefactoring.rts"));
|
||||
|
@ -49,7 +49,7 @@ public class ToggleRefactoringTestSuite extends TestSuite {
|
|||
"resources/refactoring/ToggleFreeFunction.rts"));
|
||||
suite.addTest(RefactoringTester.suite("ToggleVirtualFunctionTest",
|
||||
"resources/refactoring/ToggleVirtualFunction.rts"));
|
||||
suite.addTest(RefactoringTester.suite("ToggleOrderintTest",
|
||||
suite.addTest(RefactoringTester.suite("ToggleOrderingTest",
|
||||
"resources/refactoring/ToggleOrdering.rts"));
|
||||
suite.addTest(RefactoringTester.suite("ToggleCommentsClassToHeader",
|
||||
"resources/refactoring/ToggleCommentsClassToHeader.rts"));
|
||||
|
@ -62,5 +62,4 @@ public class ToggleRefactoringTestSuite extends TestSuite {
|
|||
suite.addTestSuite(ToggleNodeHelperTest.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue