transcendental-lisp/acctest/fixture/LispInterpreterFixture.java

33 lines
946 B
Java

package fixture;
import java.io.*;
import interpreter.*;
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 String evaluate(String input) throws IOException {
interpreter.setInput(new ByteArrayInputStream(input.getBytes()), "fitnesse");
interpreter.interpret();
String output = outputStream.toString();
outputStream.reset();
return output.trim();
}
}