transcendental-lisp/test/testutil/TestUtilities.java

41 lines
1.1 KiB
Java
Raw Normal View History

package testutil;
import static org.junit.Assert.assertEquals;
import java.io.*;
import function.builtin.EVAL;
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) {
return EVAL.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());
}
}