Groundwork for rewriting + testing Story
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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
26
tests/StoryTest.hx
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user