transcendental-lisp/test/testutil/TestUtilities.java

45 lines
1.2 KiB
Java
Raw Normal View History

package testutil;
2017-02-21 13:59:56 -05:00
import static function.builtin.EVAL.eval;
2017-03-10 13:14:16 -05:00
import static org.junit.Assert.*;
import java.io.*;
import parser.LispParser;
import sexpression.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) {
2017-02-21 13:59:56 -05:00
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());
}
2017-03-10 13:14:16 -05:00
public static void assertSExpressionsDoNotMatch(SExpression one, SExpression two) {
assertNotEquals(one.toString(), two.toString());
}
}