transcendental-lisp/test/acceptance/fixture/LispInterpreterFixture.java

41 lines
1.1 KiB
Java
Raw Normal View History

2017-03-02 15:26:21 -05:00
package acceptance.fixture;
2017-03-03 15:06:49 -05:00
import static table.FunctionTable.resetFunctionTable;
import java.io.*;
import interpreter.*;
2017-03-03 15:06:49 -05:00
import table.ExecutionContext;
public class LispInterpreterFixture {
private static ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
private static LispInterpreter interpreter = null;
static {
LispInterpreterBuilder builder = LispInterpreterBuilderImpl.getInstance();
builder.setOutput(new PrintStream(outputStream));
builder.setErrorOutput(new PrintStream(outputStream));
builder.setNotInteractive();
builder.setTerminationFunction(() -> {});
builder.setErrorTerminationFunction(() -> {});
interpreter = builder.build();
}
public void reset() {
2017-03-03 15:06:49 -05:00
resetFunctionTable();
ExecutionContext.getInstance().clearContext();
}
public String evaluate(String input) throws IOException {
interpreter.setInput(new ByteArrayInputStream(input.getBytes()), "fitnesse");
interpreter.interpret();
String output = outputStream.toString();
outputStream.reset();
return output.trim();
}
}