2017-02-22 14:11:40 -05:00
|
|
|
package fixture;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
import environment.RuntimeEnvironment;
|
|
|
|
import interpreter.*;
|
|
|
|
|
|
|
|
public class LispInterpreterFixture {
|
|
|
|
|
|
|
|
private ByteArrayOutputStream outputStream;
|
|
|
|
private RuntimeEnvironment environment;
|
|
|
|
private LispInterpreter interpreter;
|
|
|
|
|
|
|
|
public LispInterpreterFixture() throws IOException {
|
|
|
|
this.outputStream = new ByteArrayOutputStream();
|
|
|
|
this.environment = RuntimeEnvironment.getInstance();
|
|
|
|
this.interpreter = buildInterpreter();
|
|
|
|
}
|
|
|
|
|
|
|
|
private LispInterpreter buildInterpreter() {
|
|
|
|
LispInterpreterBuilder builder = LispInterpreterBuilderImpl.getInstance();
|
|
|
|
builder.setInputName("fitnesse");
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2017-02-24 11:07:06 -05:00
|
|
|
public String evaluate(String input) throws IOException {
|
2017-02-22 14:11:40 -05:00
|
|
|
environment.setInput(new ByteArrayInputStream(input.getBytes()));
|
|
|
|
interpreter.interpret();
|
|
|
|
String output = outputStream.toString();
|
|
|
|
outputStream.reset();
|
2017-02-24 11:07:06 -05:00
|
|
|
|
|
|
|
return output.trim();
|
2017-02-22 14:11:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|