Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php support #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@

/.idea/
/.haxelib
/.vscode
/test/dev.hxml
6 changes: 3 additions & 3 deletions src/yaml/Parser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions test/TestPhp.hx
Original file line number Diff line number Diff line change
@@ -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();
}
}
25 changes: 25 additions & 0 deletions test/munit_compat/massive/munit/Assert.hx
Original file line number Diff line number Diff line change
@@ -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);
}
}
27 changes: 27 additions & 0 deletions test/test.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 6 additions & 3 deletions test/yaml/YamlTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 3 additions & 1 deletion test/yaml/type/YBinaryTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
18 changes: 10 additions & 8 deletions test/yaml/type/YBoolTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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");
Expand Down
18 changes: 10 additions & 8 deletions test/yaml/type/YFloatTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
10 changes: 6 additions & 4 deletions test/yaml/type/YIntTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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));
Expand All @@ -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"));
Expand Down
6 changes: 4 additions & 2 deletions test/yaml/type/YMergeTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<<'");
Expand Down
10 changes: 6 additions & 4 deletions test/yaml/type/YNullTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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"));
Expand Down
14 changes: 9 additions & 5 deletions test/yaml/type/YOmapTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ class YOmapTest
{
var type:YOmap;

public function new() {}

@Before
public function before()
public function setup()
{
type = new YOmap();
}
Expand All @@ -18,17 +20,17 @@ 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<AnyObjectMap> = [map("key01", "value01"), map("key02", "value02")];
shouldPass(value);

var value:Array<AnyObjectMap> = [map("key01", null), map("key02", null)];
shouldPass(value);
}

@Test
public function shouldFailInvalidOmap()
public function testShouldFailInvalidOmap()
{
var value:Array<AnyObjectMap> = [map("key01", "value01"), map("key01", "value02")];
shouldFail(value);
Expand All @@ -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
Expand Down
Loading