transcendental-lisp/acceptance/fixture/LispInterpreterFixture.java

38 lines
1.1 KiB
Java

package fixture;
import java.io.*;
import interpreter.*;
public class LispInterpreterFixture {
private ByteArrayOutputStream outputStream;
private LispInterpreter interpreter;
public LispInterpreterFixture() throws IOException {
this.outputStream = new ByteArrayOutputStream();
this.interpreter = buildInterpreter();
}
private LispInterpreter buildInterpreter() {
LispInterpreterBuilder builder = LispInterpreterBuilderImpl.getInstance();
builder.setOutput(new PrintStream(outputStream));
builder.setErrorOutput(new PrintStream(outputStream));
builder.setNotInteractive();
builder.setTerminationFunction(() -> System.exit(0));
builder.setErrorTerminationFunction(() -> System.exit(1));
return builder.build();
}
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();
}
}