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