aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-01-08 08:42:49 +0000
committerMichael Williamson <mike@zwobble.org>2016-01-08 08:42:49 +0000
commit0577f8637123c92fa6c1d4e27e0d2281c9a6b519 (patch)
treeedaa735a2582030b1d6da5a66eef15e90bcc40bc /src/test/java/org
parent17072b4d14dad00acac247508e35b52c0233170b (diff)
Use list() to create lists of fixed size
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/couscous/tests/BackendEvalTests.java31
-rw-r--r--src/test/java/org/zwobble/couscous/tests/BackendMethodTests.java15
-rw-r--r--src/test/java/org/zwobble/couscous/tests/CompilerTests.java23
-rw-r--r--src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java3
-rw-r--r--src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java3
-rw-r--r--src/test/java/org/zwobble/couscous/tests/ValueObjectTests.java7
-rw-r--r--src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerEvalTests.java5
-rw-r--r--src/test/java/org/zwobble/couscous/tests/backends/python/PythonSerializerTests.java17
-rw-r--r--src/test/java/org/zwobble/couscous/tests/frontends/java/FreeVariablesTests.java9
-rw-r--r--src/test/java/org/zwobble/couscous/tests/frontends/java/JavaReaderTests.java55
-rw-r--r--src/test/java/org/zwobble/couscous/tests/interpreter/EvaluatorTests.java33
-rw-r--r--src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterMethodTests.java3
12 files changed, 108 insertions, 96 deletions
diff --git a/src/test/java/org/zwobble/couscous/tests/BackendEvalTests.java b/src/test/java/org/zwobble/couscous/tests/BackendEvalTests.java
index 9d6bb9f..3ca5a1a 100644
--- a/src/test/java/org/zwobble/couscous/tests/BackendEvalTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/BackendEvalTests.java
@@ -30,6 +30,7 @@ import static org.zwobble.couscous.ast.TernaryConditionalNode.ternaryConditional
import static org.zwobble.couscous.ast.VariableDeclaration.var;
import static org.zwobble.couscous.ast.VariableReferenceNode.reference;
import static org.zwobble.couscous.tests.TestIds.ANY_ID;
+import static org.zwobble.couscous.util.ExtraLists.list;
import static org.zwobble.couscous.values.PrimitiveValues.value;
public abstract class BackendEvalTests {
@@ -129,7 +130,7 @@ public abstract class BackendEvalTests {
PrimitiveValue result = evalExpression(methodCall(
literal("hello"),
"length",
- asList(),
+ list(),
IntegerValue.REF));
assertEquals(value(5), result);
}
@@ -139,7 +140,7 @@ public abstract class BackendEvalTests {
PrimitiveValue result = evalExpression(methodCall(
literal("hello"),
"substring",
- asList(literal(1), literal(4)),
+ list(literal(1), literal(4)),
StringValue.REF));
assertEquals(value("ell"), result);
}
@@ -149,7 +150,7 @@ public abstract class BackendEvalTests {
PrimitiveValue result = evalExpression(staticMethodCall(
"java.lang.Integer",
"parseInt",
- asList(literal("42")),
+ list(literal("42")),
IntegerValue.REF));
assertEquals(value(42), result);
}
@@ -161,11 +162,11 @@ public abstract class BackendEvalTests {
.statement(returns(staticMethodCall(
"java.lang.Integer",
"parseInt",
- asList(literal("42")),
+ list(literal("42")),
IntegerValue.REF))))
.build();
- PrimitiveValue result = evalExpression(asList(classNode),
- staticMethodCall("com.example.Example", "main", asList(), IntegerValue.REF));
+ PrimitiveValue result = evalExpression(list(classNode),
+ staticMethodCall("com.example.Example", "main", list(), IntegerValue.REF));
assertEquals(value(42), result);
}
@@ -175,8 +176,8 @@ public abstract class BackendEvalTests {
.method("main", method -> method
.statement(returns(literal(42))))
.build();
- PrimitiveValue result = evalExpression(asList(classNode),
- methodCall(constructorCall(classNode.getName(), asList()), "main", asList(), IntegerValue.REF));
+ PrimitiveValue result = evalExpression(list(classNode),
+ methodCall(constructorCall(classNode.getName(), list()), "main", list(), IntegerValue.REF));
assertEquals(value(42), result);
}
@@ -190,11 +191,11 @@ public abstract class BackendEvalTests {
.build();
PrimitiveValue result = evalExpression(
- asList(classNode),
+ list(classNode),
methodCall(
- constructorCall(classNode.getName(), asList()),
+ constructorCall(classNode.getName(), list()),
"main",
- asList(literal(42)),
+ list(literal(42)),
IntegerValue.REF));
assertEquals(value(42), result);
@@ -216,18 +217,18 @@ public abstract class BackendEvalTests {
.build();
PrimitiveValue result = evalExpression(
- asList(classNode),
+ list(classNode),
methodCall(
- constructorCall(classNode.getName(), asList(literal(42))),
+ constructorCall(classNode.getName(), list(literal(42))),
"main",
- asList(),
+ list(),
IntegerValue.REF));
assertEquals(value(42), result);
}
private PrimitiveValue evalExpression(ExpressionNode expression) {
- return evalExpression(ImmutableList.of(), expression);
+ return evalExpression(list(), expression);
}
protected abstract PrimitiveValue evalExpression(
diff --git a/src/test/java/org/zwobble/couscous/tests/BackendMethodTests.java b/src/test/java/org/zwobble/couscous/tests/BackendMethodTests.java
index a5a8d2c..1f34127 100644
--- a/src/test/java/org/zwobble/couscous/tests/BackendMethodTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/BackendMethodTests.java
@@ -28,6 +28,7 @@ import static org.zwobble.couscous.ast.VariableDeclaration.var;
import static org.zwobble.couscous.ast.VariableReferenceNode.reference;
import static org.zwobble.couscous.ast.WhileNode.whileLoop;
import static org.zwobble.couscous.tests.TestIds.ANY_ID;
+import static org.zwobble.couscous.util.ExtraLists.list;
import static org.zwobble.couscous.values.PrimitiveValues.value;
public abstract class BackendMethodTests {
@@ -97,8 +98,8 @@ public abstract class BackendMethodTests {
MethodNode.Builder method = staticMethod("hello")
.statement(ifStatement(
literal(true),
- asList(returns(literal("[true]"))),
- asList(returns(literal("[false]")))));
+ list(returns(literal("[true]"))),
+ list(returns(literal("[false]")))));
assertEquals(value("[true]"), runMethod(method));
}
@@ -107,8 +108,8 @@ public abstract class BackendMethodTests {
MethodNode.Builder method = staticMethod("hello")
.statement(ifStatement(
literal(false),
- asList(returns(literal("[true]"))),
- asList(returns(literal("[false]")))));
+ list(returns(literal("[true]"))),
+ list(returns(literal("[false]")))));
assertEquals(value("[false]"), runMethod(method));
}
@@ -121,7 +122,7 @@ public abstract class BackendMethodTests {
.statement(y)
.statement(whileLoop(
notEqual(reference(x), reference(y)),
- asList(assignStatement(x, integerAdd(reference(x), literal(1))))))
+ list(assignStatement(x, integerAdd(reference(x), literal(1))))))
.statement(returns(reference(x)));
assertEquals(value(2), runMethod(method));
}
@@ -135,7 +136,7 @@ public abstract class BackendMethodTests {
.statement(y)
.statement(whileLoop(
notEqual(reference(x), reference(y)),
- asList(
+ list(
assignStatement(x, integerAdd(reference(x), literal(1))),
returns(reference(x)))))
.statement(returns(reference(x)));
@@ -147,7 +148,7 @@ public abstract class BackendMethodTests {
String className = "com.example.Program";
ClassNode classNode = ClassNode.builder(className).method(method).build();
MethodRunner runner = buildMethodRunner();
- return runner.runMethod(asList(classNode), classNode.getName(), method.getName(), asList(arguments));
+ return runner.runMethod(list(classNode), classNode.getName(), method.getName(), asList(arguments));
}
protected abstract MethodRunner buildMethodRunner();
diff --git a/src/test/java/org/zwobble/couscous/tests/CompilerTests.java b/src/test/java/org/zwobble/couscous/tests/CompilerTests.java
index 710db7d..ea12bc4 100644
--- a/src/test/java/org/zwobble/couscous/tests/CompilerTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/CompilerTests.java
@@ -15,6 +15,7 @@ import java.util.List;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.zwobble.couscous.tests.util.ExtraFiles.deleteRecursively;
+import static org.zwobble.couscous.util.ExtraLists.list;
import static org.zwobble.couscous.values.PrimitiveValues.value;
public abstract class CompilerTests {
@@ -52,7 +53,7 @@ public abstract class CompilerTests {
"recursive-factorial",
TypeName.of("com.example.RecursiveFactorial"),
"factorial",
- asList(value(6))));
+ list(value(6))));
}
@Test
@@ -63,7 +64,7 @@ public abstract class CompilerTests {
"while-factorial",
TypeName.of("com.example.WhileFactorial"),
"factorial",
- asList(value(6))));
+ list(value(6))));
}
@Test
@@ -74,7 +75,7 @@ public abstract class CompilerTests {
"for-factorial",
TypeName.of("com.example.ForFactorial"),
"factorial",
- asList(value(6))));
+ list(value(6))));
}
@Test
@@ -85,7 +86,7 @@ public abstract class CompilerTests {
"anonymous-class",
TypeName.of("com.example.AnonymousClass"),
"value",
- asList()));
+ list()));
}
@Test
@@ -96,7 +97,7 @@ public abstract class CompilerTests {
"anonymous-class-capture",
TypeName.of("com.example.AnonymousClass"),
"value",
- asList(value(42))));
+ list(value(42))));
}
@Test
@@ -107,7 +108,7 @@ public abstract class CompilerTests {
"lambda",
TypeName.of("com.example.Lambda"),
"value",
- asList()));
+ list()));
}
@Test
@@ -118,7 +119,7 @@ public abstract class CompilerTests {
"lambda-capture",
TypeName.of("com.example.Lambda"),
"value",
- asList(value(2))));
+ list(value(2))));
}
@Test
@@ -129,7 +130,7 @@ public abstract class CompilerTests {
"lambda-this-capture",
TypeName.of("com.example.Lambda"),
"value",
- asList(value(2))));
+ list(value(2))));
}
@Test
@@ -140,7 +141,7 @@ public abstract class CompilerTests {
"static-method-overloads",
TypeName.of("com.example.StaticMethodOverloads"),
"value",
- asList()));
+ list()));
}
private PrimitiveValue execTestProgram(
@@ -182,12 +183,12 @@ public abstract class CompilerTests {
Path directoryPath = Files.createTempDirectory(null);
try {
Files.createDirectories(directoryPath.resolve("com/example"));
- Files.write(directoryPath.resolve("com/example/Example.java"), asList(javaClass));
+ Files.write(directoryPath.resolve("com/example/Example.java"), list(javaClass));
return execProgram(
directoryPath,
TypeName.of("com.example.Example"),
"main",
- asList());
+ list());
} finally {
deleteRecursively(directoryPath.toFile());
}
diff --git a/src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java b/src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java
index 8008261..59cc6d6 100644
--- a/src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/JavaToInterpreterTests.java
@@ -16,6 +16,7 @@ import java.nio.file.Path;
import java.util.List;
import static com.google.common.collect.Iterables.transform;
+import static org.zwobble.couscous.util.ExtraLists.list;
public class JavaToInterpreterTests extends CompilerTests {
@Override
@@ -26,7 +27,7 @@ public class JavaToInterpreterTests extends CompilerTests {
List<PrimitiveValue> arguments
) throws IOException, InterruptedException {
JavaFrontend frontend = new JavaFrontend();
- List<ClassNode> classNodes = frontend.readSourceDirectory(ImmutableList.of(directory), directory);
+ List<ClassNode> classNodes = frontend.readSourceDirectory(list(directory), directory);
Project project = JavaProject.of(classNodes);
Interpreter interpreter = new Interpreter(project);
diff --git a/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java b/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java
index d2d62b1..a0d1c7e 100644
--- a/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java
@@ -16,6 +16,7 @@ import java.nio.file.Path;
import java.util.List;
import static org.zwobble.couscous.tests.util.ExtraFiles.deleteRecursively;
+import static org.zwobble.couscous.util.ExtraLists.list;
public class JavaToPythonTests extends CompilerTests {
protected PrimitiveValue execProgram(
@@ -29,7 +30,7 @@ public class JavaToPythonTests extends CompilerTests {
CouscousCompiler compiler = new CouscousCompiler(
new JavaFrontend(),
new PythonBackend(directoryPath, "couscous"));
- compiler.compileDirectory(ImmutableList.of(directory), directory);
+ compiler.compileDirectory(list(directory), directory);
return PythonMethodRunner.runFunction(directoryPath, type, methodName, arguments);
} finally {
deleteRecursively(directoryPath.toFile());
diff --git a/src/test/java/org/zwobble/couscous/tests/ValueObjectTests.java b/src/test/java/org/zwobble/couscous/tests/ValueObjectTests.java
index 4366ac4..e74ac78 100644
--- a/src/test/java/org/zwobble/couscous/tests/ValueObjectTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/ValueObjectTests.java
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.zwobble.couscous.util.ExtraArrays.stream;
import static org.zwobble.couscous.util.ExtraLists.eagerFilter;
+import static org.zwobble.couscous.util.ExtraLists.list;
@RunWith(Parameterized.class)
public class ValueObjectTests {
@@ -130,7 +131,7 @@ public class ValueObjectTests {
} else if (type.equals(boolean.class)) {
return true;
} else if (type.equals(List.class)) {
- return asList("[list 1]");
+ return list("[list 1]");
} else if (type.equals(Set.class)) {
return Collections.singleton("[set 1]");
} else if (type.equals(Identifier.class)) {
@@ -152,7 +153,7 @@ public class ValueObjectTests {
} else if (type.equals(boolean.class)) {
return false;
} else if (type.equals(List.class)) {
- return asList("[list 2]");
+ return list("[list 2]");
} else if (type.equals(Set.class)) {
return Collections.singleton("[set 2]");
} else if (type.equals(Identifier.class)) {
@@ -174,7 +175,7 @@ public class ValueObjectTests {
} else if (type.equals(boolean.class)) {
return true;
} else if (type.equals(List.class)) {
- return asList("[list]");
+ return list("[list]");
} else if (type.equals(Set.class)) {
return Collections.singleton("[set]");
} else if (type.equals(Identifier.class)) {
diff --git a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerEvalTests.java b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerEvalTests.java
index c5c7aab..61f5c38 100644
--- a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerEvalTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonCompilerEvalTests.java
@@ -10,6 +10,7 @@ import org.zwobble.couscous.values.PrimitiveValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import static java.util.Arrays.asList;
+import static org.zwobble.couscous.util.ExtraLists.list;
public class PythonCompilerEvalTests extends BackendEvalTests {
@Override
@@ -23,9 +24,9 @@ public class PythonCompilerEvalTests extends BackendEvalTests {
return runner.runMethod(
ImmutableList.copyOf(Iterables.concat(
classes,
- asList(programNode))),
+ list(programNode))),
programNode.getName(),
"run",
- ImmutableList.of());
+ list());
}
} \ No newline at end of file
diff --git a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonSerializerTests.java b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonSerializerTests.java
index 9411d3e..59ab22c 100644
--- a/src/test/java/org/zwobble/couscous/tests/backends/python/PythonSerializerTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/backends/python/PythonSerializerTests.java
@@ -26,6 +26,7 @@ import static org.zwobble.couscous.backends.python.ast.PythonReturnNode.pythonRe
import static org.zwobble.couscous.backends.python.ast.PythonStringLiteralNode.pythonStringLiteral;
import static org.zwobble.couscous.backends.python.ast.PythonVariableReferenceNode.pythonVariableReference;
import static org.zwobble.couscous.backends.python.ast.PythonWhileNode.pythonWhile;
+import static org.zwobble.couscous.util.ExtraLists.list;
public class PythonSerializerTests {
@Test
@@ -69,12 +70,12 @@ public class PythonSerializerTests {
@Test
public void callIsSerializedUsingParenthesisedSubExpression() {
- assertEquals("(f)(x, y)", serialize(pythonCall(pythonVariableReference("f"), asList(pythonVariableReference("x"), pythonVariableReference("y")))));
+ assertEquals("(f)(x, y)", serialize(pythonCall(pythonVariableReference("f"), list(pythonVariableReference("x"), pythonVariableReference("y")))));
}
@Test
public void getSliceIsSerializedUsingParenthesisedSubExpression() {
- assertEquals("(x)[y:z]", serialize(pythonGetSlice(pythonVariableReference("x"), asList(pythonVariableReference("y"), pythonVariableReference("z")))));
+ assertEquals("(x)[y:z]", serialize(pythonGetSlice(pythonVariableReference("x"), list(pythonVariableReference("y"), pythonVariableReference("z")))));
}
@Test
@@ -148,7 +149,7 @@ public class PythonSerializerTests {
public void importIsSerializedUsingImportKeyword() {
String output = serialize(pythonImport(
"com.example",
- asList(pythonImportAlias("Program"))));
+ list(pythonImportAlias("Program"))));
assertEquals("from com.example import Program\n", output);
}
@@ -156,7 +157,7 @@ public class PythonSerializerTests {
public void importAliasesAreSeparatedByCommas() {
String output = serialize(pythonImport(
"com.example",
- asList(pythonImportAlias("Program"),pythonImportAlias("Runner"))));
+ list(pythonImportAlias("Program"),pythonImportAlias("Runner"))));
assertEquals("from com.example import Program, Runner\n", output);
}
@@ -164,8 +165,8 @@ public class PythonSerializerTests {
public void ifStatementIsSerializedWithIfKeyword() {
String output = serialize(pythonIfStatement(
pythonBooleanLiteral(true),
- asList(pythonReturn(pythonIntegerLiteral(1))),
- asList(pythonReturn(pythonIntegerLiteral(2)))));
+ list(pythonReturn(pythonIntegerLiteral(1))),
+ list(pythonReturn(pythonIntegerLiteral(2)))));
assertEquals("if True:\n return 1\nelse:\n return 2\n", output);
}
@@ -173,13 +174,13 @@ public class PythonSerializerTests {
public void whileIsSerializedWithWhileKeyword() {
String output = serialize(pythonWhile(
pythonBooleanLiteral(true),
- asList(pythonReturn(pythonIntegerLiteral(1)))));
+ list(pythonReturn(pythonIntegerLiteral(1)))));
assertEquals("while True:\n return 1\n", output);
}
@Test
public void moduleIsSerializedStatements() {
- PythonModuleNode classNode = pythonModule(asList(PASS));
+ PythonModuleNode classNode = pythonModule(list(PASS));
String output = serialize(classNode);
assertEquals("pass\n", output);
}
diff --git a/src/test/java/org/zwobble/couscous/tests/frontends/java/FreeVariablesTests.java b/src/test/java/org/zwobble/couscous/tests/frontends/java/FreeVariablesTests.java
index 7cf349d..84e9508 100644
--- a/src/test/java/org/zwobble/couscous/tests/frontends/java/FreeVariablesTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/frontends/java/FreeVariablesTests.java
@@ -17,20 +17,21 @@ import static org.zwobble.couscous.ast.LocalVariableDeclarationNode.localVariabl
import static org.zwobble.couscous.ast.VariableDeclaration.var;
import static org.zwobble.couscous.ast.VariableReferenceNode.reference;
import static org.zwobble.couscous.frontends.java.FreeVariables.findFreeVariables;
+import static org.zwobble.couscous.util.ExtraLists.list;
public class FreeVariablesTests {
@Test
public void referenceIsFreeIfThereIsNoAssociatedDeclaration() {
VariableDeclaration declaration = var(TestIds.ANY_ID, "[name]", StringValue.REF);
- List<ReferenceNode> freeVariables = findFreeVariables(asList(reference(declaration)));
- assertEquals(asList(reference(declaration)), freeVariables);
+ List<ReferenceNode> freeVariables = findFreeVariables(list(reference(declaration)));
+ assertEquals(list(reference(declaration)), freeVariables);
}
@Test
public void referenceIsNotFreeIfIsDeclaredAsArgument() {
VariableDeclaration declaration = var(TestIds.ANY_ID, "[name]", StringValue.REF);
List<ReferenceNode> freeVariables = findFreeVariables(
- asList(formalArg(declaration), reference(declaration)));
+ list(formalArg(declaration), reference(declaration)));
assertEquals(emptyList(), freeVariables);
}
@@ -38,7 +39,7 @@ public class FreeVariablesTests {
public void referenceIsNotFreeIfIsReferenceToLocalDefinedInBody() {
VariableDeclaration declaration = var(TestIds.ANY_ID, "[name]", StringValue.REF);
List<ReferenceNode> freeVariables = findFreeVariables(
- asList(
+ list(
localVariableDeclaration(declaration, literal("[value]")),
reference(declaration)));
assertEquals(emptyList(), freeVariables);
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 5548b2f..46e010c 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
@@ -37,6 +37,7 @@ import static org.zwobble.couscous.ast.TypeCoercionNode.typeCoercion;
import static org.zwobble.couscous.ast.VariableReferenceNode.reference;
import static org.zwobble.couscous.ast.WhileNode.whileLoop;
import static org.zwobble.couscous.tests.util.ExtraFiles.deleteRecursively;
+import static org.zwobble.couscous.util.ExtraLists.list;
public class JavaReaderTests {
@Test
@@ -61,7 +62,7 @@ public class JavaReaderTests {
"private String name;");
assertEquals(
- asList(field("name", TypeName.of("java.lang.String"))),
+ list(field("name", TypeName.of("java.lang.String"))),
classNode.getFields());
}
@@ -94,14 +95,14 @@ public class JavaReaderTests {
@Test
public void canReadInstanceMethodCalls() {
assertEquals(
- methodCall(literal("hello"), "startsWith", asList(literal("h")), BooleanValue.REF),
+ methodCall(literal("hello"), "startsWith", list(literal("h")), BooleanValue.REF),
readBooleanExpression("\"hello\".startsWith(\"h\")"));
List<StatementNode> statements = readStatements("int", "Object x = 1; return x.hashCode();");
LocalVariableDeclarationNode declaration = (LocalVariableDeclarationNode) statements.get(0);
ReturnNode returnNode = (ReturnNode) statements.get(1);
assertEquals(
- methodCall(reference(declaration), "hashCode", asList(), IntegerValue.REF),
+ methodCall(reference(declaration), "hashCode", list(), IntegerValue.REF),
returnNode.getValue());
}
@@ -117,7 +118,7 @@ public class JavaReaderTests {
methodCall(
ThisReferenceNode.thisReference(TypeName.of("com.example.Example")),
"loop",
- asList(),
+ list(),
StringValue.REF),
returnNode.getValue());
}
@@ -128,7 +129,7 @@ public class JavaReaderTests {
staticMethodCall(
TypeName.of("java.lang.Integer"),
"parseInt",
- asList(literal("42")),
+ list(literal("42")),
IntegerValue.REF),
readIntExpression("Integer.parseInt(\"42\")"));
}
@@ -145,7 +146,7 @@ public class JavaReaderTests {
staticMethodCall(
TypeName.of("com.example.Example"),
"loop",
- asList(),
+ list(),
StringValue.REF),
returnNode.getValue());
}
@@ -153,7 +154,7 @@ public class JavaReaderTests {
@Test
public void canReadConstructorCalls() {
assertEquals(
- constructorCall(TypeName.of("java.lang.String"), asList(literal("_"))),
+ constructorCall(TypeName.of("java.lang.String"), list(literal("_"))),
readExpression("String", "new String(\"_\")"));
}
@@ -274,13 +275,13 @@ public class JavaReaderTests {
assertEquals(
equal(
literal(1),
- unboxInt(constructorCall(TypeName.of("java.lang.Integer"), asList(literal(1))))),
+ unboxInt(constructorCall(TypeName.of("java.lang.Integer"), list(literal(1))))),
readBooleanExpression("1 == new Integer(1)"));
assertEquals(
notEqual(
literal(1),
- unboxInt(constructorCall(TypeName.of("java.lang.Integer"), asList(literal(1))))),
+ unboxInt(constructorCall(TypeName.of("java.lang.Integer"), list(literal(1))))),
readBooleanExpression("1 != new Integer(1)"));
}
@@ -288,14 +289,14 @@ public class JavaReaderTests {
public void equalityOperatorDoesNotUnboxIfBothOperandsAreBoxed() {
assertEquals(
same(
- typeCoercion(constructorCall(ObjectValues.BOXED_INT, asList(literal(1))), ObjectValues.OBJECT),
- typeCoercion(constructorCall(ObjectValues.BOXED_INT, asList(literal(2))), ObjectValues.OBJECT)),
+ typeCoercion(constructorCall(ObjectValues.BOXED_INT, list(literal(1))), ObjectValues.OBJECT),
+ typeCoercion(constructorCall(ObjectValues.BOXED_INT, list(literal(2))), ObjectValues.OBJECT)),
readBooleanExpression("new Integer(1) == new Integer(2)"));
assertEquals(
not(same(
- typeCoercion(constructorCall(ObjectValues.BOXED_INT, asList(literal(1))), ObjectValues.OBJECT),
- typeCoercion(constructorCall(ObjectValues.BOXED_INT, asList(literal(2))), ObjectValues.OBJECT))),
+ typeCoercion(constructorCall(ObjectValues.BOXED_INT, list(literal(1))), ObjectValues.OBJECT),
+ typeCoercion(constructorCall(ObjectValues.BOXED_INT, list(literal(2))), ObjectValues.OBJECT))),
readBooleanExpression("new Integer(1) != new Integer(2)"));
}
@@ -303,8 +304,8 @@ public class JavaReaderTests {
public void integerOperatorUnboxesWhenBothOperandsAreBoxed() {
assertEquals(
integerAdd(
- unboxInt(constructorCall(TypeName.of("java.lang.Integer"), asList(literal(1)))),
- unboxInt(constructorCall(TypeName.of("java.lang.Integer"), asList(literal(2))))),
+ unboxInt(constructorCall(TypeName.of("java.lang.Integer"), list(literal(1)))),
+ unboxInt(constructorCall(TypeName.of("java.lang.Integer"), list(literal(2))))),
readIntExpression("new Integer(1) + new Integer(2)"));
}
@@ -506,7 +507,7 @@ public class JavaReaderTests {
staticMethodCall(
TypeName.of("java.lang.Integer"),
"parseInt",
- asList(literal("42")),
+ list(literal("42")),
IntegerValue.REF)),
readStatement("Integer.parseInt(\"42\");"));
}
@@ -516,8 +517,8 @@ public class JavaReaderTests {
assertEquals(
ifStatement(
literal(true),
- asList(returns(literal(1))),
- asList(returns(literal(2)))),
+ list(returns(literal(1))),
+ list(returns(literal(2)))),
readStatement("int", "if (true) { return 1; } else { return 2; }"));
}
@@ -526,7 +527,7 @@ public class JavaReaderTests {
assertEquals(
whileLoop(
literal(true),
- asList(returns(literal(1)))),
+ list(returns(literal(1)))),
readStatement("int", "while (true) { return 1; }"));
}
@@ -535,11 +536,11 @@ public class JavaReaderTests {
List<StatementNode> statements = readStatements("int", "for (int x = 0; true; ++x) { return 1; }");
LocalVariableDeclarationNode declaration = (LocalVariableDeclarationNode) statements.get(0);
assertEquals(
- asList(
+ list(
localVariableDeclaration(declaration.getDeclaration(), literal(0)),
whileLoop(
literal(true),
- asList(
+ list(
returns(literal(1)),
expressionStatement(assign(declaration, integerAdd(reference(declaration), literal(1))))))),
statements);
@@ -555,10 +556,10 @@ public class JavaReaderTests {
ConstructorNode constructor = classNode.getConstructor();
- assertEquals(asList(), constructor.getArguments());
+ assertEquals(list(), constructor.getArguments());
assertEquals(
- asList(assignStatement(
+ list(assignStatement(
fieldAccess(
thisReference(TypeName.of("com.example.Example")),
"name",
@@ -574,7 +575,7 @@ public class JavaReaderTests {
MethodNode method = classNode.getMethods().get(0);
assertEquals(
- asList(annotation(TypeName.of("java.lang.Deprecated"))),
+ list(annotation(TypeName.of("java.lang.Deprecated"))),
method.getAnnotations());
}
@@ -585,7 +586,7 @@ public class JavaReaderTests {
MethodNode method = classNode.getMethods().get(0);
assertEquals(
- asList(returns(boxInt(literal(1)))),
+ list(returns(boxInt(literal(1)))),
method.getBody());
}
@@ -645,9 +646,9 @@ public class JavaReaderTests {
Path sourcePath = directoryPath.resolve("com/example/Example.java");
try {
Files.createDirectories(directoryPath.resolve("com/example"));
- Files.write(sourcePath, asList(javaClass));
+ Files.write(sourcePath, list(javaClass));
- return JavaReader.readClassFromFile(ImmutableList.of(directoryPath), sourcePath);
+ return JavaReader.readClassFromFile(list(directoryPath), sourcePath);
} finally {
deleteRecursively(directoryPath.toFile());
}
diff --git a/src/test/java/org/zwobble/couscous/tests/interpreter/EvaluatorTests.java b/src/test/java/org/zwobble/couscous/tests/interpreter/EvaluatorTests.java
index f3087ed..f9d57b8 100644
--- a/src/test/java/org/zwobble/couscous/tests/interpreter/EvaluatorTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/interpreter/EvaluatorTests.java
@@ -34,6 +34,7 @@ import static org.zwobble.couscous.interpreter.Evaluator.eval;
import static org.zwobble.couscous.interpreter.values.InterpreterValues.value;
import static org.zwobble.couscous.tests.TestIds.ANY_ID;
import static org.zwobble.couscous.tests.util.ExtraAsserts.assertThrows;
+import static org.zwobble.couscous.util.ExtraLists.list;
public class EvaluatorTests extends BackendEvalTests {
@Test
@@ -62,9 +63,9 @@ public class EvaluatorTests extends BackendEvalTests {
methodCall(
literal("hello"),
"size",
- asList(),
+ list(),
IntegerValue.REF)));
- assertEquals(new MethodSignature("size", asList()), exception.getSignature());
+ assertEquals(new MethodSignature("size", list()), exception.getSignature());
}
@Test
@@ -74,9 +75,9 @@ public class EvaluatorTests extends BackendEvalTests {
methodCall(
literal("hello"),
"substring",
- asList(literal(1)),
+ list(literal(1)),
StringValue.REF)));
- assertEquals(new MethodSignature("substring", asList(IntegerValue.REF)), exception.getSignature());
+ assertEquals(new MethodSignature("substring", list(IntegerValue.REF)), exception.getSignature());
}
@Test
@@ -86,10 +87,10 @@ public class EvaluatorTests extends BackendEvalTests {
methodCall(
literal("hello"),
"substring",
- asList(literal(0), literal("")),
+ list(literal(0), literal("")),
StringValue.REF)));
assertEquals(
- new MethodSignature("substring", asList(IntegerValue.REF, StringValue.REF)),
+ new MethodSignature("substring", list(IntegerValue.REF, StringValue.REF)),
exception.getSignature());
}
@@ -103,10 +104,10 @@ public class EvaluatorTests extends BackendEvalTests {
UnexpectedValueType exception = assertThrows(UnexpectedValueType.class,
() -> evalExpression(
- asList(classNode),
+ list(classNode),
constructorCall(
classNode.getName(),
- asList(literal("")))));
+ list(literal("")))));
assertEquals(new UnexpectedValueType(IntegerValue.REF, StringValue.REF), exception);
}
@@ -118,11 +119,11 @@ public class EvaluatorTests extends BackendEvalTests {
NoSuchField exception = assertThrows(NoSuchField.class,
() -> evalExpression(
- asList(classNode),
+ list(classNode),
fieldAccess(
constructorCall(
classNode.getName(),
- asList()),
+ list()),
"value",
IntegerValue.REF)));
@@ -137,11 +138,11 @@ public class EvaluatorTests extends BackendEvalTests {
UnboundField exception = assertThrows(UnboundField.class,
() -> evalExpression(
- asList(classNode),
+ list(classNode),
fieldAccess(
constructorCall(
classNode.getName(),
- asList()),
+ list()),
"value",
IntegerValue.REF)));
@@ -159,10 +160,10 @@ public class EvaluatorTests extends BackendEvalTests {
NoSuchField exception = assertThrows(NoSuchField.class,
() -> evalExpression(
- asList(classNode),
+ list(classNode),
constructorCall(
classNode.getName(),
- asList())));
+ list())));
assertEquals(new NoSuchField("value"), exception);
}
@@ -179,10 +180,10 @@ public class EvaluatorTests extends BackendEvalTests {
UnexpectedValueType exception = assertThrows(UnexpectedValueType.class,
() -> evalExpression(
- asList(classNode),
+ list(classNode),
constructorCall(
classNode.getName(),
- asList())));
+ list())));
assertEquals(new UnexpectedValueType(IntegerValue.REF, StringValue.REF), exception);
}
diff --git a/src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterMethodTests.java b/src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterMethodTests.java
index 8023ee5..d8cd4e0 100644
--- a/src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterMethodTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/interpreter/InterpreterMethodTests.java
@@ -27,6 +27,7 @@ import static org.zwobble.couscous.ast.VariableDeclaration.var;
import static org.zwobble.couscous.ast.VariableReferenceNode.reference;
import static org.zwobble.couscous.tests.TestIds.ANY_ID;
import static org.zwobble.couscous.tests.util.ExtraAsserts.assertThrows;
+import static org.zwobble.couscous.util.ExtraLists.list;
import static org.zwobble.couscous.values.PrimitiveValues.value;
public class InterpreterMethodTests extends BackendMethodTests {
@@ -37,7 +38,7 @@ public class InterpreterMethodTests extends BackendMethodTests {
NoSuchMethod exception = assertThrows(NoSuchMethod.class,
() -> runMethod(method, value("hello, world!")));
- assertEquals(new MethodSignature("hello", asList(StringValue.REF)), exception.getSignature());
+ assertEquals(new MethodSignature("hello", list(StringValue.REF)), exception.getSignature());
}
@Test