2016-12-14 14:41:43 -05:00
|
|
|
package testutil;
|
|
|
|
|
2016-12-22 10:32:48 -05:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
2016-12-14 14:41:43 -05:00
|
|
|
import java.io.*;
|
|
|
|
|
2016-12-22 10:32:48 -05:00
|
|
|
import function.builtin.EVAL;
|
|
|
|
import parser.LispParser;
|
|
|
|
import sexpression.SExpression;
|
|
|
|
|
2016-12-16 11:26:53 -05:00
|
|
|
public final class TestUtilities {
|
2016-12-14 14:41:43 -05:00
|
|
|
|
|
|
|
public static InputStream createInputStreamFromString(String string) {
|
|
|
|
return new ByteArrayInputStream(string.getBytes());
|
|
|
|
}
|
2016-12-22 10:32:48 -05:00
|
|
|
|
2016-12-14 14:41:43 -05:00
|
|
|
public static InputStream createIOExceptionThrowingInputStream() {
|
|
|
|
return new InputStream() {
|
|
|
|
|
|
|
|
public int read() throws IOException {
|
|
|
|
throw new IOException("test IOException");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-22 10:32:48 -05:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2016-12-14 14:41:43 -05:00
|
|
|
}
|