-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1122fd3
commit 7b7c8d5
Showing
6 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package me.predatorray.bud.lisp; | ||
|
||
import me.predatorray.bud.lisp.test.NullWriter; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.*; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class BudReplTest { | ||
|
||
private BudRepl repl; | ||
|
||
@Before | ||
public void setUpFixtureOfRepl() { | ||
repl = new BudRepl(false); | ||
} | ||
|
||
private String readEvaluateAndPrint(String input) throws IOException { | ||
try (Reader reader = new StringReader(input); | ||
Writer writer = new StringWriter()) { | ||
repl.execute(reader, writer, new NullWriter()); | ||
return writer.toString(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRepl1() throws Exception { | ||
String output = readEvaluateAndPrint("\"abc\""); | ||
assertEquals("\"abc\"\n", output); | ||
} | ||
|
||
@Test | ||
public void testRepl2() throws Exception { | ||
readEvaluateAndPrint("unknown"); | ||
String output = readEvaluateAndPrint("\"abc\""); | ||
assertEquals("\"abc\"\n", output); | ||
} | ||
|
||
@Test | ||
public void testRepl3() throws Exception { | ||
String output = readEvaluateAndPrint("(+ 1 1) 3"); | ||
assertEquals("2\n3\n", output); | ||
} | ||
|
||
@Test | ||
public void testRepl4() throws Exception { | ||
String output = readEvaluateAndPrint("(+ 1 1) (\n" + | ||
"- 1 1)\n"); | ||
assertEquals("2\n0\n", output); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/java/me/predatorray/bud/lisp/test/NullWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package me.predatorray.bud.lisp.test; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
|
||
public class NullWriter extends Writer { | ||
|
||
@Override | ||
public void write(char[] cbuf, int off, int len) throws IOException { | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
} | ||
} |