Resolves #5 - Added FitNesse to the project
This commit is contained in:
parent
013707e11a
commit
6f2802828d
|
@ -2,11 +2,13 @@
|
|||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="test"/>
|
||||
<classpathentry kind="src" path="acceptance"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="java"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry kind="lib" path="fitnesse/fitnesse-standalone.jar"/>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
build/
|
||||
doc/
|
||||
fitnesse/FitNesseRoot/files
|
||||
jar/
|
||||
*.zip
|
||||
*.swp
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
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();
|
||||
}
|
||||
|
||||
public void input(String input) throws IOException {
|
||||
environment.setInput(new ByteArrayInputStream(input.getBytes()));
|
||||
interpreter.interpret();
|
||||
}
|
||||
|
||||
public String output() {
|
||||
String output = outputStream.toString();
|
||||
discardOutput();
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public void discardOutput() {
|
||||
outputStream.reset();
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
|
@ -7,26 +7,26 @@ public class InteractiveLispInterpreter extends LispInterpreter {
|
|||
|
||||
@Override
|
||||
protected void printGreeting() {
|
||||
environment.getOutput().println(GREETING);
|
||||
environment.getOutput().println();
|
||||
output.println(GREETING);
|
||||
output.println();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void displayPrompt() {
|
||||
environment.getOutput().print(PROMPT);
|
||||
output.print(PROMPT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void erasePrompt() {
|
||||
for (int i = 0; i < PROMPT.length(); i++) {
|
||||
environment.getOutput().print("\b");
|
||||
output.print("\b");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void printFarewell() {
|
||||
environment.getOutput().println();
|
||||
environment.getOutput().println();
|
||||
output.println();
|
||||
output.println();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package interpreter;
|
|||
|
||||
import static function.builtin.EVAL.eval;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
import environment.RuntimeEnvironment;
|
||||
import error.*;
|
||||
import parser.LispParser;
|
||||
|
@ -11,15 +13,17 @@ public class LispInterpreter {
|
|||
|
||||
protected RuntimeEnvironment environment;
|
||||
protected ErrorManager errorManager;
|
||||
protected PrintStream output;
|
||||
private LispParser parser;
|
||||
|
||||
public LispInterpreter() {
|
||||
this.environment = RuntimeEnvironment.getInstance();
|
||||
this.errorManager = this.environment.getErrorManager();
|
||||
this.parser = new LispParser(this.environment.getInput(), this.environment.getInputName());
|
||||
this.output = environment.getOutput();
|
||||
}
|
||||
|
||||
public void interpret() {
|
||||
createParser();
|
||||
printGreeting();
|
||||
|
||||
for (displayPrompt(); !parser.isEof(); displayPrompt())
|
||||
|
@ -28,6 +32,10 @@ public class LispInterpreter {
|
|||
printFarewell();
|
||||
}
|
||||
|
||||
private void createParser() {
|
||||
parser = new LispParser(environment.getInput(), environment.getInputName());
|
||||
}
|
||||
|
||||
protected void printGreeting() {}
|
||||
|
||||
protected void displayPrompt() {}
|
||||
|
@ -46,13 +54,13 @@ public class LispInterpreter {
|
|||
String result = environment.decorateValueOutput(String.valueOf(eval(sExpression)));
|
||||
|
||||
erasePrompt();
|
||||
environment.getOutput().println(result);
|
||||
output.println(result);
|
||||
}
|
||||
|
||||
protected void erasePrompt() {}
|
||||
|
||||
protected void printFarewell() {
|
||||
environment.getOutput().println();
|
||||
output.println();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ public interface LispInterpreterBuilder {
|
|||
void setTerminationFunction(Runnable terminationFunction);
|
||||
|
||||
void setErrorTerminationFunction(Runnable errorTerminationFunction);
|
||||
|
||||
void setNotInteractive();
|
||||
|
||||
void useFile(String fileName);
|
||||
|
||||
|
|
|
@ -27,12 +27,14 @@ public class LispInterpreterBuilderImpl implements LispInterpreterBuilder {
|
|||
private Function<String, String> criticalOutputDecorator;
|
||||
private RuntimeEnvironment environment;
|
||||
private boolean isInteractive;
|
||||
private boolean isUseFile;
|
||||
private boolean isBuilt;
|
||||
|
||||
private LispInterpreterBuilderImpl() {
|
||||
this.environment = RuntimeEnvironment.getInstance();
|
||||
this.inputName = "";
|
||||
this.isInteractive = true;
|
||||
this.isUseFile = false;
|
||||
this.isBuilt = false;
|
||||
this.outputDecorator = s -> s;
|
||||
this.valueOutputDecorator = s -> s;
|
||||
|
@ -73,11 +75,17 @@ public class LispInterpreterBuilderImpl implements LispInterpreterBuilder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void useFile(String fileName) {
|
||||
this.inputName = fileName;
|
||||
public void setNotInteractive() {
|
||||
this.isInteractive = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useFile(String fileName) {
|
||||
this.isUseFile = true;
|
||||
this.setInputName(fileName);
|
||||
this.setNotInteractive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutputDecorator(Function<String, String> decorator) {
|
||||
this.outputDecorator = decorator;
|
||||
|
@ -148,7 +156,7 @@ public class LispInterpreterBuilderImpl implements LispInterpreterBuilder {
|
|||
}
|
||||
|
||||
private InputStream getInputStream() throws FileNotFoundException {
|
||||
return isInteractive ? inputStream : new FileInputStream(inputName);
|
||||
return isUseFile ? new FileInputStream(inputName) : inputStream;
|
||||
}
|
||||
|
||||
private LispInterpreter createInterpreter() {
|
||||
|
|
Loading…
Reference in New Issue