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

39 lines
1.1 KiB
Java

package acceptance.fixture;
import java.io.*;
import interpreter.*;
import table.*;
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() {
FunctionTable.reset();
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();
}
}