aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/couscous/tests/frontends
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-10-30 20:25:05 +0000
committerMichael Williamson <mike@zwobble.org>2016-10-30 20:25:05 +0000
commitfee1878340fe2055f9d5b4c52eb2993c06c25f25 (patch)
treefb827034b5a4a2174b08803120c295f5affd764f /src/test/java/org/zwobble/couscous/tests/frontends
parentfd5dde9224680d46dd7081d051f1320194ff59ea (diff)
Store inner classes in ScalarType
Diffstat (limited to 'src/test/java/org/zwobble/couscous/tests/frontends')
-rw-r--r--src/test/java/org/zwobble/couscous/tests/frontends/java/ExpressionReadingTests.java64
-rw-r--r--src/test/java/org/zwobble/couscous/tests/frontends/java/JavaReaderTests.java42
-rw-r--r--src/test/java/org/zwobble/couscous/tests/frontends/java/JavaTypesTests.java4
3 files changed, 55 insertions, 55 deletions
diff --git a/src/test/java/org/zwobble/couscous/tests/frontends/java/ExpressionReadingTests.java b/src/test/java/org/zwobble/couscous/tests/frontends/java/ExpressionReadingTests.java
index e7b2f66..4aa015e 100644
--- a/src/test/java/org/zwobble/couscous/tests/frontends/java/ExpressionReadingTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/frontends/java/ExpressionReadingTests.java
@@ -65,7 +65,7 @@ public class ExpressionReadingTests {
@Test
public void canReadThisReference() {
assertEquals(
- thisReference(ScalarType.of("com.example.Example")),
+ thisReference(ScalarType.topLevel("com.example.Example")),
readExpressionInInstanceMethod("com.example.Example", "this"));
}
@@ -81,7 +81,7 @@ public class ExpressionReadingTests {
"private String name;");
assertEquals(
- list(field("name", ScalarType.of("java.lang.String"))),
+ list(field("name", ScalarType.topLevel("java.lang.String"))),
classNode.getFields());
}
@@ -91,7 +91,7 @@ public class ExpressionReadingTests {
"private static String name;");
assertEquals(
- list(staticField("name", ScalarType.of("java.lang.String"))),
+ list(staticField("name", ScalarType.topLevel("java.lang.String"))),
classNode.getFields());
}
@@ -115,7 +115,7 @@ public class ExpressionReadingTests {
ReturnNode returnNode = (ReturnNode) classNode.getMethods().get(0).getBody().get().get(0);
assertEquals(
fieldAccess(
- thisReference(ScalarType.of("com.example.Example")),
+ thisReference(ScalarType.topLevel("com.example.Example")),
"name",
Types.STRING),
returnNode.getValue());
@@ -132,7 +132,7 @@ public class ExpressionReadingTests {
ReturnNode returnNode = (ReturnNode) classNode.getMethods().get(0).getBody().get().get(1);
assertThat(returnNode.getValue(), isFieldAccess(
- fieldHasReceiver(isVariableReference("self", ScalarType.of("com.example.Example"))),
+ fieldHasReceiver(isVariableReference("self", ScalarType.topLevel("com.example.Example"))),
fieldHasName("name"),
expressionHasType(Types.STRING)));
}
@@ -167,7 +167,7 @@ public class ExpressionReadingTests {
ReturnNode returnNode = (ReturnNode) classNode.getMethods().get(0).getBody().get().get(0);
assertEquals(
fieldAccess(
- ScalarType.of("com.example.Example"),
+ ScalarType.topLevel("com.example.Example"),
"name",
Types.STRING),
returnNode.getValue());
@@ -197,7 +197,7 @@ public class ExpressionReadingTests {
assertEquals(
methodCall(
- ThisReferenceNode.thisReference(ScalarType.of("com.example.Example")),
+ ThisReferenceNode.thisReference(ScalarType.topLevel("com.example.Example")),
"loop",
list(),
Types.STRING),
@@ -208,7 +208,7 @@ public class ExpressionReadingTests {
public void canReadStaticMethodCalls() {
assertEquals(
staticMethodCall(
- ScalarType.of("java.lang.Integer"),
+ ScalarType.topLevel("java.lang.Integer"),
"parseInt",
list(literal("42")),
Types.INT),
@@ -225,7 +225,7 @@ public class ExpressionReadingTests {
assertEquals(
staticMethodCall(
- ScalarType.of("com.example.Example"),
+ ScalarType.topLevel("com.example.Example"),
"loop",
list(),
Types.STRING),
@@ -241,12 +241,12 @@ public class ExpressionReadingTests {
"asList",
list(Types.STRING),
list(array(Types.STRING, list())),
- parameterizedType(ScalarType.of("java.util.List"), list(Types.STRING)),
+ parameterizedType(ScalarType.topLevel("java.util.List"), list(Types.STRING)),
signature(
"asList",
list(typeParameter),
list(Types.array(typeParameter)),
- parameterizedType(ScalarType.of("java.util.List"), list(typeParameter)))),
+ parameterizedType(ScalarType.topLevel("java.util.List"), list(typeParameter)))),
readExpression("java.util.List<String>", "java.util.Arrays.asList()"));
}
@@ -259,12 +259,12 @@ public class ExpressionReadingTests {
"asList",
list(Types.STRING),
list(array(Types.STRING, list(literal("one"), literal("two")))),
- parameterizedType(ScalarType.of("java.util.List"), list(Types.STRING)),
+ parameterizedType(ScalarType.topLevel("java.util.List"), list(Types.STRING)),
signature(
"asList",
list(typeParameter),
list(Types.array(typeParameter)),
- parameterizedType(ScalarType.of("java.util.List"), list(typeParameter)))),
+ parameterizedType(ScalarType.topLevel("java.util.List"), list(typeParameter)))),
readExpression("java.util.List<String>", "java.util.Arrays.asList(\"one\", \"two\")"));
}
@@ -277,12 +277,12 @@ public class ExpressionReadingTests {
"asList",
list(Types.STRING),
list(array(Types.STRING, list())),
- parameterizedType(ScalarType.of("java.util.List"), list(Types.STRING)),
+ parameterizedType(ScalarType.topLevel("java.util.List"), list(Types.STRING)),
signature(
"asList",
list(typeParameter),
list(Types.array(typeParameter)),
- parameterizedType(ScalarType.of("java.util.List"), list(typeParameter)))),
+ parameterizedType(ScalarType.topLevel("java.util.List"), list(typeParameter)))),
readExpression("java.util.List<String>", "java.util.Arrays.asList(new String[]{})"));
}
@@ -295,12 +295,12 @@ public class ExpressionReadingTests {
"emptyList",
list(Types.STRING),
list(),
- parameterizedType(ScalarType.of("java.util.List"), list(Types.STRING)),
+ parameterizedType(ScalarType.topLevel("java.util.List"), list(Types.STRING)),
signature(
"emptyList",
list(typeParameter),
list(),
- parameterizedType(ScalarType.of("java.util.List"), list(typeParameter)))),
+ parameterizedType(ScalarType.topLevel("java.util.List"), list(typeParameter)))),
readExpression("java.util.List<String>", "java.util.Collections.<String>emptyList()"));
}
@@ -313,19 +313,19 @@ public class ExpressionReadingTests {
"emptyList",
list(Types.STRING),
list(),
- parameterizedType(ScalarType.of("java.util.List"), list(Types.STRING)),
+ parameterizedType(ScalarType.topLevel("java.util.List"), list(Types.STRING)),
signature(
"emptyList",
list(typeParameter),
list(),
- parameterizedType(ScalarType.of("java.util.List"), list(typeParameter)))),
+ parameterizedType(ScalarType.topLevel("java.util.List"), list(typeParameter)))),
readExpression("java.util.List<String>", "java.util.Collections.emptyList()"));
}
@Test
public void canReadConstructorCalls() {
assertEquals(
- constructorCall(ScalarType.of("java.lang.String"), list(literal("_"))),
+ constructorCall(ScalarType.topLevel("java.lang.String"), list(literal("_"))),
readExpression("String", "new String(\"_\")"));
}
@@ -343,20 +343,20 @@ public class ExpressionReadingTests {
public void canUseOperatorsOnReferences() {
assertEquals(
same(
- constructorCall(ScalarType.of("java.lang.Object"), emptyList()),
- constructorCall(ScalarType.of("java.lang.Object"), emptyList())),
+ constructorCall(ScalarType.topLevel("java.lang.Object"), emptyList()),
+ constructorCall(ScalarType.topLevel("java.lang.Object"), emptyList())),
readBooleanExpression("new Object() == new Object()"));
assertEquals(
not(same(
- constructorCall(ScalarType.of("java.lang.Object"), emptyList()),
- constructorCall(ScalarType.of("java.lang.Object"), emptyList()))),
+ constructorCall(ScalarType.topLevel("java.lang.Object"), emptyList()),
+ constructorCall(ScalarType.topLevel("java.lang.Object"), emptyList()))),
readBooleanExpression("new Object() != new Object()"));
assertEquals(
instanceOf(
- constructorCall(ScalarType.of("java.lang.Object"), emptyList()),
- ScalarType.of("java.lang.Object")),
+ constructorCall(ScalarType.topLevel("java.lang.Object"), emptyList()),
+ ScalarType.topLevel("java.lang.Object")),
readBooleanExpression("new Object() instanceof Object"));
}
@@ -417,13 +417,13 @@ public class ExpressionReadingTests {
assertEquals(
equal(
literal(1),
- unboxInt(constructorCall(ScalarType.of("java.lang.Integer"), list(literal(1))))),
+ unboxInt(constructorCall(ScalarType.topLevel("java.lang.Integer"), list(literal(1))))),
readBooleanExpression("1 == new Integer(1)"));
assertEquals(
notEqual(
literal(1),
- unboxInt(constructorCall(ScalarType.of("java.lang.Integer"), list(literal(1))))),
+ unboxInt(constructorCall(ScalarType.topLevel("java.lang.Integer"), list(literal(1))))),
readBooleanExpression("1 != new Integer(1)"));
}
@@ -446,8 +446,8 @@ public class ExpressionReadingTests {
public void integerOperatorUnboxesWhenBothOperandsAreBoxed() {
assertEquals(
integerAdd(
- unboxInt(constructorCall(ScalarType.of("java.lang.Integer"), list(literal(1)))),
- unboxInt(constructorCall(ScalarType.of("java.lang.Integer"), list(literal(2))))),
+ unboxInt(constructorCall(ScalarType.topLevel("java.lang.Integer"), list(literal(1)))),
+ unboxInt(constructorCall(ScalarType.topLevel("java.lang.Integer"), list(literal(2))))),
readIntExpression("new Integer(1) + new Integer(2)"));
}
@@ -470,7 +470,7 @@ public class ExpressionReadingTests {
assertEquals(
assign(
fieldAccess(
- thisReference(ScalarType.of("com.example.Example")),
+ thisReference(ScalarType.topLevel("com.example.Example")),
"name",
Types.STRING),
literal("blah")),
@@ -489,7 +489,7 @@ public class ExpressionReadingTests {
assertEquals(
assign(
fieldAccess(
- thisReference(ScalarType.of("com.example.Example")),
+ thisReference(ScalarType.topLevel("com.example.Example")),
"value",
Types.OBJECT),
typeCoercion(literal(4), Types.OBJECT)),
diff --git a/src/test/java/org/zwobble/couscous/tests/frontends/java/JavaReaderTests.java b/src/test/java/org/zwobble/couscous/tests/frontends/java/JavaReaderTests.java
index 7b208f5..7410324 100644
--- a/src/test/java/org/zwobble/couscous/tests/frontends/java/JavaReaderTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/frontends/java/JavaReaderTests.java
@@ -92,7 +92,7 @@ public class JavaReaderTests {
"}");
MethodNode method = classNode.getMethods().get(0);
- assertThat(method.getArguments(), contains(isFormalArgument("value", ScalarType.of("int"))));
+ assertThat(method.getArguments(), contains(isFormalArgument("value", ScalarType.topLevel("int"))));
ReturnNode returnNode = (ReturnNode)method.getBody().get().get(0);
assertEquals(reference(method.getArguments().get(0)), returnNode.getValue());
@@ -119,7 +119,7 @@ public class JavaReaderTests {
public void canReadThrowStatements() {
assertEquals(
throwNode(
- constructorCall(ScalarType.of("java.lang.RuntimeException"), list())),
+ constructorCall(ScalarType.topLevel("java.lang.RuntimeException"), list())),
readStatement("void", "throw new RuntimeException();"));
}
@@ -128,7 +128,7 @@ public class JavaReaderTests {
assertEquals(
expressionStatement(
staticMethodCall(
- ScalarType.of("java.lang.Integer"),
+ ScalarType.topLevel("java.lang.Integer"),
"parseInt",
list(literal("42")),
Types.INT)),
@@ -224,7 +224,7 @@ public class JavaReaderTests {
isTryStatement(
hasTryBody(list(returns(literal(1)))),
hasExceptionHandlers(
- isExceptionHandler(ScalarType.of("java.lang.Exception"), "exception", list(returns(literal(2)))))));
+ isExceptionHandler(ScalarType.topLevel("java.lang.Exception"), "exception", list(returns(literal(2)))))));
}
@Test
@@ -249,7 +249,7 @@ public class JavaReaderTests {
@Test
public void canReadTryWithResourceWithoutOtherClauses() {
- ScalarType type = ScalarType.of("java.io.ByteArrayOutputStream");
+ ScalarType type = ScalarType.topLevel("java.io.ByteArrayOutputStream");
Identifier identifier = MAIN_IDENTIFIER.variable("closeable");
LocalVariableDeclarationNode expectedResource = localVariableDeclaration(identifier, "closeable", type, constructorCall(type, list()));
assertThat(
@@ -292,7 +292,7 @@ public class JavaReaderTests {
assertEquals(
list(assignStatement(
fieldAccess(
- thisReference(ScalarType.of("com.example.Example")),
+ thisReference(ScalarType.topLevel("com.example.Example")),
"name",
Types.STRING),
literal("Flaws"))),
@@ -315,13 +315,13 @@ public class JavaReaderTests {
list(
assignStatement(
fieldAccess(
- thisReference(ScalarType.of("com.example.Example")),
+ thisReference(ScalarType.topLevel("com.example.Example")),
"year",
Types.INT),
literal(2013)),
assignStatement(
fieldAccess(
- thisReference(ScalarType.of("com.example.Example")),
+ thisReference(ScalarType.topLevel("com.example.Example")),
"name",
Types.STRING),
literal("Flaws"))),
@@ -343,13 +343,13 @@ public class JavaReaderTests {
list(
assignStatement(
fieldAccess(
- thisReference(ScalarType.of("com.example.Example")),
+ thisReference(ScalarType.topLevel("com.example.Example")),
"year",
Types.INT),
literal(2013)),
assignStatement(
fieldAccess(
- thisReference(ScalarType.of("com.example.Example")),
+ thisReference(ScalarType.topLevel("com.example.Example")),
"name",
Types.STRING),
literal("Flaws"))),
@@ -369,7 +369,7 @@ public class JavaReaderTests {
assertEquals(
list(assignStatement(
fieldAccess(
- ScalarType.of("com.example.Example"),
+ ScalarType.topLevel("com.example.Example"),
"name",
Types.STRING),
literal("Flaws"))),
@@ -386,7 +386,7 @@ public class JavaReaderTests {
assertEquals(
list(assignStatement(
fieldAccess(
- ScalarType.of("com.example.Example"),
+ ScalarType.topLevel("com.example.Example"),
"name",
Types.STRING),
literal("Flaws"))),
@@ -400,7 +400,7 @@ public class JavaReaderTests {
MethodNode method = classNode.getMethods().get(0);
assertEquals(
- list(annotation(ScalarType.of("java.lang.Deprecated"))),
+ list(annotation(ScalarType.topLevel("java.lang.Deprecated"))),
method.getAnnotations());
}
@@ -422,7 +422,7 @@ public class JavaReaderTests {
List<TypeNode> classes = readSource("com/example/Example.java", source);
assertThat(classes, hasSize(1));
InterfaceNode classNode = (InterfaceNode) classes.get(0);
- assertEquals(ScalarType.of("com.example.Example"), classNode.getName());
+ assertEquals(ScalarType.topLevel("com.example.Example"), classNode.getName());
assertEquals(list(), classNode.getMethods());
assertEquals(set(), classNode.getSuperTypes());
assertEquals(list(), classNode.getTypeParameters());
@@ -435,7 +435,7 @@ public class JavaReaderTests {
List<TypeNode> classes = readSource("com/example/Example.java", source);
assertThat(classes, hasSize(1));
ClassNode classNode = (ClassNode) classes.get(0);
- assertEquals(ScalarType.of("com.example.Example"), classNode.getName());
+ assertEquals(ScalarType.topLevel("com.example.Example"), classNode.getName());
assertEquals(list(formalTypeParameter(Identifier.forType("com.example.Example"), "T")), classNode.getTypeParameters());
}
@@ -446,7 +446,7 @@ public class JavaReaderTests {
List<TypeNode> classes = readSource("com/example/Example.java", source);
assertThat(classes, hasSize(1));
InterfaceNode classNode = (InterfaceNode) classes.get(0);
- assertEquals(ScalarType.of("com.example.Example"), classNode.getName());
+ assertEquals(ScalarType.topLevel("com.example.Example"), classNode.getName());
assertEquals(list(formalTypeParameter(Identifier.forType("com.example.Example"), "T")), classNode.getTypeParameters());
}
@@ -457,9 +457,9 @@ public class JavaReaderTests {
List<TypeNode> classes = readSource("com/example/Example.java", source);
assertThat(classes, hasSize(1));
InterfaceNode classNode = (InterfaceNode) classes.get(0);
- assertEquals(ScalarType.of("com.example.Example"), classNode.getName());
+ assertEquals(ScalarType.topLevel("com.example.Example"), classNode.getName());
assertEquals(list(), classNode.getMethods());
- assertThat(classNode.getSuperTypes(), contains(ScalarType.of("java.util.function.IntSupplier")));
+ assertThat(classNode.getSuperTypes(), contains(ScalarType.topLevel("java.util.function.IntSupplier")));
}
@Test
@@ -493,7 +493,7 @@ public class JavaReaderTests {
assertEquals(
list(
assignStatement(
- FieldAccessNode.fieldAccess(ScalarType.of("com.example.Example"), "VALUE", Types.INT),
+ FieldAccessNode.fieldAccess(ScalarType.topLevel("com.example.Example"), "VALUE", Types.INT),
literal(1)
)
),
@@ -508,7 +508,7 @@ public class JavaReaderTests {
List<TypeNode> classes = readSource("com/example/Example.java", source);
assertThat(classes, hasSize(1));
EnumNode node = (EnumNode) classes.get(0);
- assertEquals(ScalarType.of("com.example.Example"), node.getName());
+ assertEquals(ScalarType.topLevel("com.example.Example"), node.getName());
}
@Test
@@ -518,7 +518,7 @@ public class JavaReaderTests {
List<TypeNode> classes = readSource("com/example/Example.java", source);
assertThat(classes, hasSize(1));
EnumNode node = (EnumNode) classes.get(0);
- assertEquals(ScalarType.of("com.example.Example"), node.getName());
+ assertEquals(ScalarType.topLevel("com.example.Example"), node.getName());
assertEquals(list("ONE", "TWO"), node.getValues());
}
diff --git a/src/test/java/org/zwobble/couscous/tests/frontends/java/JavaTypesTests.java b/src/test/java/org/zwobble/couscous/tests/frontends/java/JavaTypesTests.java
index f903eeb..f256fa9 100644
--- a/src/test/java/org/zwobble/couscous/tests/frontends/java/JavaTypesTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/frontends/java/JavaTypesTests.java
@@ -13,7 +13,7 @@ import static org.zwobble.couscous.types.TypeParameter.typeParameter;
import static org.zwobble.couscous.util.ExtraLists.list;
public class JavaTypesTests {
- private static final ScalarType INT_TYPE = ScalarType.of("int");
+ private static final ScalarType INT_TYPE = ScalarType.topLevel("int");
@Test
public void bindingTypeToItselfReturnsType() {
@@ -32,7 +32,7 @@ public class JavaTypesTests {
@Test
public void bindingTypeToParameterizedTypeBindsParameters() {
- ScalarType rawList = ScalarType.of("List");
+ ScalarType rawList = ScalarType.topLevel("List");
TypeParameter typeParameter = typeParameter(Identifier.forType("List"), "T");
assertEquals(
parameterizedType(rawList, list(boundTypeParameter(typeParameter, INT_TYPE))),