mirror of
https://github.com/processing/processing4.git
synced 2026-01-29 19:31:16 +01:00
Move to ANTLR 4 with Java 11 lang features and localization. (#5)
* Move to ANTLR 4 with Java 11 lang features and localization. Introduces ANTLR4 and Java 8 language feature support within IDE while also adding additional hooks for localization of syntax error messages, addressing https://github.com/processing/processing/issues/3054 and https://github.com/processing/processing/issues/3055. The PR is broadly a continuation of https://github.com/processing/processing/issues/3055, bringing it up to speed with the latest Processing master plus the changes introduced at https://github.com/processing/processing/pull/5753. **Requires https://github.com/processing/processing/pull/5753 as pre-requisite.** This introduces a number of edits beyond https://github.com/processing/processing/issues/3055 beyond compatibility with current Processing master and https://github.com/processing/processing/pull/5753 including: - Update to the grammar itself - Change ANTLR listeners to emit `TextTransform.Edit` to unify JDT-based `PreprocessingService` and `JavaBuild`, removing code with duplicate purpose. - Introduction of syntax error rewriting with support for localization. - Addition of complete localized strings set for English and Spanish. - Addition of partial localized strings set for other languages. - Refactor of ANTLR-related code for testability and readability - Expansion of tests including full parse tests for new Java features (type inference, lambdas). * Ask travis for ant upgrade prior to run. * Ask Travis for java11 update. * Add openjdk ppa * Travis no confirmation on add ppa. * Force newer ant on travis. * Swtich ant download to www-us mirror. * Switch ant to 1.10.7 * Start x for unit tests in travis. * More complete start x in travis. * Revert x in travis. * Try x in services.
This commit is contained in:
committed by
GitHub
parent
00dd2803f0
commit
ee299ef935
64
java/test/processing/mode/java/AutoFormatTests.java
Normal file
64
java/test/processing/mode/java/AutoFormatTests.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package processing.mode.java;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static processing.mode.java.ProcessingTestUtil.res;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AutoFormatTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
ProcessingTestUtil.init();
|
||||
}
|
||||
|
||||
static void expectGood(final String id) {
|
||||
try {
|
||||
final String formattedProgram = ProcessingTestUtil.format(res(id + ".pde"));
|
||||
final File goldenFile = res(id + ".expected");
|
||||
checkGolden(formattedProgram, goldenFile);
|
||||
// check that the formatted text doesn't change
|
||||
checkGolden(ProcessingTestUtil.format(formattedProgram), goldenFile);
|
||||
} catch (Exception e) {
|
||||
if (!e.equals(e.getCause()) && e.getCause() != null)
|
||||
fail(e.getCause().toString());
|
||||
else
|
||||
e.printStackTrace(System.err);
|
||||
fail(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkGolden(final String expectedText,
|
||||
final File goldenFile) throws IOException {
|
||||
if (goldenFile.exists()) {
|
||||
final String expected = ProcessingTestUtil.read(goldenFile);
|
||||
assertEquals(expected, expectedText);
|
||||
} else {
|
||||
System.err.println("WARN: golden file " + goldenFile
|
||||
+ " does not exist. Generating.");
|
||||
final FileWriter sug = new FileWriter(goldenFile);
|
||||
sug.write(ProcessingTestUtil.normalize(expectedText));
|
||||
sug.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug109() {
|
||||
expectGood("bug109");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug405() {
|
||||
expectGood("bug405");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug420() {
|
||||
expectGood("bug420");
|
||||
}
|
||||
}
|
||||
398
java/test/processing/mode/java/ParserTests.java
Normal file
398
java/test/processing/mode/java/ParserTests.java
Normal file
@@ -0,0 +1,398 @@
|
||||
package processing.mode.java;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static processing.mode.java.ProcessingTestUtil.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.core.compiler.IProblem;
|
||||
import org.eclipse.jdt.core.dom.AST;
|
||||
import org.eclipse.jdt.core.dom.ASTParser;
|
||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import processing.app.SketchException;
|
||||
import processing.mode.java.pdex.JdtCompilerUtil;
|
||||
import processing.mode.java.preproc.PreprocessorResult;
|
||||
import processing.mode.java.preproc.issue.PdePreprocessIssueException;
|
||||
|
||||
|
||||
public class ParserTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
ProcessingTestUtil.init();
|
||||
}
|
||||
|
||||
static void expectRecognitionException(final String id,
|
||||
final int expectedLine) {
|
||||
|
||||
PreprocessorResult result;
|
||||
try {
|
||||
preprocess(id, res(id + ".pde"));
|
||||
fail("Expected to fail with on line " + expectedLine);
|
||||
} catch (PdePreprocessIssueException e) {
|
||||
assertNotNull(e.getIssue().getMsg());
|
||||
assertEquals(expectedLine, e.getIssue().getLine());
|
||||
} catch (Exception e) {
|
||||
if (!e.equals(e.getCause()) && e.getCause() != null)
|
||||
fail(e.getCause().toString());
|
||||
else
|
||||
fail(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
static void expectRunnerException(final String id,
|
||||
final int expectedLine) {
|
||||
|
||||
try {
|
||||
preprocess(id, res(id + ".pde"));
|
||||
fail("Expected to fail with on line " + expectedLine);
|
||||
} catch (SketchException e) {
|
||||
assertEquals(expectedLine, e.getCodeLine());
|
||||
} catch (PdePreprocessIssueException e) {
|
||||
assertNotNull(e.getIssue().getMsg());
|
||||
assertEquals(expectedLine, e.getIssue().getLine());
|
||||
} catch (Exception e) {
|
||||
if (!e.equals(e.getCause()) && e.getCause() != null)
|
||||
fail(e.getCause().toString());
|
||||
else
|
||||
fail(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
static void expectCompilerException(final String id) {
|
||||
try {
|
||||
final String program = preprocess(id, res(id + ".pde"));
|
||||
boolean succeeded = compile(id, program);
|
||||
if (succeeded) {
|
||||
fail("Expected to fail.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!e.equals(e.getCause()) && e.getCause() != null)
|
||||
fail(e.getCause().toString());
|
||||
else
|
||||
fail(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
static void expectGood(final String id) {
|
||||
expectGood(id, true);
|
||||
}
|
||||
|
||||
static void expectGood(final String id, boolean ignoreWhitespace) {
|
||||
try {
|
||||
final String program = preprocess(id, res(id + ".pde"));
|
||||
boolean successful = compile(id, program);
|
||||
if (successful) {
|
||||
System.err.println("----------------------------");
|
||||
System.err.println(program);
|
||||
System.err.println("----------------------------");
|
||||
fail("Compilation failed.");
|
||||
}
|
||||
|
||||
final File expectedFile = res(id + ".expected");
|
||||
if (expectedFile.exists()) {
|
||||
final String expected = ProcessingTestUtil.read(expectedFile);
|
||||
if (ignoreWhitespace) {
|
||||
String expectedStrip = expected.replace("\t", "")
|
||||
.replace(" ", "")
|
||||
.replace("\n", "")
|
||||
.replace("\r", "");
|
||||
|
||||
String actualStrip = program.replace("\t", "")
|
||||
.replace(" ", "")
|
||||
.replace("\n", "")
|
||||
.replace("\r", "");
|
||||
|
||||
if (!expectedStrip.equals(actualStrip)) {
|
||||
System.err.println("Expected >>>>>>>");
|
||||
System.err.println(expected);
|
||||
System.err.println("<<<<<<< Got >>>>>>>");
|
||||
System.err.println(program);
|
||||
System.err.println("<<<<<<<");
|
||||
assertEquals(expectedStrip, actualStrip);
|
||||
}
|
||||
} else {
|
||||
assertEquals(expected, program);
|
||||
}
|
||||
} else {
|
||||
System.err.println("WARN: " + id
|
||||
+ " does not have an expected output file. Generating.");
|
||||
final FileWriter sug = new FileWriter(res(id + ".expected"));
|
||||
sug.write(ProcessingTestUtil.normalize(program));
|
||||
sug.close();
|
||||
}
|
||||
|
||||
} catch (SketchException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug4() {
|
||||
expectGood("bug4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug5a() {
|
||||
expectGood("bug5a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug5b() {
|
||||
expectGood("bug5b");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug6() {
|
||||
expectRecognitionException("bug6", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug16() {
|
||||
expectRunnerException("bug16", 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug136() {
|
||||
expectGood("bug136", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug196() {
|
||||
expectRecognitionException("bug196", 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug281() {
|
||||
expectGood("bug281");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug481() {
|
||||
expectGood("bug481");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug507() {
|
||||
expectRecognitionException("bug507", 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug598() {
|
||||
expectGood("bug598");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug631() {
|
||||
expectGood("bug631");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug763() {
|
||||
expectRunnerException("bug763", 8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug820() {
|
||||
expectCompilerException("bug820");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1064() {
|
||||
expectGood("bug1064");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1145() {
|
||||
expectCompilerException("bug1145");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1362() {
|
||||
expectGood("bug1362");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1390() {
|
||||
expectGood("bug1390");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1442() {
|
||||
expectGood("bug1442");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1511() {
|
||||
expectGood("bug1511");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1512() {
|
||||
expectGood("bug1512");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1514a() {
|
||||
expectGood("bug1514a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1514b() {
|
||||
expectGood("bug1514b");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1515() {
|
||||
expectGood("bug1515");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1516() {
|
||||
expectGood("bug1516");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1517() {
|
||||
expectGood("bug1517");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1518a() {
|
||||
expectGood("bug1518a");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1518b() {
|
||||
expectGood("bug1518b");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1525() {
|
||||
expectGood("bug1525");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1532() {
|
||||
expectRecognitionException("bug1532", 50);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1534() {
|
||||
expectGood("bug1534");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug1936() {
|
||||
expectGood("bug1936");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug315g() {
|
||||
expectGood("bug315g");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug400g() {
|
||||
expectGood("bug400g", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bug427g() {
|
||||
expectGood("bug427g");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void color() {
|
||||
expectGood("color", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotations() {
|
||||
expectGood("annotations", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generics() {
|
||||
expectGood("generics", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lambda() {
|
||||
expectGood("lambdaexample", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void specialMethods() {
|
||||
expectGood("speicalmethods", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void specialMethodsPrivate() {
|
||||
expectGood("specialmethodsprivate", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void classInStatic() {
|
||||
expectGood("classinstatic", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fullscreen() {
|
||||
expectGood("fullscreen", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customMain() {
|
||||
expectGood("custommain", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void charSpecial() {
|
||||
expectGood("charspecial", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typeInference() {
|
||||
expectGood("typeinference");
|
||||
}
|
||||
|
||||
private static boolean compile(String id, String program) {
|
||||
// Create compilable AST to get syntax problems
|
||||
CompilationUnit compilableCU = JdtCompilerUtil.makeAST(
|
||||
ASTParser.newParser(AST.JLS8),
|
||||
program.toCharArray(),
|
||||
JdtCompilerUtil.COMPILER_OPTIONS
|
||||
);
|
||||
|
||||
// Get syntax problems from compilable AST
|
||||
Optional<IProblem> problem = Arrays.stream(compilableCU.getProblems())
|
||||
.filter(IProblem::isError)
|
||||
.findFirst();
|
||||
|
||||
if (problem.isPresent()) {
|
||||
IProblem problemFound = problem.get();
|
||||
|
||||
System.err.println("Compilation issue: "
|
||||
+ problemFound.getMessage()
|
||||
+ "(" + problemFound.getSourceLineNumber() + ")"
|
||||
);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
87
java/test/processing/mode/java/ProcessingTestUtil.java
Normal file
87
java/test/processing/mode/java/ProcessingTestUtil.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package processing.mode.java;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringWriter;
|
||||
import processing.app.Preferences;
|
||||
import processing.app.SketchException;
|
||||
import processing.mode.java.preproc.PdePreprocessor;
|
||||
import processing.mode.java.preproc.PreprocessorResult;
|
||||
import processing.mode.java.preproc.issue.PdePreprocessIssueException;
|
||||
|
||||
|
||||
public class ProcessingTestUtil {
|
||||
static void init() {
|
||||
// noop; just causes class to be loaded
|
||||
}
|
||||
|
||||
private static final String RESOURCES = "test/resources/";
|
||||
private static final String RESOURCES_UP_DIR = "../java/test/resources";
|
||||
static final UTCompiler COMPILER;
|
||||
|
||||
static {
|
||||
try {
|
||||
COMPILER = new UTCompiler(new File("bin-test"), new File("../core/bin"));
|
||||
Preferences.load(new FileInputStream(res("preferences.txt")));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//System.err.println("ProcessingTestUtil initialized.");
|
||||
}
|
||||
|
||||
static String normalize(final Object s) {
|
||||
return String.valueOf(s).replace("\r", "");
|
||||
}
|
||||
|
||||
static String preprocess(final String name, final File resource)
|
||||
throws SketchException {
|
||||
final String program = read(resource);
|
||||
final StringWriter out = new StringWriter();
|
||||
PreprocessorResult result = new PdePreprocessor(name, 4, true).write(out, program);
|
||||
|
||||
if (result.getPreprocessIssues().size() > 0) {
|
||||
throw new PdePreprocessIssueException(result.getPreprocessIssues().get(0));
|
||||
}
|
||||
|
||||
return normalize(out);
|
||||
}
|
||||
|
||||
static String format(final File resource)
|
||||
{
|
||||
return format(read(resource));
|
||||
}
|
||||
|
||||
static String format(final String programText) {
|
||||
return normalize(new AutoFormat().format(programText));
|
||||
}
|
||||
|
||||
static File res(final String resourceName) {
|
||||
File target = new File(RESOURCES, resourceName);
|
||||
if (target.exists()) {
|
||||
return target;
|
||||
}
|
||||
return new File(RESOURCES_UP_DIR, resourceName);
|
||||
}
|
||||
|
||||
static String read(final File f) {
|
||||
try {
|
||||
final FileInputStream fin = new FileInputStream(f);
|
||||
final InputStreamReader in = new InputStreamReader(fin, "UTF-8");
|
||||
try {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final char[] buf = new char[1 << 12];
|
||||
int len;
|
||||
while ((len = in.read(buf)) != -1)
|
||||
sb.append(buf, 0, len);
|
||||
return normalize(sb);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unexpected", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
60
java/test/processing/mode/java/UTCompiler.java
Normal file
60
java/test/processing/mode/java/UTCompiler.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package processing.mode.java;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import processing.app.Platform;
|
||||
import processing.app.exec.ProcessHelper;
|
||||
import processing.app.exec.ProcessResult;
|
||||
|
||||
/**
|
||||
* Utility class for compiling single compilationUnits.
|
||||
*
|
||||
* @author Jonathan Feinberg <jdf@pobox.com>
|
||||
*
|
||||
*/
|
||||
class UTCompiler {
|
||||
private final String classpath;
|
||||
|
||||
UTCompiler(File... classpath) throws IOException {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (final File f : classpath) {
|
||||
if (sb.length() > 0)
|
||||
sb.append(File.pathSeparatorChar);
|
||||
sb.append(f.getAbsolutePath());
|
||||
}
|
||||
this.classpath = sb.toString();
|
||||
}
|
||||
|
||||
ProcessResult compile(final String name, final String program)
|
||||
throws IOException {
|
||||
final File tmpdir = File.createTempFile("utcompiler", ".tmp");
|
||||
if (!tmpdir.delete())
|
||||
throw new IOException("Cannot delete " + tmpdir);
|
||||
if (!tmpdir.mkdir())
|
||||
throw new IOException("Cannot create " + tmpdir);
|
||||
final File javaFile = new File(tmpdir, name + ".java");
|
||||
final FileWriter java = new FileWriter(javaFile);
|
||||
try {
|
||||
java.write(program);
|
||||
} finally {
|
||||
java.close();
|
||||
}
|
||||
try {
|
||||
return new ProcessHelper("javac",
|
||||
"-sourcepath", tmpdir.getAbsolutePath(),
|
||||
"-cp", classpath,
|
||||
"-nowarn",
|
||||
"-d", tmpdir.getAbsolutePath(),
|
||||
javaFile.getAbsolutePath()).execute();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
for (final File f: tmpdir.listFiles())
|
||||
if (!f.getName().startsWith("."))if (!f.delete())
|
||||
throw new IOException("Can't delete " + f);
|
||||
if (!tmpdir.delete())
|
||||
throw new IOException("Can't delete " + tmpdir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import processing.app.Problem;
|
||||
import processing.app.ui.Editor;
|
||||
import processing.mode.java.preproc.issue.PdePreprocessIssue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ProblemFactoryTest {
|
||||
|
||||
private PdePreprocessIssue pdePreprocessIssue;
|
||||
private List<Integer> tabStarts;
|
||||
private Editor editor;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
pdePreprocessIssue = new PdePreprocessIssue(8, 2, "test");
|
||||
|
||||
tabStarts = new ArrayList<>();
|
||||
tabStarts.add(5);
|
||||
|
||||
editor = Mockito.mock(Editor.class);
|
||||
Mockito.when(editor.getLineStartOffset(3)).thenReturn(10);
|
||||
Mockito.when(editor.getLineStopOffset(3)).thenReturn(12);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildWithEditor() {
|
||||
Problem problem = ProblemFactory.build(pdePreprocessIssue, tabStarts, 15, editor);
|
||||
|
||||
Assert.assertEquals(3, problem.getLineNumber());
|
||||
Assert.assertEquals("test", problem.getMessage());
|
||||
Assert.assertEquals(10, problem.getStartOffset());
|
||||
Assert.assertEquals(11, problem.getStopOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildWithoutEditor() {
|
||||
Problem problem = ProblemFactory.build(pdePreprocessIssue, tabStarts);
|
||||
|
||||
Assert.assertEquals(3, problem.getLineNumber());
|
||||
Assert.assertEquals("test", problem.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package processing.mode.java.pdex.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TabLineFactoryTest {
|
||||
|
||||
private List<Integer> starts;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
starts = new ArrayList<>();
|
||||
starts.add(0);
|
||||
starts.add(5);
|
||||
starts.add(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTabStart() {
|
||||
Assert.assertEquals(0, TabLineFactory.getTab(starts, 0).getTab());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTabMiddleFrontEdge() {
|
||||
Assert.assertEquals(1, TabLineFactory.getTab(starts, 5).getTab());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTabMiddle() {
|
||||
TabLine tabLine = TabLineFactory.getTab(starts, 7);
|
||||
Assert.assertEquals(1, tabLine.getTab());
|
||||
Assert.assertEquals(2, tabLine.getLineInTab());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTabMiddleBackEdge() {
|
||||
Assert.assertEquals(2, TabLineFactory.getTab(starts, 10).getTab());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTabEnd() {
|
||||
Assert.assertEquals(2, TabLineFactory.getTab(starts, 15).getTab());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package processing.mode.java.preproc.code;
|
||||
|
||||
import org.antlr.v4.runtime.BufferedTokenStream;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.TokenStream;
|
||||
import org.antlr.v4.runtime.TokenStreamRewriter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import processing.mode.java.pdex.TextTransform;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class CodeEditOperationUtilTest {
|
||||
|
||||
private TokenStreamRewriter tokenStreamRewriter;
|
||||
private Token sampleStart;
|
||||
private Token sampleEnd;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
tokenStreamRewriter = Mockito.mock(TokenStreamRewriter.class);
|
||||
|
||||
sampleStart = Mockito.mock(Token.class);
|
||||
Mockito.when(sampleStart.getStartIndex()).thenReturn(5);
|
||||
Mockito.when(sampleStart.getText()).thenReturn("test");
|
||||
|
||||
sampleEnd = Mockito.mock(Token.class);
|
||||
Mockito.when(sampleEnd.getStartIndex()).thenReturn(10);
|
||||
Mockito.when(sampleEnd.getText()).thenReturn("testing");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDeleteSingle() {
|
||||
TextTransform.Edit edit = CodeEditOperationUtil.createDelete(sampleStart, tokenStreamRewriter);
|
||||
Assert.assertNotNull(edit);
|
||||
Mockito.verify(tokenStreamRewriter).delete(sampleStart);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDeleteRange() {
|
||||
TextTransform.Edit edit = CodeEditOperationUtil.createDelete(
|
||||
sampleStart,
|
||||
sampleEnd,
|
||||
tokenStreamRewriter
|
||||
);
|
||||
|
||||
Assert.assertNotNull(edit);
|
||||
Mockito.verify(tokenStreamRewriter).delete(sampleStart, sampleEnd);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createInsertAfterLocation() {
|
||||
TextTransform.Edit edit = CodeEditOperationUtil.createInsertAfter(
|
||||
5,
|
||||
"text",
|
||||
tokenStreamRewriter
|
||||
);
|
||||
|
||||
Assert.assertNotNull(edit);
|
||||
Mockito.verify(tokenStreamRewriter).insertAfter(5, "text");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createInsertAfterToken() {
|
||||
TextTransform.Edit edit = CodeEditOperationUtil.createInsertAfter(
|
||||
sampleStart,
|
||||
"text",
|
||||
tokenStreamRewriter
|
||||
);
|
||||
|
||||
Assert.assertNotNull(edit);
|
||||
Mockito.verify(tokenStreamRewriter).insertAfter(sampleStart, "text");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createInsertBeforeToken() {
|
||||
TextTransform.Edit edit = CodeEditOperationUtil.createInsertBefore(
|
||||
sampleStart,
|
||||
"text",
|
||||
tokenStreamRewriter
|
||||
);
|
||||
|
||||
Assert.assertNotNull(edit);
|
||||
Mockito.verify(tokenStreamRewriter).insertBefore(sampleStart, "text");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createInsertBeforeLocation() {
|
||||
TextTransform.Edit edit = CodeEditOperationUtil.createInsertBefore(
|
||||
5,
|
||||
5,
|
||||
"text",
|
||||
tokenStreamRewriter
|
||||
);
|
||||
|
||||
Assert.assertNotNull(edit);
|
||||
Mockito.verify(tokenStreamRewriter).insertBefore(5, "text");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package processing.mode.java.preproc.code;
|
||||
|
||||
import org.antlr.v4.runtime.TokenStreamRewriter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import processing.mode.java.pdex.TextTransform;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class PrintWriterWithEditGenTest {
|
||||
|
||||
private TokenStreamRewriter tokenStreamRewriter;
|
||||
private RewriteResultBuilder rewriteResultBuilder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
tokenStreamRewriter = Mockito.mock(TokenStreamRewriter.class);
|
||||
rewriteResultBuilder = new RewriteResultBuilder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addEmptyLineBefore() {
|
||||
PrintWriterWithEditGen editGen = createGen(true);
|
||||
editGen.addEmptyLine();
|
||||
editGen.finish();
|
||||
|
||||
List<TextTransform.Edit> edits = rewriteResultBuilder.getEdits();
|
||||
Assert.assertEquals(1, edits.size());
|
||||
|
||||
Mockito.verify(tokenStreamRewriter).insertBefore(5, "\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addCodeLineBefore() {
|
||||
PrintWriterWithEditGen editGen = createGen(true);
|
||||
editGen.addCodeLine("test");
|
||||
editGen.finish();
|
||||
|
||||
List<TextTransform.Edit> edits = rewriteResultBuilder.getEdits();
|
||||
Assert.assertEquals(1, edits.size());
|
||||
|
||||
Mockito.verify(tokenStreamRewriter).insertBefore(5, "test\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addCodeBefore() {
|
||||
PrintWriterWithEditGen editGen = createGen(true);
|
||||
editGen.addCode("test");
|
||||
editGen.finish();
|
||||
|
||||
List<TextTransform.Edit> edits = rewriteResultBuilder.getEdits();
|
||||
Assert.assertEquals(1, edits.size());
|
||||
|
||||
Mockito.verify(tokenStreamRewriter).insertBefore(5, "test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addEmptyLineAfter() {
|
||||
PrintWriterWithEditGen editGen = createGen(false);
|
||||
editGen.addEmptyLine();
|
||||
editGen.finish();
|
||||
|
||||
List<TextTransform.Edit> edits = rewriteResultBuilder.getEdits();
|
||||
Assert.assertEquals(1, edits.size());
|
||||
|
||||
Mockito.verify(tokenStreamRewriter).insertAfter(5, "\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addCodeLineAfter() {
|
||||
PrintWriterWithEditGen editGen = createGen(false);
|
||||
editGen.addCodeLine("test");
|
||||
editGen.finish();
|
||||
|
||||
List<TextTransform.Edit> edits = rewriteResultBuilder.getEdits();
|
||||
Assert.assertEquals(1, edits.size());
|
||||
|
||||
Mockito.verify(tokenStreamRewriter).insertAfter(5, "test\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addCodeAfter() {
|
||||
PrintWriterWithEditGen editGen = createGen(false);
|
||||
editGen.addCode("test");
|
||||
editGen.finish();
|
||||
|
||||
List<TextTransform.Edit> edits = rewriteResultBuilder.getEdits();
|
||||
Assert.assertEquals(1, edits.size());
|
||||
|
||||
Mockito.verify(tokenStreamRewriter).insertAfter(5, "test");
|
||||
}
|
||||
|
||||
private PrintWriterWithEditGen createGen(boolean before) {
|
||||
return new PrintWriterWithEditGen(
|
||||
tokenStreamRewriter,
|
||||
rewriteResultBuilder,
|
||||
5,
|
||||
before
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class AssignmentMessageSimplifierStrategyTest {
|
||||
|
||||
private AssignmentMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new AssignmentMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify(" int x =");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresentDiamond() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify(" List<Integer> x =");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("class {");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class BadIdentifierMessageSimplifierStrategyTest {
|
||||
|
||||
private BadIdentifierMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new BadIdentifierMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("test(a,01a");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("class {");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class BadParamMessageSimplifierStrategyTest {
|
||||
|
||||
private BadParamMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new BadParamMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("void test (int x,\ny) \n{");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresentUnderscore() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("void test (int x,\ny_y) \n{");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresentVarType() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("void test (int x,\nint) \n{");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("int x = y");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class ExtraneousInputMessageSimplifierStrategyTest {
|
||||
|
||||
private ExtraneousInputMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new ExtraneousInputMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("extraneous input 'test' expecting ';'");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("String x = \" \\\" \"");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class KnownMissingMessageSimplifierStrategyTest {
|
||||
|
||||
private KnownMissingMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new KnownMissingMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("missing ';' at 'addCircle'");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("String x = \" \\\" \"");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MessageSimplifierUtilTest {
|
||||
|
||||
@Test
|
||||
public void getOffendingAreaMatch() {
|
||||
String input = "no viable alternative at input 'ellipse(\n\nellipse();'";
|
||||
String output = MessageSimplifierUtil.getOffendingArea(input);
|
||||
Assert.assertEquals("ellipse();", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOffendingAreaNoMatch() {
|
||||
String input = "ambig at input 'ellipse(\n\nellipse();'";
|
||||
String output = MessageSimplifierUtil.getOffendingArea(input);
|
||||
Assert.assertEquals("ambig at input 'ellipse(\n\nellipse();'", output);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MismatchedInputMessageSimplifierStrategyTest {
|
||||
|
||||
private MismatchedInputMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new MismatchedInputMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("mismatched input 'final' expecting {'instanceof', ';', ',', '.', '>', '<', '==', '<=', '>=', '!=', '&&', '||', '++', '--', '+', '-', '*', '/', '&', '|', '^', '%', '::'}");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("String x = \" \\\" \"");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MissingChevMessageSimplifierStrategyTest {
|
||||
|
||||
private processing.mode.java.preproc.issue.strategy.MissingChevMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new MissingChevMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("class Test <a extends {");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("class {");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MissingClassNameMessageSimplifierStrategyTest {
|
||||
|
||||
private MissingClassNameMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new MissingClassNameMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresentExtends() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("class extends Base\n{");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresentNoExtends() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("class \n{");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("int x = y");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MissingCurlyMessageSimplifierStrategyTest {
|
||||
|
||||
private MissingCurlyMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new MissingCurlyMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("class Test {");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("class Test { }");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MissingDoubleQuoteMessageSimplifierStrategyTest {
|
||||
|
||||
private MissingDoubleQuoteMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new MissingDoubleQuoteMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("String x = \" \" \"");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("String x = \" \\\" \"");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MissingGenericTypeMessageSimplifierStrategyTest {
|
||||
|
||||
private MissingGenericTypeMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new MissingGenericTypeMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("<>'");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("class {");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MissingIdentifierMessageSimplifierStrategyTest {
|
||||
|
||||
private MissingIdentifierMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new MissingIdentifierMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("Missing identifier at ';'");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("String x = \" \\\" \"");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MissingMethodNameMessageSimplifierStrategyTest {
|
||||
|
||||
private MissingMethodNameMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new MissingMethodNameMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("void (int x) \n{");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresentNoSpace() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("test(int x) \n{");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresentUnderscore() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("void (int x_y) \n{");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("int x = y");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MissingParenMessageSimplifierStrategyTest {
|
||||
|
||||
private MissingParenMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new MissingParenMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("int x = ((5 + 4) / 3");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("int x = (y/5)/(\n4)");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MissingSingleQuoteMessageSimplifierStrategyTest {
|
||||
|
||||
private MissingSingleQuoteMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new MissingSingleQuoteMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("char x = '");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("char x = '\\''");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package processing.mode.java.preproc.issue.strategy;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MissingVariableNameMessageSimplifierStrategyTest {
|
||||
|
||||
private MissingVariableNameMessageSimplifierStrategy strategy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
strategy = new MissingVariableNameMessageSimplifierStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("char = ';");
|
||||
Assert.assertTrue(msg.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotPresent() {
|
||||
Optional<IssueMessageSimplification> msg = strategy.simplify("class test {");
|
||||
Assert.assertTrue(msg.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package processing.mode.java.preproc.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.IssueLocation;
|
||||
import processing.mode.java.preproc.issue.IssueLocationFactory;
|
||||
import processing.mode.java.preproc.issue.IssueMessageSimplification;
|
||||
|
||||
|
||||
public class IssueLocationFactoryTest {
|
||||
|
||||
private String source;
|
||||
private IssueLocation issueLocation;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
source = "//Test\n" +
|
||||
"noFill();\n" +
|
||||
"/**\n" +
|
||||
"**/\n" +
|
||||
"ellipse(50,50,50,50)\n" +
|
||||
"\n" +
|
||||
"/**\n" +
|
||||
"Test\n" +
|
||||
"* Test\n" +
|
||||
"** Test\n" +
|
||||
"*/\n" +
|
||||
"\n" +
|
||||
"// Testing\n" +
|
||||
"\n";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLineWithOffsetApplies() {
|
||||
issueLocation = IssueLocationFactory.getLineWithOffset(
|
||||
new IssueMessageSimplification("test message", true),
|
||||
15,
|
||||
0,
|
||||
source
|
||||
);
|
||||
|
||||
Assert.assertEquals(5, issueLocation.getLine());
|
||||
Assert.assertEquals(20, issueLocation.getCharPosition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLineWithOffsetNotApplies() {
|
||||
issueLocation = IssueLocationFactory.getLineWithOffset(
|
||||
new IssueMessageSimplification("test message", false),
|
||||
15,
|
||||
0,
|
||||
source
|
||||
);
|
||||
|
||||
Assert.assertEquals(15, issueLocation.getLine());
|
||||
Assert.assertEquals(0, issueLocation.getCharPosition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLineWithOffsetEndWhite() {
|
||||
issueLocation = IssueLocationFactory.getLineWithOffset(
|
||||
new IssueMessageSimplification("test message", true),
|
||||
14,
|
||||
0,
|
||||
"\n\n\n\n\n\n\n\n\n\n\nnoFill()\nellipse(50,50,50,50)\n"
|
||||
);
|
||||
|
||||
Assert.assertEquals(13, issueLocation.getLine());
|
||||
Assert.assertEquals(20, issueLocation.getCharPosition());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package processing.mode.java.preproc.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.issue.PreprocessIssueMessageSimplifierFacade;
|
||||
|
||||
|
||||
public class PreprocessIssueMessageSimplifierFacadeTest {
|
||||
|
||||
@Test
|
||||
public void testAssignment() {
|
||||
String input = "List<ColoredCircle> =";
|
||||
String output = PreprocessIssueMessageSimplifierFacade.get().simplify(input).getMessage();
|
||||
Assert.assertTrue(output.contains("assignment"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadIdentifier() {
|
||||
String input = "List<ColoredCircle> 9";
|
||||
String output = PreprocessIssueMessageSimplifierFacade.get().simplify(input).getMessage();
|
||||
Assert.assertTrue(output.contains("digit"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadParamLead() {
|
||||
String input = "x,";
|
||||
String output = PreprocessIssueMessageSimplifierFacade.get().simplify(input).getMessage();
|
||||
Assert.assertTrue(output.contains("parameter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadParamEnd() {
|
||||
String input = "colorGen),";
|
||||
String output = PreprocessIssueMessageSimplifierFacade.get().simplify(input).getMessage();
|
||||
Assert.assertTrue(output.contains("parameter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCaret() {
|
||||
String input = "List<ColoredCircle circles";
|
||||
String output = PreprocessIssueMessageSimplifierFacade.get().simplify(input).getMessage();
|
||||
Assert.assertTrue(output.contains(">"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingIdentifier() {
|
||||
String input = "missing Identifier at '{'";
|
||||
String output = PreprocessIssueMessageSimplifierFacade.get().simplify(input).getMessage();
|
||||
Assert.assertTrue(output.contains("{"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simplifyParen() {
|
||||
String input = "no viable alternative at input 'ellipse(\n\nellipse();'";
|
||||
String output = PreprocessIssueMessageSimplifierFacade.get().simplify(input).getMessage();
|
||||
Assert.assertNotNull(output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simplifySemicolon() {
|
||||
String input = "no viable alternative at input 'ellipse(\n\nellipse())'";
|
||||
String output = PreprocessIssueMessageSimplifierFacade.get().simplify(input).getMessage();
|
||||
Assert.assertNotNull(output);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package processing.mode.java.preproc.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import processing.mode.java.preproc.code.SyntaxUtil;
|
||||
|
||||
|
||||
public class SyntaxUtilTest {
|
||||
|
||||
@Test
|
||||
public void getCountPresent() {
|
||||
String input = "test1,test2\n,test3";
|
||||
int count = processing.mode.java.preproc.code.SyntaxUtil.getCount(input, ",");
|
||||
Assert.assertEquals(2, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCountNotPresent() {
|
||||
String input = "test1 test2 test3";
|
||||
int count = SyntaxUtil.getCount(input, ",");
|
||||
Assert.assertEquals(0, count);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user