diff --git a/.munit b/.munit deleted file mode 100755 index 46a5001..0000000 --- a/.munit +++ /dev/null @@ -1,6 +0,0 @@ -version=2.3.3 -src=test -bin=build -report=report -hxml=test.hxml -classPaths=src diff --git a/.vim/coc-settings.json b/.vim/coc-settings.json index c0c1634..f0add07 100644 --- a/.vim/coc-settings.json +++ b/.vim/coc-settings.json @@ -1,3 +1,3 @@ { - "haxe.hxml": "test.hxml" + "haxe.hxml": "build.hxml" } \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md index 3b80ecf..5332990 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ This code is licensed under the MIT License: -> Copyright (c) 2016: Martin O'Leary +> Copyright (c) 2016: Benjamin Van Treese > > Permission is hereby granted, free of charge, to any person obtaining > a copy of this software and associated documentation files (the diff --git a/build.hxml b/build.hxml index afdec2b..4327988 100755 --- a/build.hxml +++ b/build.hxml @@ -18,4 +18,6 @@ targets/js-esm.hxml --next targets/cs.hxml --next +targets/python.hxml +--next targets/docs.hxml diff --git a/package-lock.json b/package-lock.json index a8c7e56..027794b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,13 @@ { "name": "@dropecho/storygen", - "version": "0.11.0", + "version": "0.13.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@dropecho/storygen", - "version": "0.11.0", + "version": "0.13.0", + "hasInstallScript": true, "license": "MIT", "devDependencies": { "@semantic-release/changelog": "^6.0.2", diff --git a/package.json b/package.json index 37808ea..8eb548c 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,10 @@ }, "license": "MIT", "scripts": { + "install": "lix download", "build": "npm run clean && haxe build.hxml && npm run docs:cp_js", "docs:cp_js": "cp dist/js/cjs/index.cjs docs/storygen.js", - "test": "haxelib run munit t", + "test": "haxelib run dropecho.testing", "clean": "rm -rf dist && rm -rf artifacts" }, "devDependencies": { diff --git a/test.hxml b/test.hxml index d53ead0..248a0b5 100755 --- a/test.hxml +++ b/test.hxml @@ -1,36 +1,29 @@ -# CSharp --main TestMain --lib dropecho.interop --lib munit --lib hamcrest --lib seedyrng - -cp src -cp test --D dce=no - --D dll_import --D no-root --cs build/cs_test ---next - -## JavaScript NodeJS --main TestMain --lib dropecho.interop --lib munit --lib hamcrest -lib seedyrng +-lib dropecho.interop +-lib dropecho.testing +-lib utest --cp src --cp test - --D dce=no +--each +# --next -lib hxnodejs --js build/js_test.cjs +-D js-es=6 +-js artifacts/js_test.cjs + +# --next +# -lib hxnodejs +# -lib genes +# -js artifacts/js_esm_test/test.js +# +# --next +# -D net-ver=40 +# -cs artifacts/cs_test + # --next +# -python artifacts/python_test -# ## HashLink # --next -# -hl build/hl_test.hl +# -neko artifacts/neko_test.n diff --git a/test/TestMain.hx b/test/TestMain.hx deleted file mode 100644 index eb87670..0000000 --- a/test/TestMain.hx +++ /dev/null @@ -1,74 +0,0 @@ -import massive.munit.client.PrintClient; -import massive.munit.client.RichPrintClient; -import massive.munit.client.HTTPClient; -import massive.munit.client.JUnitReportClient; -import massive.munit.client.SummaryReportClient; -import massive.munit.TestRunner; - -/** - * Auto generated Test Application. - * Refer to munit command line tool for more information (haxelib run munit) - */ -class TestMain -{ - static function main(){ new TestMain(); } - - public function new() - { - var suites = new Array>(); - suites.push(TestSuite); - - #if MCOVER - var client = new mcover.coverage.munit.client.MCoverPrintClient(); - var httpClient = new HTTPClient(new mcover.coverage.munit.client.MCoverSummaryReportClient()); - #else - var client = new RichPrintClient(); - var httpClient = new HTTPClient(new SummaryReportClient()); - #end - - var runner:TestRunner = new TestRunner(client); - runner.addResultClient(httpClient); - - // runner.completionHandler = completionHandler; - - #if (js && !nodejs) - var seconds = 0; // edit here to add some startup delay - function delayStartup() - { - if (seconds > 0) { - seconds--; - js.Browser.document.getElementById("munit").innerHTML = - "Tests will start in " + seconds + "s..."; - haxe.Timer.delay(delayStartup, 1000); - } - else { - js.Browser.document.getElementById("munit").innerHTML = ""; - runner.run(suites); - } - } - delayStartup(); - #else - runner.run(suites); - #end - } - - /** - * updates the background color and closes the current browser - * for flash and html targets (useful for continous integration servers) - */ - function completionHandler(successful:Bool) - { - try - { - #if flash - flash.external.ExternalInterface.call("testResult", successful); - #elseif (js && !nodejs) - js.Lib.eval("testResult(" + successful + ");"); - #elseif (neko || cpp || java || cs || python || php || hl || eval || nodejs) - Sys.exit(0); - #end - } - // if run from outside browser can get error which we can ignore - catch (e:Dynamic) {} - } -} diff --git a/test/TestSuite.hx b/test/TestSuite.hx deleted file mode 100755 index c32845b..0000000 --- a/test/TestSuite.hx +++ /dev/null @@ -1,23 +0,0 @@ -import massive.munit.TestSuite; - -import storygen.TokenTest; -import storygen.GeneratorTest; -import storygen.TransformsTest; -import storygen.FunctionsTest; - -/** - * Auto generated Test Suite for MassiveUnit. - * Refer to munit command line tool for more information (haxelib run munit) - */ -class TestSuite extends massive.munit.TestSuite -{ - public function new() - { - super(); - - add(storygen.TokenTest); - add(storygen.GeneratorTest); - add(storygen.TransformsTest); - add(storygen.FunctionsTest); - } -} diff --git a/test/storygen/FunctionsTest.hx b/test/storygen/Functions_Tests.hx similarity index 61% rename from test/storygen/FunctionsTest.hx rename to test/storygen/Functions_Tests.hx index 5a271ea..f3ffc7c 100644 --- a/test/storygen/FunctionsTest.hx +++ b/test/storygen/Functions_Tests.hx @@ -1,63 +1,57 @@ package storygen; import dropecho.storygen.Generator.WordList; -import massive.munit.Assert; import dropecho.storygen.*; +import utest.Assert; -class FunctionsTest { +class Functions_Tests extends utest.Test { var generator:Generator; - @Before public function setup() { var config = ["test" => (['a'] : WordList), "test2" => (['b'] : WordList)]; generator = new Generator(config); } - @Test - public function repeat() { + public function test_repeat() { var repeat = Functions.get("repeat"); - Assert.isNotNull(random); + Assert.notNull(repeat); var out = repeat(generator, ["test2", "4", "4"]); - Assert.areEqual("b b b b", out); + Assert.equals("b b b b", out); } - @Test - public function random() { + public function test_random() { var random = Functions.get("random"); - Assert.isNotNull(random); + Assert.notNull(random); var out = random(generator, ["1", "1"]); - Assert.areEqual("1", out); + Assert.equals("1", out); } - @Test - public function switch_test() { + public function test_switch_test() { generator.memory.set("bar", "test2"); var sw = Functions.get("switch"); - Assert.isNotNull(sw); + Assert.notNull(sw); var out = sw(generator, ["bar", "test=>test", "test2=>test2"]); - Assert.areEqual("#test2#", out); + Assert.equals("#test2#", out); } - @Test - public function swit_to_null() { + public function test_switch_to_null() { generator.memory.set("bar", "test2"); var sw = Functions.get("switch"); - Assert.isNotNull(sw); + Assert.notNull(sw); var out = sw(generator, ["bar", "test=>test"]); - Assert.areEqual("", out); + Assert.equals("", out); } - @Test - public function switch_test_default() { + public function test_switch_test_default() { generator.memory.set("bar", "test2"); var sw = Functions.get("switch"); - Assert.isNotNull(sw); + Assert.notNull(sw); var out = sw(generator, ["bar", "test=>test", "_=>default"]); - Assert.areEqual("default", out); + Assert.equals("default", out); } } diff --git a/test/storygen/GeneratorTest.hx b/test/storygen/Generator_Tests.hx similarity index 75% rename from test/storygen/GeneratorTest.hx rename to test/storygen/Generator_Tests.hx index bb0afbe..b960d68 100644 --- a/test/storygen/GeneratorTest.hx +++ b/test/storygen/Generator_Tests.hx @@ -1,13 +1,12 @@ package storygen; import dropecho.storygen.Generator.WordList; -import massive.munit.Assert; import dropecho.storygen.*; +import utest.Assert; -class GeneratorTest { +class Generator_Tests extends utest.Test { var generator:Generator; - @Before public function setup() { var config = [ "test" => (['a'] : WordList), @@ -19,33 +18,29 @@ class GeneratorTest { generator = new Generator(config); } - @Test - public function canInstantiate() { - Assert.isNotNull(generator); + public function test_canInstantiate() { + Assert.notNull(generator); } #if js - @Test - public function runDynamicConfig() { + public function test_runDynamicConfig() { var config:Dynamic = {test: ["a"]}; var gen = new Generator(config); var out = gen.run("#test#"); var expected = "a"; - Assert.areEqual(expected, out); + Assert.equals(expected, out); } #end - @Test - public function run() { + public function test_run() { var out = generator.run("#test#"); var expected = "a"; - Assert.areEqual(expected, out); + Assert.equals(expected, out); } - @Test - public function run_merged() { + public function test_run_merged() { var c = ["origin" => (["#c2_name# met #c3_name#"] : WordList)]; var c2 = ["c2_name" => (["bob"] : WordList)]; var c3 = ["c3_name" => (["sally"] : WordList)]; @@ -57,35 +52,31 @@ class GeneratorTest { var out = gen.run("#origin#"); var expected = "bob met sally"; - Assert.areEqual(expected, out); + Assert.equals(expected, out); } - @Test - public function recurse() { + public function test_recurse() { var out = generator.run("#bar#"); var expected = "a bar"; - Assert.areEqual(expected, out); + Assert.equals(expected, out); } - @Test - public function recurse2Levels() { + public function test_recurse2Levels() { var out = generator.run("#foo#"); var expected = "a bar"; - Assert.areEqual(expected, out); + Assert.equals(expected, out); } - @Test - public function recurse3Levels() { + public function test_recurse3Levels() { var out = generator.run("#baz#"); var expected = "a bar a bar"; - Assert.areEqual(expected, out); + Assert.equals(expected, out); } - @Test - public function memory_advanced() { + public function test_memory_advanced() { var config = [ "sentence" => (["#n:name# #n:name# #n# #n#"] : WordList), "name" => (["Arjun", "Yuuma", "Darcy", "Mia", "Chiaki", "Izzi", "Azra", "Lina"] : WordList) @@ -96,12 +87,11 @@ class GeneratorTest { var name = generated.output.split(" ")[0]; var expected = name + " " + name + " " + name + " " + name; - Assert.areEqual(expected, generated.output); - Assert.areEqual(name, generated.memory["n"]); + Assert.equals(expected, generated.output); + Assert.equals(name, generated.memory["n"]); } - @Test - public function memory() { + public function test_memory() { var config = [ "sentence" => (["#n:name# #n:name# #n# #n#"] : WordList), "name" => (["Arjun", "Yuuma", "Darcy", "Mia", "Chiaki", "Izzi", "Azra", "Lina"] : WordList) @@ -112,11 +102,10 @@ class GeneratorTest { var name = generated.split(" ")[0]; var expected = name + " " + name + " " + name + " " + name; - Assert.areEqual(expected, generated); + Assert.equals(expected, generated); } - @Test - public function memory_with_silent_action() { + public function test_memory_with_silent_action() { var config = [ "sentence" => (["#[n:name]##n# #n#"] : WordList), "name" => (["Arjun", "Yuuma", "Darcy", "Mia", "Chiaki", "Izzi", "Azra", "Lina"] : WordList) @@ -127,11 +116,10 @@ class GeneratorTest { var name = generated.split(" ")[0]; var expected = name + " " + name; - Assert.areEqual(expected, generated); + Assert.equals(expected, generated); } - @Test - public function memory_with_multiple_silent_action() { + public function test_memory_with_multiple_silent_action() { var config = [ "sentence" => (["#[n:name]# #[b:name]# #n# #n# #b# #b#"] : WordList), "name" => (["Arjun", "Yuuma", "Darcy", "Mia", "Chiaki", "Izzi", "Azra", "Lina"] : WordList) @@ -141,12 +129,11 @@ class GeneratorTest { var generated = generator.run("#sentence#"); var split = generated.split(" "); - Assert.areEqual(split[0], split[1]); - Assert.areEqual(split[2], split[3]); + Assert.equals(split[0], split[1]); + Assert.equals(split[2], split[3]); } - // @Test - // public function memory_with_transforms() { + // public function test_memory_with_transforms() { // var config = [ // "sentence" => ["#n:name.capitalize# #n:name.capitalize# #n:name.capitalize# #n#"], // "name" => ["Arjun", "Yuuma", "Darcy", "Mia", "Chiaki", "Izzi", "Azra", "Lina"] @@ -157,22 +144,20 @@ class GeneratorTest { // var name = generated.split(" ")[0]; // var expected = name + " " + name + " " + name + " " + name; // - // Assert.areEqual(expected, generated); + // Assert.equals(expected, generated); // } // - // @Test - // public function memory_sub_token() { + // public function test_memory_sub_token() { // var config = ["sentence" => ["#n:name#"], "name" => ["#othername#"], "othername" => ["Arjun"]]; // // generator = new Generator(config); // var generated = generator.run("#sentence#"); // var expected = "Arjun"; // - // Assert.areEqual(expected, generated); + // Assert.equals(expected, generated); // } // - // @Test - // public function memory_nested() { + // public function test_memory_nested() { // var config = [ // "sentence" => ["#[n:char]##n# #n#"], // "char" => ["[#[on:othername]##[h:heritage]##on##h#"], @@ -185,11 +170,10 @@ class GeneratorTest { // var name = generated.split(" ")[0]; // var expected = name + " " + name; // - // Assert.areEqual(expected, generated); + // Assert.equals(expected, generated); // } // - // @Test - // public function memory_first_last_name() { + // public function test_memory_first_last_name() { // var grammar = [ // "origin" => ["#n:full_name# #n# #n# #n#"], // "full_name" => ["#first_name#-#last_name#"], @@ -202,61 +186,60 @@ class GeneratorTest { // var name = generated.split(" ")[0]; // var expected = name + " " + name + " " + name + " " + name; // - // Assert.areEqual(expected, generated); + // Assert.equals(expected, generated); // } // - // @Test public function transforms() { + // public function test_transforms() { // var config = ["name" => ["bird"]]; // // generator = new Generator(config); // var generated = generator.run("#name.a#"); // var expected = "a bird"; // - // Assert.areEqual(expected, generated); + // Assert.equals(expected, generated); // } // - // @Test public function multiple_transforms() { + // public function test_multiple_transforms() { // var config = ["name" => ["bird"]]; // // generator = new Generator(config); // var generated = generator.run("#name.capitalize.a#"); // var expected = "a Bird"; // - // Assert.areEqual(expected, generated); + // Assert.equals(expected, generated); // } // - // @Test public function multiple_transforms_other_order() { + // public function test_multiple_transforms_other_order() { // var config = ["name" => ["bird"]]; // // generator = new Generator(config); // var generated = generator.run("#name.a.capitalize#"); // var expected = "A bird"; // - // Assert.areEqual(expected, generated); + // Assert.equals(expected, generated); // } // - // @Test public function multiple_transforms_other_transform() { + // public function test_multiple_transforms_other_transform() { // var config = ["name" => ["bird"]]; // // generator = new Generator(config); // var generated = generator.run("#name.capitalize.a.capitalize#"); // var expected = "A Bird"; // - // Assert.areEqual(expected, generated); + // Assert.equals(expected, generated); // } // - // @Test public function function_call() { + // public function test_function_call() { // var config = ["rand" => ["#random( 0, 0)#"]]; // // generator = new Generator(config); // var generated = generator.run("#rand#"); // var expected = "0"; // - // Assert.areEqual(expected, generated); + // Assert.equals(expected, generated); // } // - // @Test - // public function function_call_sw() { + // public function test_function_call_sw() { // var config = [ // "origin" => ["#[char_race:race]##[char_name:name]##char#"], // "char" => ["#char_name# the #char_race#"], @@ -272,7 +255,7 @@ class GeneratorTest { // Assert.isTrue(generated == "bob the elf" || generated == "sally the dwarf", generated); // } // - // @Test public function basically_everything() { + // public function test_basically_everything() { // Functions.set("test", (gen:Generator, args:Array) -> { // return "test"; // }); @@ -282,11 +265,10 @@ class GeneratorTest { // var generated = generator.run("#test#"); // var expected = "a Test"; // - // Assert.areEqual(expected, generated); + // Assert.equals(expected, generated); // } // - // @Test - // public function jsonParse() { + // public function test_jsonParse() { // var json = ' // { // "sentence": ["a"] @@ -297,33 +279,30 @@ class GeneratorTest { // var gen = new Generator(config); // var out = gen.run("#sentence#"); // - // Assert.areEqual("a", out); + // Assert.equals("a", out); // } // - // @Test - // public function transform() { + // public function test_transform() { // var config = ["sentence" => ["#name.capitalize#"], "name" => ["lina"]]; // // generator = new Generator(config); // var generated = generator.run("#sentence#"); // var expected = "Lina"; // - // Assert.areEqual(expected, generated); + // Assert.equals(expected, generated); // } // - // @Test - // public function advanced() { + // public function test_advanced() { // var config = ["sentence" => ["#name:name.capitalize#"], "name" => ["lina"]]; // // generator = new Generator(config); // var generated = generator.runAdvanced("#sentence#"); // var expected = "Lina"; // - // Assert.areEqual(expected, generated.output); + // Assert.equals(expected, generated.output); // } // - // @Test - // public function advanced_with_Seed() { + // public function test_advanced_with_Seed() { // var config = ["origin" => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]]; // // generator = new Generator(config); @@ -336,68 +315,63 @@ class GeneratorTest { // var out3 = generator.runAdvanced("#origin#", seed).output; // var out4 = generator.runAdvanced("#origin#", seed).output; // - // Assert.areEqual(out1, out2, "first run should be same"); - // Assert.areEqual(out1, out3, "second run should be same"); - // Assert.areEqual(out1, out4, "third run should be same"); + // Assert.equals(out1, out2, "first run should be same"); + // Assert.equals(out1, out3, "second run should be same"); + // Assert.equals(out1, out4, "third run should be same"); // } // - // @Test // // @Ignore - // public function missing_symbol_exception() { + // public function test_missing_symbol_exception() { // var config = ["origin" => ["#someFunc()"]]; // // generator = new Generator(config); // try { // generator.run("other"); // } catch (e:Any) { - // Assert.isNotNull(e); + // Assert.notNull(e); // // trace(e); // } // } // - // @Test - // public function missing_choices_exception() { + // public function test_missing_choices_exception() { // var config = ["origin" => []]; // // generator = new Generator(config); // try { // generator.run("origin"); // } catch (e:Any) { - // Assert.isNotNull(e); + // Assert.notNull(e); // // trace(e); // } // } // - // @Test // // @Ignore - // public function missing_function_exception() { + // public function test_missing_function_exception() { // var config = ["origin" => ["#myFunc()#"]]; // // generator = new Generator(config); // try { // generator.run("origin"); // } catch (e:Any) { - // Assert.isNotNull(e); + // Assert.notNull(e); // // trace(e); // } // } // - // @Test // // @Ignore - // public function missing_transform_exception() { + // public function test_missing_transform_exception() { // var config = ["origin" => ["#foo.bar#"], "foo" => ["hi"]]; // // generator = new Generator(config); // try { // generator.run("origin"); // } catch (e:Any) { - // Assert.isNotNull(e); + // Assert.notNull(e); // // trace(e); // } // } /* - @Test - public function moreComplicatedGrammar() { + public function test_moreComplicatedGrammar() { var config = { grammars: [ "sentence" => ["The #color# #animal# of the #natureNoun# is called #name#"], @@ -416,8 +390,7 @@ class GeneratorTest { trace("TEST", out); } - @Test - public function guildGenerator() { + public function test_guildGenerator() { var config = { grammars: [ "origin" => [ diff --git a/test/storygen/TokenTest.hx b/test/storygen/TokenTest.hx deleted file mode 100644 index ba87292..0000000 --- a/test/storygen/TokenTest.hx +++ /dev/null @@ -1,147 +0,0 @@ -package storygen; - -import massive.munit.Assert; -import dropecho.storygen.*; - -class TokenTest { - @Test - public function canInstantiate() { - Assert.isNotNull(new Token("hi")); - } - - @Test - public function tokenValidationPositive() { - var token = new Token("#test#"); - - Assert.isTrue(token.isExpandable); - } - - @Test - public function tokenValidationNegative() { - var token = new Token("test"); - - Assert.isFalse(token.isExpandable); - } - - @Test - public function should_be_memorized_when_has_colon() { - var token = new Token("#t:test#"); - - Assert.isTrue(token.isExpandable); - Assert.isTrue(token.isMemorized); - } - - @Test - public function should_not_be_memorized_when_no_colon_present() { - var token = new Token("#test#"); - - Assert.isTrue(token.isExpandable); - Assert.isFalse(token.isMemorized); - } - - @Test - public function should_store_key_for_memory_when_has_colon() { - var token = new Token("#t:test#"); - - Assert.areEqual("t", token.memSymbol); - } - - @Test - public function should_not_store_key_for_memory_when_has_no_colon() { - var token = new Token("#test#"); - - Assert.isNull(token.memSymbol); - } - - @Test function should_store_symbol_when_valid() { - var token = new Token("#test#"); - - Assert.areEqual("test", token.symbol); - } - - @Test function should_not_store_symbol_when_invalid() { - var token = new Token("test"); - - Assert.isNull(token.symbol); - } - - @Test function should_be_transformed_when_period_present() { - var token = new Token("#test.cap#"); - - Assert.isTrue(token.isTransformed); - } - - @Test function should_not_be_transformed_when_no_period_present() { - var token = new Token("#test#"); - - Assert.isFalse(token.isTransformed); - } - - @Test function should_parse_transforms_into_list_when_present() { - var token = new Token("#test.cap#"); - - Assert.isTrue(token.transforms.length > 0); - Assert.areEqual("cap", token.transforms[0]); - } - - @Test function should_have_empty_transforms_list_when_not_present() { - var token = new Token("#test#"); - - Assert.isFalse(token.transforms.length > 0); - } - - @Test function should_be_marked_as_function_when_wrapped_in_parens() { - var token = new Token("#random(5, 10)#"); - - Assert.isTrue(token.isFunction); - Assert.areEqual("random", token.symbol); - Assert.areEqual("5", token.functionArgs[0]); - Assert.areEqual("10", token.functionArgs[1]); - } - - @Test function should_be_marked_as_function_with_no_params() { - var token = new Token("#random()#"); - - Assert.isTrue(token.isFunction); - Assert.areEqual("random", token.symbol); - Assert.areEqual(0, token.functionArgs.length); - } - - - @Test function should_not_be_marked_as_function_when_no_parens() { - var token = new Token("#random#"); - - Assert.isFalse(token.isFunction); - Assert.areEqual("random", token.symbol); - Assert.areEqual(0, token.functionArgs.length); - } - - @Test function should_be_marked_as_silent_when_wrapped_with_brackets() { - var token = new Token("#[test]#"); - - Assert.isTrue(token.isExpandable); - Assert.isTrue(token.isSilent); - Assert.areEqual("test", token.symbol); - } - - @Test function should_not_be_marked_as_silent_when_no_square_brackets() { - var token = new Token("#test#"); - - Assert.isFalse(token.isSilent); - Assert.areEqual("test", token.symbol); - } - - @Test function silent_memory_function_with_transforms() { - var token = new Token("#[t:test(5).capitalize.a]#"); - - Assert.isTrue(token.isSilent); - Assert.isTrue(token.isFunction); - Assert.isTrue(token.isMemorized); - Assert.isTrue(token.isTransformed); - Assert.areEqual("test", token.symbol); - Assert.areEqual("t", token.memSymbol); - Assert.areEqual("5", token.functionArgs[0]); - Assert.areEqual("capitalize", token.transforms[0]); - Assert.areEqual("a", token.transforms[1]); - } -} diff --git a/test/storygen/Token_Tests.hx b/test/storygen/Token_Tests.hx new file mode 100644 index 0000000..fa6a8fe --- /dev/null +++ b/test/storygen/Token_Tests.hx @@ -0,0 +1,139 @@ +package storygen; + +import dropecho.storygen.*; +import utest.Assert; + +class Token_Tests extends utest.Test { + public function test_canInstantiate() { + Assert.notNull(new Token("hi")); + } + + public function test_tokenValidationPositive() { + var token = new Token("#test#"); + + Assert.isTrue(token.isExpandable); + } + + public function test_tokenValidationNegative() { + var token = new Token("test"); + + Assert.isFalse(token.isExpandable); + } + + public function test_should_be_memorized_when_has_colon() { + var token = new Token("#t:test#"); + + Assert.isTrue(token.isExpandable); + Assert.isTrue(token.isMemorized); + } + + public function test_should_not_be_memorized_when_no_colon_present() { + var token = new Token("#test#"); + + Assert.isTrue(token.isExpandable); + Assert.isFalse(token.isMemorized); + } + + public function test_should_store_key_for_memory_when_has_colon() { + var token = new Token("#t:test#"); + + Assert.equals("t", token.memSymbol); + } + + public function test_should_not_store_key_for_memory_when_has_no_colon() { + var token = new Token("#test#"); + + Assert.isNull(token.memSymbol); + } + + function test_should_store_symbol_when_valid() { + var token = new Token("#test#"); + + Assert.equals("test", token.symbol); + } + + function test_should_not_store_symbol_when_invalid() { + var token = new Token("test"); + + Assert.isNull(token.symbol); + } + + function test_should_be_transformed_when_period_present() { + var token = new Token("#test.cap#"); + + Assert.isTrue(token.isTransformed); + } + + function test_should_not_be_transformed_when_no_period_present() { + var token = new Token("#test#"); + + Assert.isFalse(token.isTransformed); + } + + function test_should_parse_transforms_into_list_when_present() { + var token = new Token("#test.cap#"); + + Assert.isTrue(token.transforms.length > 0); + Assert.equals("cap", token.transforms[0]); + } + + function test_should_have_empty_transforms_list_when_not_present() { + var token = new Token("#test#"); + + Assert.isFalse(token.transforms.length > 0); + } + + function test_should_be_marked_as_function_when_wrapped_in_parens() { + var token = new Token("#random(5, 10)#"); + + Assert.isTrue(token.isFunction); + Assert.equals("random", token.symbol); + Assert.equals("5", token.functionArgs[0]); + Assert.equals("10", token.functionArgs[1]); + } + + function test_should_be_marked_as_function_with_no_params() { + var token = new Token("#random()#"); + + Assert.isTrue(token.isFunction); + Assert.equals("random", token.symbol); + Assert.equals(0, token.functionArgs.length); + } + + function test_should_not_be_marked_as_function_when_no_parens() { + var token = new Token("#random#"); + + Assert.isFalse(token.isFunction); + Assert.equals("random", token.symbol); + Assert.equals(0, token.functionArgs.length); + } + + function test_should_be_marked_as_silent_when_wrapped_with_brackets() { + var token = new Token("#[test]#"); + + Assert.isTrue(token.isExpandable); + Assert.isTrue(token.isSilent); + Assert.equals("test", token.symbol); + } + + function test_should_not_be_marked_as_silent_when_no_square_brackets() { + var token = new Token("#test#"); + + Assert.isFalse(token.isSilent); + Assert.equals("test", token.symbol); + } + + function test_silent_memory_function_with_transforms() { + var token = new Token("#[t:test(5).capitalize.a]#"); + + Assert.isTrue(token.isSilent); + Assert.isTrue(token.isFunction); + Assert.isTrue(token.isMemorized); + Assert.isTrue(token.isTransformed); + Assert.equals("test", token.symbol); + Assert.equals("t", token.memSymbol); + Assert.equals("5", token.functionArgs[0]); + Assert.equals("capitalize", token.transforms[0]); + Assert.equals("a", token.transforms[1]); + } +} diff --git a/test/storygen/TransformsTest.hx b/test/storygen/TransformsTest.hx deleted file mode 100644 index 573dcf3..0000000 --- a/test/storygen/TransformsTest.hx +++ /dev/null @@ -1,59 +0,0 @@ -package storygen; - -import massive.munit.Assert; -import dropecho.storygen.*; - -class TransformsTest { - @Test - public function capitalize() { - var s = "hi"; - var expected = "Hi"; - - var out = Transforms.get("capitalize")(s); - Assert.areEqual(expected, out); - } - - @Test - public function titlize() { - var s = "lord banana of lemonville"; - var expected = "Lord Banana Of Lemonville"; - - var out = Transforms.get("titlize")(s); - Assert.areEqual(expected, out); - } - - @Test - public function a_const() { - var s = "bird"; - var expected = "a bird"; - - var out = Transforms.get('a')(s); - Assert.areEqual(expected, out); - } - - @Test - public function a_const_by_name() { - var s = "bird"; - var expected = "a bird"; - - var out = Transforms.get("a")(s); - Assert.areEqual(expected, out); - } - - @Test - public function a_vowel() { - var s = "owl"; - var expected = "an owl"; - - var out = Transforms.get('a')(s); - Assert.areEqual(expected, out); - } - - @Test - public function pluralize() { - Assert.areEqual("owls", Transforms.get('pluralize')("owl")); - Assert.areEqual("birds", Transforms.get('pluralize')("bird")); - Assert.areEqual("batches", Transforms.get('pluralize')("batch")); - Assert.areEqual("glories", Transforms.get('pluralize')("glory")); - } -} diff --git a/test/storygen/Transforms_Tests.hx b/test/storygen/Transforms_Tests.hx new file mode 100644 index 0000000..6d7fe96 --- /dev/null +++ b/test/storygen/Transforms_Tests.hx @@ -0,0 +1,53 @@ +package storygen; + +import utest.Assert; +import dropecho.storygen.*; + +class Transforms_Tests extends utest.Test { + public function test_capitalize() { + var s = "hi"; + var expected = "Hi"; + + var out = Transforms.get("capitalize")(s); + Assert.equals(expected, out); + } + + public function test_titlize() { + var s = "lord banana of lemonville"; + var expected = "Lord Banana Of Lemonville"; + + var out = Transforms.get("titlize")(s); + Assert.equals(expected, out); + } + + public function test_a_const() { + var s = "bird"; + var expected = "a bird"; + + var out = Transforms.get('a')(s); + Assert.equals(expected, out); + } + + public function test_a_const_by_name() { + var s = "bird"; + var expected = "a bird"; + + var out = Transforms.get("a")(s); + Assert.equals(expected, out); + } + + public function test_a_vowel() { + var s = "owl"; + var expected = "an owl"; + + var out = Transforms.get('a')(s); + Assert.equals(expected, out); + } + + public function test_pluralize() { + Assert.equals("owls", Transforms.get('pluralize')("owl")); + Assert.equals("birds", Transforms.get('pluralize')("bird")); + Assert.equals("batches", Transforms.get('pluralize')("batch")); + Assert.equals("glories", Transforms.get('pluralize')("glory")); + } +}