aboutsummaryrefslogtreecommitdiff
path: root/javatests/com/google/turbine/parse
diff options
context:
space:
mode:
Diffstat (limited to 'javatests/com/google/turbine/parse')
-rw-r--r--javatests/com/google/turbine/parse/ExpressionParserTest.java16
-rw-r--r--javatests/com/google/turbine/parse/ParseErrorTest.java17
-rw-r--r--javatests/com/google/turbine/parse/ParserIntegrationTest.java3
-rw-r--r--javatests/com/google/turbine/parse/testdata/anno2.input3
-rw-r--r--javatests/com/google/turbine/parse/testdata/record.input53
-rw-r--r--javatests/com/google/turbine/parse/testdata/sealed.input15
6 files changed, 99 insertions, 8 deletions
diff --git a/javatests/com/google/turbine/parse/ExpressionParserTest.java b/javatests/com/google/turbine/parse/ExpressionParserTest.java
index 9fa96e2..7b5889b 100644
--- a/javatests/com/google/turbine/parse/ExpressionParserTest.java
+++ b/javatests/com/google/turbine/parse/ExpressionParserTest.java
@@ -39,7 +39,7 @@ public class ExpressionParserTest {
"14 + 42", "(14 + 42)",
},
{
- "14 + 42 + 123", "((14 + 42) + 123)",
+ "14 + 42 + 123", "(14 + 42 + 123)",
},
{
"14 / 42 + 123", "((14 / 42) + 123)",
@@ -49,7 +49,7 @@ public class ExpressionParserTest {
},
{
"1 + 2 / 3 + 4 / 5 + 6 / 7 / 8 + 9 + 10",
- "(((((1 + (2 / 3)) + (4 / 5)) + ((6 / 7) / 8)) + 9) + 10)",
+ "(1 + (2 / 3) + (4 / 5) + (6 / 7 / 8) + 9 + 10)",
},
{
"1 >> 2 || 3 ^ 4 << 3", "((1 >> 2) || (3 ^ (4 << 3)))",
@@ -64,7 +64,7 @@ public class ExpressionParserTest {
"((Object) 1 + 2)", "((Object) 1 + 2)",
},
{
- "(1) + 1 + 2", "((1 + 1) + 2)",
+ "(1) + 1 + 2", "(1 + 1 + 2)",
},
{
"((1 + 2) / (1 + 2))", "((1 + 2) / (1 + 2))",
@@ -82,7 +82,7 @@ public class ExpressionParserTest {
"(int) +2", "(int) +2",
},
{
- "(1 + 2) +2", "((1 + 2) + 2)",
+ "(1 + 2) + 2", "((1 + 2) + 2)",
},
{
"((1 + (2 / 3)) + (4 / 5))", "((1 + (2 / 3)) + (4 / 5))",
@@ -121,7 +121,7 @@ public class ExpressionParserTest {
"x.y = z", null,
},
{
- "0b100L + 0100L + 0x100L", "((4L + 64L) + 256L)",
+ "0b100L + 0100L + 0x100L", "(4L + 64L + 256L)",
},
{
"1+-2", "(1 + -2)",
@@ -132,6 +132,9 @@ public class ExpressionParserTest {
{
"A ? B : C ? D : E;", "(A ? B : (C ? D : E))",
},
+ {
+ "Foo.class", "Foo.class",
+ },
});
}
@@ -146,7 +149,8 @@ public class ExpressionParserTest {
@Test
public void test() {
StreamLexer lexer = new StreamLexer(new UnicodeEscapePreprocessor(new SourceFile(null, input)));
- Tree.Expression expression = new ConstExpressionParser(lexer, lexer.next()).expression();
+ Tree.Expression expression =
+ new ConstExpressionParser(lexer, lexer.next(), lexer.position()).expression();
if (expected == null) {
assertThat(expression).isNull();
} else {
diff --git a/javatests/com/google/turbine/parse/ParseErrorTest.java b/javatests/com/google/turbine/parse/ParseErrorTest.java
index eeb3923..2c48b81 100644
--- a/javatests/com/google/turbine/parse/ParseErrorTest.java
+++ b/javatests/com/google/turbine/parse/ParseErrorTest.java
@@ -35,7 +35,7 @@ public class ParseErrorTest {
StreamLexer lexer =
new StreamLexer(
new UnicodeEscapePreprocessor(new SourceFile("<>", String.valueOf("2147483648"))));
- ConstExpressionParser parser = new ConstExpressionParser(lexer, lexer.next());
+ ConstExpressionParser parser = new ConstExpressionParser(lexer, lexer.next(), lexer.position());
TurbineError e = assertThrows(TurbineError.class, () -> parser.expression());
assertThat(e).hasMessageThat().contains("invalid literal");
}
@@ -45,7 +45,7 @@ public class ParseErrorTest {
StreamLexer lexer =
new StreamLexer(
new UnicodeEscapePreprocessor(new SourceFile("<>", String.valueOf("0x100000000"))));
- ConstExpressionParser parser = new ConstExpressionParser(lexer, lexer.next());
+ ConstExpressionParser parser = new ConstExpressionParser(lexer, lexer.next(), lexer.position());
TurbineError e = assertThrows(TurbineError.class, () -> parser.expression());
assertThat(e).hasMessageThat().contains("invalid literal");
}
@@ -294,6 +294,19 @@ public class ParseErrorTest {
" ^"));
}
+ @Test
+ public void notCast() {
+ String input = "@j(@truetugt^(oflur)!%t";
+ TurbineError e = assertThrows(TurbineError.class, () -> Parser.parse(input));
+ assertThat(e)
+ .hasMessageThat()
+ .isEqualTo(
+ lines(
+ "<>:1: error: could not evaluate constant expression",
+ "@j(@truetugt^(oflur)!%t",
+ " ^"));
+ }
+
private static String lines(String... lines) {
return Joiner.on(System.lineSeparator()).join(lines);
}
diff --git a/javatests/com/google/turbine/parse/ParserIntegrationTest.java b/javatests/com/google/turbine/parse/ParserIntegrationTest.java
index 2503553..c758a74 100644
--- a/javatests/com/google/turbine/parse/ParserIntegrationTest.java
+++ b/javatests/com/google/turbine/parse/ParserIntegrationTest.java
@@ -42,6 +42,7 @@ public class ParserIntegrationTest {
public static Iterable<Object[]> parameters() {
String[] tests = {
"anno1.input",
+ "anno2.input",
"annodecl1.input",
"annodecl2.input",
"annodecl3.input",
@@ -75,6 +76,8 @@ public class ParserIntegrationTest {
"weirdstring.input",
"type_annotations.input",
"module-info.input",
+ "record.input",
+ "sealed.input",
};
return Iterables.transform(
Arrays.asList(tests),
diff --git a/javatests/com/google/turbine/parse/testdata/anno2.input b/javatests/com/google/turbine/parse/testdata/anno2.input
new file mode 100644
index 0000000..60b1901
--- /dev/null
+++ b/javatests/com/google/turbine/parse/testdata/anno2.input
@@ -0,0 +1,3 @@
+@Foo(bar = FooBar.Bar[].class)
+class Test {
+} \ No newline at end of file
diff --git a/javatests/com/google/turbine/parse/testdata/record.input b/javatests/com/google/turbine/parse/testdata/record.input
new file mode 100644
index 0000000..575d741
--- /dev/null
+++ b/javatests/com/google/turbine/parse/testdata/record.input
@@ -0,0 +1,53 @@
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.util.List;
+
+private record R() {
+}
+
+class Records {
+ record R1() {
+ }
+
+ private record R2() {
+ }
+
+ @Deprecated
+ private record R3() {
+ }
+
+ record R4<T>() {
+ }
+
+ record R5<T>(int x) {
+ }
+
+ record R6<T>(@Deprecated int x) {
+ }
+
+ record R7<T>(@Deprecated int x, int[] y) {
+ }
+
+ record R8<T>() implements Comparable<R8<T>> {
+ @Override
+ public int compareTo(R8<T> other) {}
+ }
+
+ record R9(int x) {
+ }
+
+ @Target(ElementType.TYPE_USE)
+ @interface A {
+ }
+
+ @Target(ElementType.RECORD_COMPONENT)
+ @interface B {
+ }
+
+ @Target({ElementType.TYPE_USE, ElementType.RECORD_COMPONENT})
+ @interface C {
+ }
+
+ record R10<T>(@A List<@A T> x, @B int y, @C int z) {
+ }
+}
diff --git a/javatests/com/google/turbine/parse/testdata/sealed.input b/javatests/com/google/turbine/parse/testdata/sealed.input
new file mode 100644
index 0000000..5a277b8
--- /dev/null
+++ b/javatests/com/google/turbine/parse/testdata/sealed.input
@@ -0,0 +1,15 @@
+sealed class Sealed permits Sealed.Foo, Sealed.Bar {
+ static final class Foo extends Sealed {
+ }
+
+ static final class Bar extends Sealed {
+ }
+}
+
+sealed interface ISealed permits ISealed.Foo, ISealed.Bar {
+ static final class Foo implements ISealed {
+ }
+
+ static non-sealed class Bar implements ISealed {
+ }
+}