| author | Marc Aubry | 2012-07-23 12:17:20 (EDT) |
|---|---|---|
| committer | sbernard | 2012-07-24 08:41:00 (EDT) |
| commit | bc1be7045c5a4cde38a1dfd24ee0fbb1b9e2f676 (patch) (side-by-side diff) | |
| tree | 52a29d7ab060fcec4fd0dd8bfe6bef276dcebe48 | |
| parent | 672c70087538d1906e3d8bdb401f3e4628f59125 (diff) | |
| download | org.eclipse.koneki.ldt-bc1be7045c5a4cde38a1dfd24ee0fbb1b9e2f676.zip org.eclipse.koneki.ldt-bc1be7045c5a4cde38a1dfd24ee0fbb1b9e2f676.tar.gz org.eclipse.koneki.ldt-bc1be7045c5a4cde38a1dfd24ee0fbb1b9e2f676.tar.bz2 | |
Intial commit of Scanner JUnit tests
and some enhancements of all ui tests
21 files changed, 730 insertions, 45 deletions
diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.koneki.ldt.ui.tests/META-INF/MANIFEST.MF index ed9b67f..b5e1e6d 100644 --- a/tests/org.eclipse.koneki.ldt.ui.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.koneki.ldt.ui.tests/META-INF/MANIFEST.MF @@ -12,8 +12,13 @@ Require-Bundle: org.eclipse.ui, org.eclipse.koneki.ldt.ui;bundle-version="0.8.0", org.eclipse.dltk.ui;bundle-version="3.0.0", org.eclipse.dltk.core;bundle-version="3.0.0", - org.eclipse.ui.editors + org.eclipse.ui.editors, + org.apache.commons.io;bundle-version="1.4.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.koneki.ldt.ui.tests, + org.eclipse.koneki.ldt.ui.tests.internal;x-internal:=true, + org.eclipse.koneki.ldt.ui.tests.internal.autoedit;x-internal:=true, + org.eclipse.koneki.ldt.ui.tests.internal.scanners;x-internal:=true, org.eclipse.koneki.ldt.ui.tests.internal.rules;x-internal:=true +Bundle-Activator: org.eclipse.koneki.ldt.ui.tests.internal.Activator diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/build.properties b/tests/org.eclipse.koneki.ldt.ui.tests/build.properties index bc4c475..903970f 100644 --- a/tests/org.eclipse.koneki.ldt.ui.tests/build.properties +++ b/tests/org.eclipse.koneki.ldt.ui.tests/build.properties @@ -12,7 +12,8 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ .,\ - OSGI-INF/ + OSGI-INF/,\ + tests/ javacProjectSettings = true javacDefaultEncoding.. = UTF-8 diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/AllUITests.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/AllUITests.java index 6f0c54a..ef68842 100644 --- a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/AllUITests.java +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/AllUITests.java @@ -10,6 +10,11 @@ *******************************************************************************/
package org.eclipse.koneki.ldt.ui.tests;
+import junit.framework.JUnit4TestAdapter;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
import org.eclipse.koneki.ldt.ui.tests.internal.LuaWordFinderTest;
@@ -19,13 +24,31 @@ import org.eclipse.koneki.ldt.ui.tests.internal.rules.LuaDocSingleCommentSeriesR import org.eclipse.koneki.ldt.ui.tests.internal.rules.LuaMultLineCommentRuleTest;
import org.eclipse.koneki.ldt.ui.tests.internal.rules.LuaMultLineStringRuleTest;
import org.eclipse.koneki.ldt.ui.tests.internal.rules.LuaNumberRuleTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
+import org.eclipse.koneki.ldt.ui.tests.internal.rules.LuaDocMultLineCommentTest;
+import org.eclipse.koneki.ldt.ui.tests.internal.rules.LuaDocSingleCommentSeriesRuleTest;
+import org.eclipse.koneki.ldt.ui.tests.internal.rules.LuaMultLineCommentRuleTest;
+import org.eclipse.koneki.ldt.ui.tests.internal.rules.LuaMultLineStringRuleTest;
+import org.eclipse.koneki.ldt.ui.tests.internal.rules.LuaNumberRuleTest;
+import org.eclipse.koneki.ldt.ui.tests.internal.scanners.LuaCodeScannerTestSuite;
+import org.eclipse.koneki.ldt.ui.tests.internal.scanners.LuaDocumentorScannerTestSuite;
+import org.eclipse.koneki.ldt.ui.tests.internal.scanners.LuaPartitionScannerTestSuite;
+
+public class AllUITests extends TestCase {
+
+ public static Test suite() {
+ final TestSuite suite = new TestSuite(AllUITests.class.getName());
+ suite.addTest(new LuaPartitionScannerTestSuite());
+ suite.addTest(new LuaCodeScannerTestSuite());
+ suite.addTest(new LuaDocumentorScannerTestSuite());
-@RunWith(Suite.class) -@SuiteClasses({ LuaWordFinderTest.class, LuaNumberRuleTest.class, LuaMultLineCommentRuleTest.class, LuaMultLineStringRuleTest.class,
- LuaDocMultLineCommentTest.class, LuaDocSingleCommentSeriesRuleTest.class, LuaDocumentorCommentAutoEditStrategyTest.class }) -public class AllUITests {
+ suite.addTest(new JUnit4TestAdapter(LuaNumberRuleTest.class));
+ suite.addTest(new JUnit4TestAdapter(LuaMultLineStringRuleTest.class));
+ suite.addTest(new JUnit4TestAdapter(LuaMultLineCommentRuleTest.class));
+ suite.addTest(new JUnit4TestAdapter(LuaDocMultLineCommentTest.class));
+ suite.addTest(new JUnit4TestAdapter(LuaDocSingleCommentSeriesRuleTest.class));
+ suite.addTest(new JUnit4TestAdapter(LuaDocumentorCommentAutoEditStrategyTest.class));
+ suite.addTest(new JUnit4TestAdapter(LuaWordFinderTest.class));
+ return suite;
+ }
}
diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/Activator.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/Activator.java new file mode 100644 index 0000000..9355c9a --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/Activator.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2009, 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.tests.internal; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.koneki.ldt.ui"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Log a error message caused by the given exception + * + * @param message + * message to log + * @param throwable + * exception which causes the error + */ + public static void logError(final String message, final Throwable throwable) { + IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, message, throwable); + getDefault().getLog().log(status); + } + + /** + * Log a simple warning message + * + * @param message + * message to log + */ + public static void logWarning(final String message) { + IStatus status = new Status(IStatus.WARNING, PLUGIN_ID, message); + getDefault().getLog().log(status); + } + + /** + * Log a warning message caused by the given exception + * + * @param message + * message to log + * @param throwable + * exception which causes the warning + */ + public static void logWarning(final String message, final Throwable throwable) { + IStatus status = new Status(IStatus.WARNING, PLUGIN_ID, message, throwable); + getDefault().getLog().log(status); + } + + /** + * Log the given status + * + * @param status + * status to log + */ + public static void log(final IStatus status) { + getDefault().getLog().log(status); + } + +} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/LuaWordFinderTest.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/LuaWordFinderTest.java index 93b4d1a..4405c54 100644 --- a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/LuaWordFinderTest.java +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/LuaWordFinderTest.java @@ -17,22 +17,14 @@ import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.koneki.ldt.ui.internal.editor.text.LuaWordFinder; +import org.junit.Test; /** * Tests for LuaWordFinder. */ public class LuaWordFinderTest extends TestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - + @Test public void testBasic() { IDocument doc = new Document(" foo:bar(arg1, arg2)"); //$NON-NLS-1$ // | foo:bar(arg1, arg2) @@ -81,6 +73,7 @@ public class LuaWordFinderTest extends TestCase { assertEquals(4, region.getLength()); } + @Test public void testWordAtEnd() { IDocument doc = new Document(" foo"); //$NON-NLS-1$ // |foo @@ -99,6 +92,7 @@ public class LuaWordFinderTest extends TestCase { assertEquals(0, region.getLength()); } + @Test public void testWordAtStart() { IDocument doc = new Document("foo "); //$NON-NLS-1$ // |foo diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/ScannerResult.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/ScannerResult.java new file mode 100644 index 0000000..2fa0edb --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/ScannerResult.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.tests.internal; + +import java.text.MessageFormat; + +import org.eclipse.jface.text.rules.IToken; + +public class ScannerResult { + + private IToken token; + private int offset; + private int lenght; + + public ScannerResult(IToken token2, int tokenOffset, int tokenLength) { + token = token2; + offset = tokenOffset; + lenght = tokenLength; + } + + public IToken getToken() { + return token; + } + + public int getOffset() { + return offset; + } + + public int getLenght() { + return lenght; + } + + @Override + public String toString() { + return MessageFormat.format("'{'{0};{1};{2}'}'\n", offset, lenght, token.getData()); //$NON-NLS-1$ + } +} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/rules/AbstractRuleTestCase.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/rules/AbstractRuleTestCase.java index 5ca4b61..042c92f 100644 --- a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/rules/AbstractRuleTestCase.java +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/rules/AbstractRuleTestCase.java @@ -23,10 +23,10 @@ import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.ITokenScanner; import org.eclipse.jface.text.rules.RuleBasedScanner; import org.eclipse.jface.text.rules.Token; +import org.eclipse.koneki.ldt.ui.tests.internal.ScannerResult; /** -<<<<<<< OURS - * An abstract class to perform JUnit tests on rules + * An abstract class to perform junit test on rules */ public abstract class AbstractRuleTestCase extends TestCase { @@ -45,21 +45,21 @@ public abstract class AbstractRuleTestCase extends TestCase { ITokenScanner scanner = createScanner(doc); boolean tokenFound = false; - List<TestResult> tokenList = new ArrayList<TestResult>(); + List<ScannerResult> tokenList = new ArrayList<ScannerResult>(); for (IToken token = scanner.nextToken(); token != Token.EOF; token = scanner.nextToken()) { if (token == expectedToken && scanner.getTokenOffset() == expectedOffset && scanner.getTokenLength() == expectedLength) { tokenFound = true; } - tokenList.add(new TestResult(token, scanner.getTokenOffset(), scanner.getTokenLength())); + tokenList.add(new ScannerResult(token, scanner.getTokenOffset(), scanner.getTokenLength())); } if (!tokenFound) { StringBuffer messageBuilder = new StringBuffer(); - messageBuilder.append(MessageFormat.format("For input:\"{0}\" expected token is [-Token={1} -Offset={2} -Length={3}] ", //$NON-NLS-1$ + messageBuilder.append(MessageFormat.format("For input:\"{0}\" expected token is [-Token={1} -Offset={2} -Lenght={3}] ", //$NON-NLS-1$ inputString.replace("\n", "\\n"), expectedToken.getData(), expectedOffset, expectedLength)); //$NON-NLS-1$//$NON-NLS-2$ if (tokenList.isEmpty()) { messageBuilder.append("but no token was found"); //$NON-NLS-1$ } else { - messageBuilder.append("\nbut token(s) found was:\n"); //$NON-NLS-1$ + messageBuilder.append("\nbut token(s) found were:\n"); //$NON-NLS-1$ appendTokenList(tokenList, messageBuilder, inputString); } fail(messageBuilder.toString()); @@ -71,13 +71,13 @@ public abstract class AbstractRuleTestCase extends TestCase { ITokenScanner scanner = createScanner(doc); boolean tokenFound = false; - List<TestResult> tokenList = new ArrayList<TestResult>(); + List<ScannerResult> tokenList = new ArrayList<ScannerResult>(); for (IToken token = scanner.nextToken(); token != Token.EOF; token = scanner.nextToken()) { if (token == tokenNotExpected) { tokenFound = true; } - tokenList.add(new TestResult(token, scanner.getTokenOffset(), scanner.getTokenLength())); + tokenList.add(new ScannerResult(token, scanner.getTokenOffset(), scanner.getTokenLength())); } if (tokenFound) { @@ -92,26 +92,15 @@ public abstract class AbstractRuleTestCase extends TestCase { } } - protected void appendTokenList(final List<TestResult> tokenList, final StringBuffer messageBuilder, final String inputString) { - for (TestResult result : tokenList) { + protected void appendTokenList(final List<ScannerResult> tokenList, final StringBuffer messageBuilder, final String inputString) { + for (ScannerResult result : tokenList) { StringBuilder inputWithStar = new StringBuilder(inputString); - inputWithStar.insert(result.offset, '*'); - inputWithStar.insert(result.offset + result.length + 1, '*'); - messageBuilder.append(MessageFormat.format("'{'-Token={0} -Offset={1} -Length={2} \"{3}\"'}'\n", result.token.getData(), result.offset, //$NON-NLS-1$ - result.length, inputWithStar.toString())); + inputWithStar.insert(result.getOffset(), '*'); + inputWithStar.insert(result.getOffset() + result.getLenght() + 1, '*'); + messageBuilder.append(MessageFormat.format( + "'{'-Token={0} -Offset={1} -Lenght={2} \"{3}\"'}'\n", result.getToken().getData(), result.getOffset(), //$NON-NLS-1$ + result.getLenght(), inputWithStar.toString())); } } - private static class TestResult { - - private IToken token; - private int offset; - private int length; - - public TestResult(IToken token2, int tokenOffset, int tokenLength) { - token = token2; - offset = tokenOffset; - length = tokenLength; - } - } } diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/AbstractScannerTestCase.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/AbstractScannerTestCase.java new file mode 100644 index 0000000..e5bc6bd --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/AbstractScannerTestCase.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.tests.internal.scanners; + +import java.io.File; +import java.io.IOException; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.commons.io.FileUtils; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.ITokenScanner; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.koneki.ldt.ui.tests.internal.ScannerResult; +import org.junit.Before; +import org.junit.Test; + +public abstract class AbstractScannerTestCase extends TestCase { + + private final File referenceFile; + private final File inputFile; + private String inputString; + private String referenceString; + + public AbstractScannerTestCase(String testName, File inputFilePath, File referenceFilePath) { + inputFile = inputFilePath; + referenceFile = referenceFilePath; + + setName(testName); + } + + @Before + public void setUp() { + + // Check if input file exist + if (!inputFile.exists()) { + final String message = MessageFormat.format("{0} input does not exist.", inputFile); //$NON-NLS-1$ + throw new RuntimeException(message); + } + // Check if reference file exist + if (!referenceFile.exists()) { + final String message = MessageFormat.format("{0} reference does not exist.", referenceFile); //$NON-NLS-1$ + throw new RuntimeException(message); + } + + inputString = loadInputString(inputFile); + + referenceString = loadReferenceString(referenceFile); + + try { + referenceString = FileUtils.readFileToString(referenceFile); + } catch (IOException e) { + final String message = MessageFormat.format("Unable to read reference file: {0}", referenceFile); //$NON-NLS-1$ + throw new RuntimeException(message, e); + } + + } + + protected String loadInputString(File inputFile2) { + return loadString(inputFile2); + } + + protected String loadReferenceString(File referenceFile2) { + return loadString(referenceFile2); + } + + private String loadString(File file) { + String fileInString; + try { + fileInString = FileUtils.readFileToString(file); + } catch (IOException e) { + final String message = MessageFormat.format("Unable to read source file: {0}", inputFile.getAbsolutePath()); //$NON-NLS-1$ + throw new RuntimeException(message, e); + } + return fileInString; + } + + @Test + public void test() { + Document doc = new Document(getInputString()); + ITokenScanner partionner = createScanner(); + partionner.setRange(doc, 0, doc.getLength()); + List<ScannerResult> tokenList = new ArrayList<ScannerResult>(); + + for (IToken token = partionner.nextToken(); token != Token.EOF; token = partionner.nextToken()) { + tokenList.add(new ScannerResult(token, partionner.getTokenOffset(), partionner.getTokenLength())); + } + + assertEquals("File partionning differ from the reference:", getReferenceString(), toString(tokenList)); //$NON-NLS-1$ + } + + protected abstract ITokenScanner createScanner(); + + protected String toString(List<ScannerResult> tokenList) { + StringBuilder stringBuilder = new StringBuilder(); + + for (ScannerResult result : tokenList) { + if (!isIgnoredToken(result.getToken())) { + stringBuilder.append(result.toString()); + } + } + return stringBuilder.toString(); + } + + protected boolean isIgnoredToken(IToken token) { + return token.getData() == null; + } + + @Override + public void runTest() { + test(); + } + + public String getInputString() { + return inputString; + } + + public String getReferenceString() { + return referenceString; + } + +} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/AbstractScannerTestSuite.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/AbstractScannerTestSuite.java new file mode 100644 index 0000000..560cf6b --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/AbstractScannerTestSuite.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.tests.internal.scanners; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.koneki.ldt.ui.tests.internal.Activator; +import org.osgi.framework.Bundle; + +/** + * Launch a bench of TestCase for each file to test in the given folder. + */ +public abstract class AbstractScannerTestSuite extends TestSuite { + + private List<String> blacklist; + + /** + * @param name + * Name of the suite + * @param folderPath + * The project relative path of the folder containing inputs, references and test files + * @param referenceFileExtension + * Extension of the reference file (e.g. "lua" or "serialized") + * @param ignore + */ + public AbstractScannerTestSuite(final String name, final String folderPath, final String referenceFileExtension, boolean ignore) { + super(); + setName(name); + + try { + // Retrieve folder + final Bundle bundle = Activator.getDefault().getBundle(); + final URL ressource = bundle.getResource(folderPath); + final Path folderAbsolutePath = new Path(FileLocator.toFileURL(ressource).getPath()); + + // check test suite folder + checkFolder(folderAbsolutePath, "This is not a directory and cannot contain test suite files and folders."); //$NON-NLS-1$ + + // check input folder + final File inputFolder = checkFolder(folderAbsolutePath.append(getInputFolderPath()), + "This is not a directory and cannot contain test lua input files."); //$NON-NLS-1$ + + // check reference folder + final File referenceFolder = checkFolder(folderAbsolutePath.append(getReferenceFolderPath()), + "This is not a directory and cannot contain test reference files."); //$NON-NLS-1$ + + // Retrieve files + for (final File inputFile : getRecursiveFileList(inputFolder)) { + + // Compute relative file path + final IPath inputFilePath = new Path(inputFile.getCanonicalPath()); + final IPath relativeToFolderPath = inputFilePath.makeRelativeTo(new Path(inputFolder.getCanonicalPath())); + + // Build reference file path + IPath referenceFilePath = new Path(referenceFolder.getCanonicalPath()).append(relativeToFolderPath); + referenceFilePath = referenceFilePath.removeFileExtension(); + referenceFilePath = referenceFilePath.addFileExtension(referenceFileExtension); + final File referenceFile = new File(referenceFilePath.toOSString()); + + // Compute testName + final String testName = MessageFormat.format("{0}#{1}", getName(), relativeToFolderPath.toOSString()); //$NON-NLS-1$ + + // Append test case and ignore blacklisted files + if (!(ignore && getTestBlacklisted().contains(relativeToFolderPath.toPortableString()))) { + addTest(createTestCase(testName, inputFile, referenceFile)); + } + } + } catch (final IOException e) { + final String message = MessageFormat.format("Unable to locate {0}.", folderPath); //$NON-NLS-1$ + raiseRuntimeException(message, e); + } + } + + private List<String> getTestBlacklisted() { + if (blacklist == null) { + blacklist = createTestBlacklist(); + } + return blacklist; + } + + protected List<String> createTestBlacklist() { + return Collections.<String> emptyList(); + } + + private File checkFolder(final IPath folderAbosultePath, final String errorMessage) { + final File folder = new File(folderAbosultePath.toOSString()); + if (!folder.isDirectory()) { + String message = MessageFormat.format("{0}: {1}", errorMessage, folderAbosultePath); //$NON-NLS-1$ + raiseRuntimeException(message, null); + } + return folder; + } + + private List<File> getRecursiveFileList(final File file) { + return getRecursiveFileList(file, new ArrayList<File>()); + } + + private List<File> getRecursiveFileList(final File file, List<File> list) { + + // Loop over directory + if (file.isDirectory()) { + for (final File subfile : file.listFiles()) { + getRecursiveFileList(subfile, list); + } + return list; + } + + // Regular file + list.add(file); + return list; + } + + /** + * @return Input file root folder + */ + protected String getInputFolderPath() { + return "input"; //$NON-NLS-1$ + } + + /** + * @return References file root folder + */ + protected String getReferenceFolderPath() { + return "reference"; //$NON-NLS-1$ + } + + protected final void raiseRuntimeException(final String message, final Throwable t) { + throw new RuntimeException(message, t); + } + + protected abstract TestCase createTestCase(final String testName, final File inputFile, final File referenceFile); +} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaCodeScannerTestCase.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaCodeScannerTestCase.java new file mode 100644 index 0000000..a72918c --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaCodeScannerTestCase.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.tests.internal.scanners; + +import java.io.File; + +import org.eclipse.dltk.internal.ui.text.DLTKColorManager; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.ITokenScanner; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.koneki.ldt.ui.internal.editor.text.LuaCodeScanner; +import org.eclipse.ui.internal.editors.text.EditorsPlugin; + +@SuppressWarnings("restriction") +public class LuaCodeScannerTestCase extends AbstractScannerTestCase { + + public LuaCodeScannerTestCase(String testName, File inputFile, File referenceFile) { + super(testName, inputFile, referenceFile); + } + + @Override + protected ITokenScanner createScanner() { + return new LuaCodeScanner(new DLTKColorManager(true), EditorsPlugin.getDefault().getPreferenceStore()) { + @Override + public Token getToken(String key) { + Token token = super.getToken(key); + token.setData(key); + return token; + } + }; + } + + @Override + protected boolean isIgnoredToken(IToken token) { + return super.isIgnoredToken(token) || token.getData().equals("DLTK_default"); //$NON-NLS-1$ + } +} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaCodeScannerTestSuite.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaCodeScannerTestSuite.java new file mode 100644 index 0000000..4c6b04b --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaCodeScannerTestSuite.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.tests.internal.scanners; + +import java.io.File; + +import junit.framework.TestCase; + +public class LuaCodeScannerTestSuite extends AbstractScannerTestSuite { + + public LuaCodeScannerTestSuite() { + super("LuaCodeScanner", "tests/codescanner", "txt", false); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + } + + @Override + protected TestCase createTestCase(String testName, File inputFile, File referenceFile) { + return new LuaCodeScannerTestCase(testName, inputFile, referenceFile); + } +} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaDocumentorScannerTestCase.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaDocumentorScannerTestCase.java new file mode 100644 index 0000000..ddd2cce --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaDocumentorScannerTestCase.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.tests.internal.scanners; + +import java.io.File; + +import org.eclipse.dltk.internal.ui.text.DLTKColorManager; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.ITokenScanner; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.koneki.ldt.ui.internal.editor.templates.SimpleLuaSourceViewerConfiguration; +import org.eclipse.koneki.ldt.ui.internal.editor.text.ILuaPartitions; +import org.eclipse.koneki.ldt.ui.internal.editor.text.LuaDocumentorScanner; +import org.eclipse.ui.internal.editors.text.EditorsPlugin; + +@SuppressWarnings("restriction") +public class LuaDocumentorScannerTestCase extends AbstractScannerTestCase { + + public LuaDocumentorScannerTestCase(String testName, File inputFile, File referenceFile) { + super(testName, inputFile, referenceFile); + } + + @Override + protected ITokenScanner createScanner() { + IPreferenceStore preferenceStore = EditorsPlugin.getDefault().getPreferenceStore(); + SimpleLuaSourceViewerConfiguration configuration = new SimpleLuaSourceViewerConfiguration(new DLTKColorManager(true), preferenceStore, null, + ILuaPartitions.LUA_PARTITIONING, false); + return new LuaDocumentorScanner(configuration) { + @Override + public Token getToken(String key) { + Token token = super.getToken(key); + token.setData(key); + return token; + } + }; + } + + @Override + protected boolean isIgnoredToken(IToken token) { + return super.isIgnoredToken(token) || token.getData().toString().equals("DLTK_doc"); //$NON-NLS-1$ + } + +} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaDocumentorScannerTestSuite.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaDocumentorScannerTestSuite.java new file mode 100644 index 0000000..1cc31b0 --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaDocumentorScannerTestSuite.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.tests.internal.scanners; + +import java.io.File; + +import junit.framework.TestCase; + +public class LuaDocumentorScannerTestSuite extends AbstractScannerTestSuite { + + public LuaDocumentorScannerTestSuite() { + super("LuaDocumentorScanner", "tests/luadocumentor", "txt", false); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + } + + @Override + protected TestCase createTestCase(String testName, File inputFile, File referenceFile) { + return new LuaDocumentorScannerTestCase(testName, inputFile, referenceFile); + } + +} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaPartitionScannerTestCase.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaPartitionScannerTestCase.java new file mode 100644 index 0000000..ee48c45 --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaPartitionScannerTestCase.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.tests.internal.scanners; + +import java.io.File; + +import org.eclipse.jface.text.rules.ITokenScanner; +import org.eclipse.koneki.ldt.ui.internal.editor.text.LuaPartitionScanner; + +public class LuaPartitionScannerTestCase extends AbstractScannerTestCase { + + public LuaPartitionScannerTestCase(String testName, File inputFile, File referenceFile) { + super(testName, inputFile, referenceFile); + } + + @Override + protected ITokenScanner createScanner() { + return new LuaPartitionScanner(); + } + +} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaPartitionScannerTestSuite.java b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaPartitionScannerTestSuite.java new file mode 100644 index 0000000..4f03bb7 --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/src/org/eclipse/koneki/ldt/ui/tests/internal/scanners/LuaPartitionScannerTestSuite.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.ldt.ui.tests.internal.scanners; + +import java.io.File; + +import junit.framework.TestCase; + +public class LuaPartitionScannerTestSuite extends AbstractScannerTestSuite { + + public LuaPartitionScannerTestSuite() { + super("LuaPartitionScanner", "tests/codepartionner", "txt", false); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + } + + @Override + protected TestCase createTestCase(String testName, File inputFile, File referenceFile) { + return new LuaPartitionScannerTestCase(testName, inputFile, referenceFile); + } + +} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/tests/codepartionner/input/simple.lua b/tests/org.eclipse.koneki.ldt.ui.tests/tests/codepartionner/input/simple.lua new file mode 100644 index 0000000..fcb5ae3 --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/tests/codepartionner/input/simple.lua @@ -0,0 +1,7 @@ +--- @module modulename + +--[[- @function [parent=#modulename] functionname]] +--[[print hello]] + +-- return the module +return "hello world"
\ No newline at end of file diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/tests/codepartionner/reference/simple.txt b/tests/org.eclipse.koneki.ldt.ui.tests/tests/codepartionner/reference/simple.txt new file mode 100644 index 0000000..0e97ac9 --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/tests/codepartionner/reference/simple.txt @@ -0,0 +1,5 @@ +{0;23;__lua_doc} +{24;51;__lua_doc_multi_line} +{76;17;__lua_multi_line_comment} +{95;21;__lua_comment} +{123;13;__lua_string} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/tests/codescanner/input/simple.lua b/tests/org.eclipse.koneki.ldt.ui.tests/tests/codescanner/input/simple.lua new file mode 100644 index 0000000..91085aa --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/tests/codescanner/input/simple.lua @@ -0,0 +1,2 @@ +local var = "coucou" +var = 12
\ No newline at end of file diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/tests/codescanner/reference/simple.txt b/tests/org.eclipse.koneki.ldt.ui.tests/tests/codescanner/reference/simple.txt new file mode 100644 index 0000000..64e7cc7 --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/tests/codescanner/reference/simple.txt @@ -0,0 +1,2 @@ +{0;5;DLTK_keyword} +{27;2;DLTK_number} diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/tests/luadocumentor/input/simple.lua b/tests/org.eclipse.koneki.ldt.ui.tests/tests/luadocumentor/input/simple.lua new file mode 100644 index 0000000..c15c5f4 --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/tests/luadocumentor/input/simple.lua @@ -0,0 +1,4 @@ +--- +-- @module modulename + +--- @type typename
\ No newline at end of file diff --git a/tests/org.eclipse.koneki.ldt.ui.tests/tests/luadocumentor/reference/simple.txt b/tests/org.eclipse.koneki.ldt.ui.tests/tests/luadocumentor/reference/simple.txt new file mode 100644 index 0000000..d1e5a4b --- a/dev/null +++ b/tests/org.eclipse.koneki.ldt.ui.tests/tests/luadocumentor/reference/simple.txt @@ -0,0 +1,2 @@ +{7;7;luadoc.tags} +{31;5;luadoc.tags} |

