diff --git a/.gitignore b/.gitignore index 5379f74..422511d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ /.idea/ /.haxelib +/.vscode +/test/dev.hxml \ No newline at end of file diff --git a/src/yaml/Parser.hx b/src/yaml/Parser.hx index f54aa3d..418f39f 100644 --- a/src/yaml/Parser.hx +++ b/src/yaml/Parser.hx @@ -1994,15 +1994,15 @@ class Parser hash; }; - #if (neko || cpp || display) + #if (neko || cpp || display || php) public static var PATTERN_NON_PRINTABLE = ~/[\x{00}-\x{08}\x{0B}\x{0C}\x{0E}-\x{1F}\x{7F}-\x{84}\x{86}-\x{9F}\x{FFFE}\x{FFFF}]/u; #elseif (js || flash9 || java) public static var PATTERN_NON_PRINTABLE = ~/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uD800-\uDFFF\uFFFE\uFFFF]/u; #else #error "Compilation target not supported due to lack of Unicode RegEx support." #end - - #if (neko || cpp || display) + + #if (neko || cpp || display || php) public static var PATTERN_NON_ASCII_LINE_BREAKS = ~/[\x{85}\x{2028}\x{2029}]/u; #elseif (js || flash9 || java) public static var PATTERN_NON_ASCII_LINE_BREAKS = ~/[\x85\u2028\u2029]/u; diff --git a/test/TestPhp.hx b/test/TestPhp.hx new file mode 100644 index 0000000..ada12de --- /dev/null +++ b/test/TestPhp.hx @@ -0,0 +1,25 @@ +package; + +import yaml.type.*; +import yaml.YamlTest; +import utest.Runner; +import utest.ui.Report; + +class TestPhp { + static public function main() { + var runner = new Runner(); + runner.addCase(new YPairsTest()); + runner.addCase(new YIntTest()); + runner.addCase(new YBoolTest()); + runner.addCase(new YSetTest()); + runner.addCase(new YMergeTest()); + runner.addCase(new YFloatTest()); + runner.addCase(new YOmapTest()); + runner.addCase(new YTimestampTest()); + runner.addCase(new YBinaryTest()); + runner.addCase(new YNullTest()); + runner.addCase(new YamlTest()); + Report.create(runner); + runner.run(); + } +} \ No newline at end of file diff --git a/test/munit_compat/massive/munit/Assert.hx b/test/munit_compat/massive/munit/Assert.hx new file mode 100644 index 0000000..7059d63 --- /dev/null +++ b/test/munit_compat/massive/munit/Assert.hx @@ -0,0 +1,25 @@ +package massive.munit; + +import haxe.PosInfos; + +class Assert { + static public function areEqual(a:Dynamic, b:Dynamic, ?pos:PosInfos) { + utest.Assert.equals(a, b, pos); + } + + static public function isFalse(a:Bool, ?pos:PosInfos) { + utest.Assert.isFalse(a, pos); + } + + static public function isTrue(a:Bool, ?pos:PosInfos) { + utest.Assert.isTrue(a, pos); + } + + static public function isNull(a:Dynamic, ?pos:PosInfos) { + utest.Assert.isNull(a, pos); + } + + static public function fail(str:String, ?pos:PosInfos) { + utest.Assert.fail(str, pos); + } +} \ No newline at end of file diff --git a/test/test.hxml b/test/test.hxml index c4a0694..960b21b 100644 --- a/test/test.hxml +++ b/test/test.hxml @@ -50,4 +50,31 @@ #-D HXCPP_M64 -cpp bin/cpp_test +--next + +## PHP7 +-main TestPhp +-lib hamcrest +-lib utest +-cp src +-resource resource/small_sample.yaml@small +-resource resource/sample.yaml@large + +-cp test/munit_compat +-cp test +-D php7 +-php bin/php7 +--next + +## PHP +-main TestPhp +-lib hamcrest +-lib utest +-cp src +-resource resource/small_sample.yaml@small +-resource resource/sample.yaml@large + +-cp test/munit_compat +-cp test +-php bin/php diff --git a/test/yaml/YamlTest.hx b/test/yaml/YamlTest.hx index f787351..67d8687 100644 --- a/test/yaml/YamlTest.hx +++ b/test/yaml/YamlTest.hx @@ -10,25 +10,28 @@ class YamlTest var smallSample:String; var largeSample:String; + public function new() init(); + @BeforeClass public function init() { smallSample = haxe.Resource.getString("small"); largeSample = haxe.Resource.getString("large"); } - + @TestDebug - public function shouldParseYaml() + public function testShouldParseYaml() { var time = haxe.Timer.stamp(); // var data:Dynamic = Yaml.parse(smallSample, Parser.options().useObjects()); var data:Dynamic = Yaml.parse(largeSample, Parser.options().useObjects()); trace((haxe.Timer.stamp() - time)); - + #if sys Yaml.write("bin/test/output.yaml", data); #else trace(Yaml.render(data)); #end + Assert.isTrue(true); } } diff --git a/test/yaml/type/YBinaryTest.hx b/test/yaml/type/YBinaryTest.hx index 769bb73..e4d7ff3 100644 --- a/test/yaml/type/YBinaryTest.hx +++ b/test/yaml/type/YBinaryTest.hx @@ -5,8 +5,10 @@ import massive.munit.Assert; class YBinaryTest { + public function new() {} + @Test - public function shouldResolveAndRepresentBinary() + public function testShouldResolveAndRepresentBinary() { var type = new YBinary(); var data:Bytes = cast type.resolve(createValue()); diff --git a/test/yaml/type/YBoolTest.hx b/test/yaml/type/YBoolTest.hx index 815cabe..267b983 100644 --- a/test/yaml/type/YBoolTest.hx +++ b/test/yaml/type/YBoolTest.hx @@ -7,26 +7,28 @@ class YBoolTest { var type:AnyYamlType; + public function new() {} + @Before - public function before() + public function setup() { type = new YBool(); } - + @Test - public function shouldResolveExplicitValues() + public function testShouldResolveExplicitValues() { var pos = ["true", "True", "TRUE", "y", "Y", "yes", "Yes", "YES", "on", "On", "ON"]; for (value in pos) Assert.isTrue(type.resolve(value, true, true)); - + var neg = ["n", "N", "no", "No", "NO", "false", "False", "FALSE", "off", "Off", "OFF"]; for (value in neg) Assert.isFalse(type.resolve(value, true, true)); } @Test - public function shouldResolveImplicitValues() + public function testShouldResolveImplicitValues() { var pos = ["true", "True", "TRUE"]; for (value in pos) @@ -36,9 +38,9 @@ class YBoolTest for (value in neg) Assert.isFalse(type.resolve(value, true, false)); } - + @Test - public function shouldNotResolveExplicitValueWhenImplicit() + public function testShouldNotResolveExplicitValueWhenImplicit() { var values = ["y", "Y", "yes", "Yes", "YES", "on", "On", "ON", "n", "N", "no", "No", "NO", "off", "Off", "OFF"]; while (values.length > 0) @@ -55,7 +57,7 @@ class YBoolTest } @Test - public function shouldRepresentValue() + public function testShouldRepresentValue() { Assert.areEqual(type.represent(true, "uppercase"), "TRUE"); Assert.areEqual(type.represent(false, "uppercase"), "FALSE"); diff --git a/test/yaml/type/YFloatTest.hx b/test/yaml/type/YFloatTest.hx index cf26f23..c140c31 100644 --- a/test/yaml/type/YFloatTest.hx +++ b/test/yaml/type/YFloatTest.hx @@ -7,39 +7,41 @@ class YFloatTest { var type:YFloat; + public function new() {} + @Before - public function before() + public function setup() { type = new YFloat(); } @Test - public function shouldResolveFloat() + public function testShouldResolveFloat() { var const = 685230.15; - + var values = ["6.8523015e+5", "685.230_15e+03", "685_230.15", "190:20:30.15"]; for (value in values) Assert.areEqual(const, type.resolve(value)); - + Assert.areEqual(Math.NEGATIVE_INFINITY, type.resolve("-.inf")); Assert.areEqual(Math.POSITIVE_INFINITY, type.resolve(".inf")); Assert.isTrue(Math.isNaN(type.resolve(".NaN"))); } @Test - public function shouldRepresentFloat() + public function testShouldRepresentFloat() { Assert.areEqual("685230.15", type.represent(685230.15)); - + Assert.areEqual(".inf", type.represent(Math.POSITIVE_INFINITY, "lowercase")); Assert.areEqual(".INF", type.represent(Math.POSITIVE_INFINITY, "uppercase")); Assert.areEqual(".Inf", type.represent(Math.POSITIVE_INFINITY, "camelcase")); - + Assert.areEqual("-.inf", type.represent(Math.NEGATIVE_INFINITY, "lowercase")); Assert.areEqual("-.INF", type.represent(Math.NEGATIVE_INFINITY, "uppercase")); Assert.areEqual("-.Inf", type.represent(Math.NEGATIVE_INFINITY, "camelcase")); - + Assert.areEqual(".nan", type.represent(Math.NaN, "lowercase")); Assert.areEqual(".NAN", type.represent(Math.NaN, "uppercase")); Assert.areEqual(".NaN", type.represent(Math.NaN, "camelcase")); diff --git a/test/yaml/type/YIntTest.hx b/test/yaml/type/YIntTest.hx index 8bc5b4a..cbacc96 100644 --- a/test/yaml/type/YIntTest.hx +++ b/test/yaml/type/YIntTest.hx @@ -8,14 +8,16 @@ class YIntTest var type:YInt; + public function new() {} + @Before - public function before() + public function setup() { type = new YInt(); } @Test - public function shouldResolveInt() + public function testShouldResolveInt() { var canonical = "685230"; var decimal = "+685_230"; @@ -25,7 +27,7 @@ class YIntTest var binaryA = "0b1010_0111_0100_1010_1110"; var binaryB = "0b10100111010010101110"; var sexagesimal = "190:20:30"; - + Assert.areEqual(CONST, type.resolve(canonical)); Assert.areEqual(CONST, type.resolve(decimal)); Assert.areEqual(CONST, type.resolve(octal)); @@ -37,7 +39,7 @@ class YIntTest } @Test - public function shouldRepresentInt() + public function testShouldRepresentInt() { Assert.areEqual("0b10100111010010101110", type.represent(CONST, "binary")); Assert.areEqual("02472256", type.represent(CONST, "octal")); diff --git a/test/yaml/type/YMergeTest.hx b/test/yaml/type/YMergeTest.hx index 5f9d15a..d7ae839 100644 --- a/test/yaml/type/YMergeTest.hx +++ b/test/yaml/type/YMergeTest.hx @@ -5,12 +5,14 @@ import massive.munit.Assert; class YMergeTest { + public function new() {} + @Test - public function shouldResolveMerge() + public function testShouldResolveMerge() { var type = new YMerge(); Assert.areEqual("<<", type.resolve("<<")); - + try { type.resolve(""); Assert.fail("Should not resolve merge on any value but '<<'"); diff --git a/test/yaml/type/YNullTest.hx b/test/yaml/type/YNullTest.hx index 494dc88..714f948 100644 --- a/test/yaml/type/YNullTest.hx +++ b/test/yaml/type/YNullTest.hx @@ -7,20 +7,22 @@ class YNullTest { var type:YNull; + public function new() {} + @Before - public function before() + public function setup() { type = new YNull(); } @Test - public function shouldResolveNull() + public function testShouldResolveNull() { Assert.isNull(type.resolve("null")); Assert.isNull(type.resolve("Null")); Assert.isNull(type.resolve("NULL")); Assert.isNull(type.resolve("~")); - + try { type.resolve("some value"); Assert.fail("Should not resolve non-null value"); @@ -30,7 +32,7 @@ class YNullTest } @Test - public function shouldRepresentNull() + public function testShouldRepresentNull() { Assert.areEqual("~", type.represent(null, "canonical")); Assert.areEqual("null", type.represent(null, "lowercase")); diff --git a/test/yaml/type/YOmapTest.hx b/test/yaml/type/YOmapTest.hx index 341574a..050772f 100644 --- a/test/yaml/type/YOmapTest.hx +++ b/test/yaml/type/YOmapTest.hx @@ -8,8 +8,10 @@ class YOmapTest { var type:YOmap; + public function new() {} + @Before - public function before() + public function setup() { type = new YOmap(); } @@ -18,7 +20,7 @@ class YOmapTest @Ignore("CPP seems to be passing arrays by value(?) so comparison check fails") #end @Test - public function shouldAllowValidOmap() + public function testShouldAllowValidOmap() { var value:Array = [map("key01", "value01"), map("key02", "value02")]; shouldPass(value); @@ -26,9 +28,9 @@ class YOmapTest var value:Array = [map("key01", null), map("key02", null)]; shouldPass(value); } - + @Test - public function shouldFailInvalidOmap() + public function testShouldFailInvalidOmap() { var value:Array = [map("key01", "value01"), map("key01", "value02")]; shouldFail(value); @@ -50,7 +52,9 @@ class YOmapTest type.resolve(value); Assert.fail("Expected failure of omap resolution but succeeded. " + value); } - catch(e:ResolveTypeException) {} + catch(e:ResolveTypeException) { + Assert.isTrue(true); + } } function map(key:Dynamic, value:Dynamic):AnyObjectMap diff --git a/test/yaml/type/YPairsTest.hx b/test/yaml/type/YPairsTest.hx index b35f07a..5777eca 100644 --- a/test/yaml/type/YPairsTest.hx +++ b/test/yaml/type/YPairsTest.hx @@ -8,14 +8,16 @@ class YPairsTest { var type:YPairs; + public function new() {} + @Before - public function before() + public function setup() { type = new YPairs(); } @Test - public function shouldAllowValidPair() + public function testShouldAllowValidPair() { var value:Array = [map("key01", "value01"), map("key02", "value02")]; shouldPass(value); @@ -28,7 +30,7 @@ class YPairsTest } @Test - public function shouldFailInvalidOmap() + public function testShouldFailInvalidOmap() { var m = map("key01", "value01"); m.set("key02", "value02"); @@ -40,13 +42,13 @@ class YPairsTest { var result = type.resolve(value); Assert.areEqual(value.length, result.length); - + for (i in 0...value.length) { var key = null; for (k in value[i].keys()) key = k; - + Assert.areEqual(result[i][0], key); Assert.areEqual(result[i][1], value[i].get(key)); } @@ -58,7 +60,9 @@ class YPairsTest type.resolve(value); Assert.fail("Expected failure of pairs resolution but succeeded. " + value); } - catch(e:ResolveTypeException) {} + catch(e:ResolveTypeException) { + Assert.isTrue(true); + } } function map(key:Dynamic, value:Dynamic):AnyObjectMap diff --git a/test/yaml/type/YSetTest.hx b/test/yaml/type/YSetTest.hx index ba14d9d..d1482ae 100644 --- a/test/yaml/type/YSetTest.hx +++ b/test/yaml/type/YSetTest.hx @@ -6,29 +6,31 @@ import massive.munit.Assert; class YSetTest { + public function new() {} + @Test - public function shouldOnlyAllowNullValuesInMaps() + public function testShouldOnlyAllowNullValuesInMaps() { var type = new YSet(); var map = new AnyObjectMap(); map.set("key", "value"); - + try { type.resolve(map); Assert.fail("Expcted failure due to map having non-null value"); } catch(e:ResolveTypeException) { - + Assert.isTrue(true); } } @Test - public function shouldAllowMapsWithNullValue() + public function testShouldAllowMapsWithNullValue() { var type = new YSet(); var map = new AnyObjectMap(); map.set("key", null); - + Assert.areEqual(map, type.resolve(map)); } diff --git a/test/yaml/type/YTimestampTest.hx b/test/yaml/type/YTimestampTest.hx index 0ed9c9d..cc05464 100644 --- a/test/yaml/type/YTimestampTest.hx +++ b/test/yaml/type/YTimestampTest.hx @@ -8,17 +8,21 @@ class YTimestampTest var type:YTimestamp; + public function new() {} + @Before - public function before() + public function setup() { type = new YTimestamp(); } #if !(js || flash) @Ignore("UTC Dates not supported on this target") - #end @Test - public function shouldResolveTimestamp() + public function testShouldResolveTimestamp() Assert.isTrue(true); + #else + @Test + public function testShouldResolveTimestamp() { var canonical = "2001-12-15T02:59:43.1Z"; var validIso8601 = "2001-12-14t21:59:43.10-05:00"; @@ -26,20 +30,24 @@ class YTimestampTest var noTimeZone = "2001-12-15 2:59:43.10"; var date = "2002-12-14"; var time:Float = 1039824000000; - + Assert.areEqual(STAMP, type.resolve(canonical).getTime()); Assert.areEqual(STAMP, type.resolve(validIso8601).getTime()); Assert.areEqual(STAMP, type.resolve(spaceSeparated).getTime()); Assert.areEqual(STAMP, type.resolve(noTimeZone).getTime()); Assert.areEqual(time, type.resolve(date).getTime()); } + #end #if !(js || flash) @Ignore("UTC Dates not supported on this target") - #end @Test - public function shouldRepresentTimestamp() + public function testShouldRepresentTimestamp() Assert.isTrue(true); + #else + @Test + public function testShouldRepresentTimestamp() { Assert.areEqual("2001-12-15T02:59:43.100Z", type.represent(Date.fromTime(STAMP))); } + #end }