mirror of
https://github.com/processing/processing4.git
synced 2026-01-30 20:01:09 +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
@@ -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