56 lines
1.5 KiB
Java
56 lines
1.5 KiB
Java
package testutil;
|
|
|
|
import static function.builtin.EVAL.eval;
|
|
import static org.junit.Assert.*;
|
|
import static sexpression.Nil.NIL;
|
|
|
|
import java.io.*;
|
|
import java.util.Arrays;
|
|
|
|
import parser.LispParser;
|
|
import sexpression.*;
|
|
|
|
public final class TestUtilities {
|
|
|
|
public static InputStream createInputStreamFromString(String string) {
|
|
return new ByteArrayInputStream(string.getBytes());
|
|
}
|
|
|
|
public static InputStream createIOExceptionThrowingInputStream() {
|
|
return new InputStream() {
|
|
|
|
public int read() throws IOException {
|
|
throw new IOException("test IOException");
|
|
}
|
|
};
|
|
}
|
|
|
|
public static SExpression evaluateString(String input) {
|
|
return eval(parseString(input));
|
|
}
|
|
|
|
public static SExpression parseString(String input) {
|
|
InputStream stringInputStream = TestUtilities.createInputStreamFromString(input);
|
|
|
|
return new LispParser(stringInputStream, "testFile").getNextSExpression();
|
|
}
|
|
|
|
public static void assertSExpressionsMatch(SExpression one, SExpression two) {
|
|
assertEquals(one.toString(), two.toString());
|
|
}
|
|
|
|
public static void assertSExpressionsDoNotMatch(SExpression one, SExpression two) {
|
|
assertNotEquals(one.toString(), two.toString());
|
|
}
|
|
|
|
public static Cons makeList(SExpression... expressionList) {
|
|
if (expressionList.length == 0)
|
|
return NIL;
|
|
|
|
Cons rest = makeList(Arrays.copyOfRange(expressionList, 1, expressionList.length));
|
|
|
|
return new Cons(expressionList[0], rest);
|
|
}
|
|
|
|
}
|