tests for new examples

This commit is contained in:
2020-10-04 15:27:38 -06:00
parent e99af9b53f
commit 4d3cac8a11
6 changed files with 73 additions and 0 deletions

28
src/hank/StoryTester.hx Normal file
View 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);
}
}

View 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();
}
}
}
}

View 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.

View File

@@ -0,0 +1 @@
Hello, world!

View File

@@ -0,0 +1,2 @@
We start here!
We end here!

4
test.hxml Normal file
View File

@@ -0,0 +1,4 @@
-lib hiss
-cp src
-main hank.TestStoryExamples
--interp