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