aboutsummaryrefslogtreecommitdiffstats
path: root/javaparser-testing/src
diff options
context:
space:
mode:
authorDanny van Bruggen <hexagonaal@gmail.com>2017-08-26 21:48:26 +0200
committerDanny van Bruggen <hexagonaal@gmail.com>2017-08-26 21:48:26 +0200
commit5145d35c452e05b49de20fd9d54b6c2dfbeb4718 (patch)
treeed027c98525c52d524cfa8f2e35413d533e7c91b /javaparser-testing/src
parentfed5f5aed9e48239a1472a40d8fd8aab3b0095f2 (diff)
parent77fe1130d88ca49908f8987c941321bacb55b92a (diff)
downloadplatform_external_javaparser-5145d35c452e05b49de20fd9d54b6c2dfbeb4718.tar.gz
platform_external_javaparser-5145d35c452e05b49de20fd9d54b6c2dfbeb4718.tar.bz2
platform_external_javaparser-5145d35c452e05b49de20fd9d54b6c2dfbeb4718.zip
Merge remote-tracking branch 'javaparser/master' into issue_1050_no_tokens_option
# Conflicts: # javaparser-testing/src/test/java/com/github/javaparser/JavaParserTest.java
Diffstat (limited to 'javaparser-testing/src')
-rw-r--r--javaparser-testing/src/test/java/com/github/javaparser/JavaParserTest.java19
-rw-r--r--javaparser-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithVariablesTest.java20
-rw-r--r--javaparser-testing/src/test/java/com/github/javaparser/ast/type/ArrayTypeTest.java6
-rw-r--r--javaparser-testing/src/test/java/com/github/javaparser/ast/type/TypeConstructionTest.java6
-rw-r--r--javaparser-testing/src/test/java/com/github/javaparser/ast/type/TypeTest.java10
-rw-r--r--javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java1_4ValidatorTest.java2
-rw-r--r--javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java5ValidatorTest.java2
7 files changed, 37 insertions, 28 deletions
diff --git a/javaparser-testing/src/test/java/com/github/javaparser/JavaParserTest.java b/javaparser-testing/src/test/java/com/github/javaparser/JavaParserTest.java
index d7784de65..c30427b27 100644
--- a/javaparser-testing/src/test/java/com/github/javaparser/JavaParserTest.java
+++ b/javaparser-testing/src/test/java/com/github/javaparser/JavaParserTest.java
@@ -28,21 +28,19 @@ import com.github.javaparser.ast.expr.ArrayCreationExpr;
import com.github.javaparser.ast.expr.CastExpr;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.LambdaExpr;
+import com.github.javaparser.ast.stmt.BlockStmt;
import com.github.javaparser.ast.stmt.ReturnStmt;
import com.github.javaparser.ast.stmt.Statement;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.ast.type.IntersectionType;
import com.github.javaparser.ast.type.Type;
-import com.github.javaparser.ast.visitor.ModifierVisitor;
-import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter;
-import com.github.javaparser.utils.Pair;
import org.junit.Test;
import java.util.Optional;
-import static com.github.javaparser.ParseStart.*;
+import static com.github.javaparser.ParseStart.COMPILATION_UNIT;
import static com.github.javaparser.Providers.*;
-import static com.github.javaparser.Range.*;
+import static com.github.javaparser.Range.range;
import static com.github.javaparser.utils.TestUtils.assertInstanceOf;
import static com.github.javaparser.utils.Utils.EOL;
import static org.junit.Assert.assertEquals;
@@ -200,4 +198,15 @@ public class JavaParserTest {
ParseResult<CompilationUnit> result = javaParser.parse(ParseStart.COMPILATION_UNIT, provider("class X{}"));
assertEquals(false, result.getTokens().isPresent());
}
+
+ @Test(expected = ParseProblemException.class)
+ public void trailingCodeIsAnError() {
+ JavaParser.parseBlock("{} efijqoifjqefj");
+ }
+
+ @Test
+ public void trailingWhitespaceIsIgnored() {
+ BlockStmt blockStmt = JavaParser.parseBlock("{} // hello");
+ assertEquals("\"}\" <120> (line 1,col 2)-(line 1,col 2)", blockStmt.getTokenRange().get().getEnd().toString());
+ }
}
diff --git a/javaparser-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithVariablesTest.java b/javaparser-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithVariablesTest.java
index edc439e46..f179a6c73 100644
--- a/javaparser-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithVariablesTest.java
+++ b/javaparser-testing/src/test/java/com/github/javaparser/ast/nodeTypes/NodeWithVariablesTest.java
@@ -32,61 +32,61 @@ public class NodeWithVariablesTest {
@Test
public void getCommonTypeWorksForNormalVariables() {
- VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a,b;");
+ VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a,b");
assertEquals(PrimitiveType.intType(), declaration.getCommonType());
}
@Test
public void getCommonTypeWorksForArrayTypes() {
- JavaParser.parseVariableDeclarationExpr("int a[],b[];").getCommonType();
+ JavaParser.parseVariableDeclarationExpr("int a[],b[]").getCommonType();
}
@Test(expected = AssertionError.class)
public void getCommonTypeFailsOnArrayDifferences() {
- JavaParser.parseVariableDeclarationExpr("int a[],b[][];").getCommonType();
+ JavaParser.parseVariableDeclarationExpr("int a[],b[][]").getCommonType();
}
@Test(expected = AssertionError.class)
public void getCommonTypeFailsOnDodgySetterUsage() {
- VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a,b;");
+ VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a,b");
declaration.getVariable(1).setType(String.class);
declaration.getCommonType();
}
@Test(expected = AssertionError.class)
public void getCommonTypeFailsOnInvalidEmptyVariableList() {
- VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a;");
+ VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a");
declaration.getVariables().clear();
declaration.getCommonType();
}
@Test
public void getElementTypeWorksForNormalVariables() {
- VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a,b;");
+ VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a,b");
assertEquals(PrimitiveType.intType(), declaration.getElementType());
}
@Test
public void getElementTypeWorksForArrayTypes() {
- VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a[],b[];");
+ VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a[],b[]");
assertEquals(PrimitiveType.intType(), declaration.getElementType());
}
@Test
public void getElementTypeIsOkayWithArrayDifferences() {
- JavaParser.parseVariableDeclarationExpr("int a[],b[][];").getElementType();
+ JavaParser.parseVariableDeclarationExpr("int a[],b[][]").getElementType();
}
@Test(expected = AssertionError.class)
public void getElementTypeFailsOnDodgySetterUsage() {
- VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a,b;");
+ VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a,b");
declaration.getVariable(1).setType(String.class);
declaration.getElementType();
}
@Test(expected = AssertionError.class)
public void getElementTypeFailsOnInvalidEmptyVariableList() {
- VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a;");
+ VariableDeclarationExpr declaration = JavaParser.parseVariableDeclarationExpr("int a");
declaration.getVariables().clear();
declaration.getElementType();
}
diff --git a/javaparser-testing/src/test/java/com/github/javaparser/ast/type/ArrayTypeTest.java b/javaparser-testing/src/test/java/com/github/javaparser/ast/type/ArrayTypeTest.java
index 0241d4bcf..d2cd7c285 100644
--- a/javaparser-testing/src/test/java/com/github/javaparser/ast/type/ArrayTypeTest.java
+++ b/javaparser-testing/src/test/java/com/github/javaparser/ast/type/ArrayTypeTest.java
@@ -84,7 +84,7 @@ public class ArrayTypeTest {
@Test
public void getMethodDeclarationWithArrays() {
- MethodDeclaration methodDeclaration = (MethodDeclaration) parseBodyDeclaration("@C int @A[] a() @B[] {};");
+ MethodDeclaration methodDeclaration = (MethodDeclaration) parseBodyDeclaration("@C int @A[] a() @B[] {}");
ArrayType arrayType1 = (ArrayType) methodDeclaration.getType();
ArrayType arrayType2 = (ArrayType) arrayType1.getComponentType();
@@ -99,7 +99,7 @@ public class ArrayTypeTest {
@Test
public void getParameterWithArrays() {
- MethodDeclaration methodDeclaration = (MethodDeclaration) parseBodyDeclaration("void a(@C int @A[] a @B[]) {};");
+ MethodDeclaration methodDeclaration = (MethodDeclaration) parseBodyDeclaration("void a(@C int @A[] a @B[]) {}");
Parameter parameter = methodDeclaration.getParameter(0);
@@ -143,7 +143,7 @@ public class ArrayTypeTest {
@Test
public void setParameterWithArrays() {
- MethodDeclaration method = (MethodDeclaration) parseBodyDeclaration("void a(int[][] a[][]) {};");
+ MethodDeclaration method = (MethodDeclaration) parseBodyDeclaration("void a(int[][] a[][]) {}");
method.getParameter(0).setType(new ArrayType(new ArrayType(parseClassOrInterfaceType("Blob"))));
assertEquals("void a(Blob[][] a) {" + EOL + "}", method.toString());
diff --git a/javaparser-testing/src/test/java/com/github/javaparser/ast/type/TypeConstructionTest.java b/javaparser-testing/src/test/java/com/github/javaparser/ast/type/TypeConstructionTest.java
index 7a75d9043..32739b200 100644
--- a/javaparser-testing/src/test/java/com/github/javaparser/ast/type/TypeConstructionTest.java
+++ b/javaparser-testing/src/test/java/com/github/javaparser/ast/type/TypeConstructionTest.java
@@ -82,7 +82,7 @@ public class TypeConstructionTest {
@Test
public void getMethodDeclarationWithArrays() {
- MethodDeclaration methodDeclaration = (MethodDeclaration) parseBodyDeclaration("@C int @A[] a() @B[] {};");
+ MethodDeclaration methodDeclaration = (MethodDeclaration) parseBodyDeclaration("@C int @A[] a() @B[] {}");
ArrayType arrayType1 = (ArrayType) methodDeclaration.getType();
ArrayType arrayType2 = (ArrayType) arrayType1.getComponentType();
@@ -97,7 +97,7 @@ public class TypeConstructionTest {
@Test
public void getParameterWithArrays() {
- MethodDeclaration methodDeclaration = (MethodDeclaration) parseBodyDeclaration("void a(@C int @A[] a @B[]) {};");
+ MethodDeclaration methodDeclaration = (MethodDeclaration) parseBodyDeclaration("void a(@C int @A[] a @B[]) {}");
Parameter parameter = methodDeclaration.getParameter(0);
@@ -141,7 +141,7 @@ public class TypeConstructionTest {
@Test
public void setParameterWithArrays() {
- MethodDeclaration method = (MethodDeclaration) parseBodyDeclaration("void a(int[][] a[][]) {};");
+ MethodDeclaration method = (MethodDeclaration) parseBodyDeclaration("void a(int[][] a[][]) {}");
method.getParameter(0).setType(new ArrayType(new ArrayType(parseClassOrInterfaceType("Blob"))));
assertEquals("void a(Blob[][] a) {" + EOL + "}", method.toString());
diff --git a/javaparser-testing/src/test/java/com/github/javaparser/ast/type/TypeTest.java b/javaparser-testing/src/test/java/com/github/javaparser/ast/type/TypeTest.java
index 51f5d5ee2..744fb1fad 100644
--- a/javaparser-testing/src/test/java/com/github/javaparser/ast/type/TypeTest.java
+++ b/javaparser-testing/src/test/java/com/github/javaparser/ast/type/TypeTest.java
@@ -17,10 +17,10 @@ import static org.junit.Assert.assertTrue;
public class TypeTest {
@Test
public void asString() {
- assertEquals("int", typeAsString("int x;"));
- assertEquals("List<Long>", typeAsString("List<Long> x;"));
- assertEquals("String", typeAsString("@A String x;"));
- assertEquals("List<? extends Object>", typeAsString("List<? extends Object> x;"));
+ assertEquals("int", typeAsString("int x"));
+ assertEquals("List<Long>", typeAsString("List<Long> x"));
+ assertEquals("String", typeAsString("@A String x"));
+ assertEquals("List<? extends Object>", typeAsString("List<? extends Object> x"));
}
@Test(expected = ParseProblemException.class)
@@ -36,7 +36,7 @@ public class TypeTest {
}});
ParseResult<VariableDeclarationExpr> result = new JavaParser(config).parse(
- VARIABLE_DECLARATION_EXPR, provider("List<long> x;"));
+ VARIABLE_DECLARATION_EXPR, provider("List<long> x"));
assertTrue(result.isSuccessful());
VariableDeclarationExpr decl = result.getResult().get();
diff --git a/javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java1_4ValidatorTest.java b/javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java1_4ValidatorTest.java
index 1107e033f..60f62a5fb 100644
--- a/javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java1_4ValidatorTest.java
+++ b/javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java1_4ValidatorTest.java
@@ -49,7 +49,7 @@ public class Java1_4ValidatorTest {
@Test
public void noforeach() {
- ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("for(X x: xs){};"));
+ ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("for(X x: xs){}"));
assertProblems(result, "(line 1,col 1) For-each loops are not supported.");
}
diff --git a/javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java5ValidatorTest.java b/javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java5ValidatorTest.java
index c7b03a648..d212ab037 100644
--- a/javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java5ValidatorTest.java
+++ b/javaparser-testing/src/test/java/com/github/javaparser/ast/validator/Java5ValidatorTest.java
@@ -130,7 +130,7 @@ public class Java5ValidatorTest {
@Test
public void foreach() {
- ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("for(X x: xs){};"));
+ ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("for(X x: xs){}"));
assertNoProblems(result);
}