Groundwork for rewriting + testing Story

This commit is contained in:
2019-03-17 18:09:29 -06:00
parent 952d7c9d0d
commit 00f74bdc46
9 changed files with 156 additions and 9 deletions

View File

@@ -1,26 +0,0 @@
package tests;
import utest.Assert;
class HankAssert {
/**
Assert that two complex values (i.e. algebraic enums) are the same.
**/
public static function equals(expected: Dynamic, actual: Dynamic, ?pos: String) {
var failureMessage = 'Assertion that ${actual} is ${expected} failed ${if (pos!= null) 'at ${pos}' else ''}';
Assert.equals(Std.string(Type.typeof(expected)), Std.string(Type.typeof(actual)), failureMessage);
Assert.equals(Std.string(expected), Std.string(actual), failureMessage);
}
/** Assert that a string contains an expected substring. **/
public static function contains(expected: String, actual: String) {
Assert.notEquals(-1, actual.indexOf(expected));
}
/**
Assert that a string does not contain an unexpected substring.
**/
public static function notContains(unexpected: String, actual: String) {
Assert.equals(-1, actual.indexOf(unexpected));
}
}

View File

@@ -5,6 +5,7 @@ using hank.Extensions.OptionExtender;
import haxe.ds.Option;
import hank.HankBuffer;
import hank.HankBuffer.Position;
import hank.HankAssert;
class HankBufferTest extends utest.Test {
var file: HankBuffer;

View File

@@ -1,9 +1,10 @@
package tests;
import hank.Parser;
import hank.Parser.HankAST;
import hank.HankAST;
import hank.Output;
import hank.Alt;
import hank.HankAssert;
class ParserTest extends utest.Test {
var ast: HankAST;
@@ -80,7 +81,7 @@ class ParserTest extends utest.Test {
ToggleOutput(new Output([Text(".")]), false),
ToggleOutput(new Output([Text(" that changes after a choice is made!")]), true)
])));
trace(nextExpr());
// TODO test the last one
}

26
tests/StoryTest.hx Normal file
View File

@@ -0,0 +1,26 @@
package tests;
class StoryTest extends hank.StoryTestCase {
function testAllExamples() {
var exampleFolders = sys.FileSystem.readDirectory('examples');
// Iterate through every example in the examples folder
for (folder in exampleFolders) {
trace('Running tests for example "${folder}"');
var files = sys.FileSystem.readDirectory('examples/${folder}');
for (file in files) {
if (StringTools.endsWith(file, '.hlog')) {
trace(' Running ${file}');
var disabled = file.indexOf("disabled") != -1;
var debug = file.indexOf("debug") != -1;
var partial = file.indexOf("partial") != -1;
if (!disabled) {
validateAgainstTranscript('examples/${folder}/main.hank', 'examples/${folder}/${file}', !partial);
}
}
}
}
}
}

View File

@@ -3,6 +3,6 @@ import utest.Test;
class TestMain extends Test {
public static function main() {
utest.UTest.run([new HInterfaceTest(), new HankBufferTest(), new ParserTest()]);
utest.UTest.run([new HInterfaceTest(), new HankBufferTest(), new ParserTest(), new StoryTest()]);
}
}