tests for new examples
This commit is contained in:
28
src/hank/StoryTester.hx
Normal file
28
src/hank/StoryTester.hx
Normal file
@@ -0,0 +1,28 @@
|
||||
package hank;
|
||||
|
||||
import hiss.HissReader;
|
||||
import hiss.HissTools;
|
||||
import hiss.StaticFiles;
|
||||
using StringTools;
|
||||
|
||||
class StoryTester implements StoryTeller {
|
||||
var transcriptLines: Array<String>;
|
||||
|
||||
public function new(testTranscript: String) {
|
||||
transcriptLines = StaticFiles.getContent(testTranscript).split("\n").map(StringTools.trim).filter((s) -> s.length > 0);
|
||||
}
|
||||
|
||||
public function handleOutput(text: String, finished: (Int) -> Void) {
|
||||
var expected = transcriptLines.shift();
|
||||
if (expected != text) throw 'expected "$expected" but output was "$text"';
|
||||
finished(0);
|
||||
}
|
||||
|
||||
public function handleChoices(choices: Array<String>, choose: (Int) -> Void) {
|
||||
for (choice in choices) {
|
||||
var expected = transcriptLines.shift().substr(1).trim(); // clip the *
|
||||
if (expected != choice) throw 'expected choice "$expected" but it was "$choice"';
|
||||
}
|
||||
choose(Std.parseInt(transcriptLines.shift().substr(1).trim()) - 1);
|
||||
}
|
||||
}
|
||||
21
src/hank/TestStoryExamples.hx
Normal file
21
src/hank/TestStoryExamples.hx
Normal file
@@ -0,0 +1,21 @@
|
||||
package hank;
|
||||
|
||||
using StringTools;
|
||||
import hiss.StaticFiles;
|
||||
|
||||
class TestStoryExamples {
|
||||
public static function main() {
|
||||
StaticFiles.compileWithAll("examples");
|
||||
|
||||
var examples = sys.FileSystem.readDirectory("src/hank/examples");
|
||||
|
||||
for (example in examples) {
|
||||
var transcripts = sys.FileSystem.readDirectory("src/hank/examples/" + example);
|
||||
transcripts = transcripts.filter((file) -> file.endsWith(".hlog"));
|
||||
|
||||
for (transcript in transcripts) {
|
||||
new Story("examples/" + example + "/main.hank", new StoryTester("examples/" + example + "/" + transcript)).run();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/hank/examples/choices/test1.hlog
Normal file
17
src/hank/examples/choices/test1.hlog
Normal file
@@ -0,0 +1,17 @@
|
||||
You have to make a choice.
|
||||
* A
|
||||
* B
|
||||
* C
|
||||
> 1
|
||||
A
|
||||
* A
|
||||
* B
|
||||
* C
|
||||
> 2
|
||||
B
|
||||
* A
|
||||
* B
|
||||
* C
|
||||
> 3
|
||||
C
|
||||
Good choice.
|
||||
1
src/hank/examples/hello/test1.hlog
Normal file
1
src/hank/examples/hello/test1.hlog
Normal file
@@ -0,0 +1 @@
|
||||
Hello, world!
|
||||
2
src/hank/examples/knots/test1.hlog
Normal file
2
src/hank/examples/knots/test1.hlog
Normal file
@@ -0,0 +1,2 @@
|
||||
We start here!
|
||||
We end here!
|
||||
Reference in New Issue
Block a user