|
|
@ -1,6 +1,6 @@ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set of tests for functionality of JSON printing/parsing. |
|
|
|
* Set of tests for functionality of JSON printing/parsing. |
|
|
|
* Copyright 2021 Anton Tarasenko |
|
|
|
* Copyright 2021-2022 Anton Tarasenko |
|
|
|
*------------------------------------------------------------------------------ |
|
|
|
*------------------------------------------------------------------------------ |
|
|
|
* This file is part of Acedia. |
|
|
|
* This file is part of Acedia. |
|
|
|
* |
|
|
|
* |
|
|
@ -226,9 +226,9 @@ protected static function SubTest_SimplePrint() |
|
|
|
|
|
|
|
|
|
|
|
protected static function SubTest_ArrayPrint() |
|
|
|
protected static function SubTest_ArrayPrint() |
|
|
|
{ |
|
|
|
{ |
|
|
|
local DynamicArray array, subArray; |
|
|
|
local ArrayList array, subArray; |
|
|
|
array = DynamicArray(__().memory.Allocate(class'DynamicArray')); |
|
|
|
array = ArrayList(__().memory.Allocate(class'ArrayList')); |
|
|
|
subArray = DynamicArray(__().memory.Allocate(class'DynamicArray')); |
|
|
|
subArray = ArrayList(__().memory.Allocate(class'ArrayList')); |
|
|
|
subArray.AddItem(__().box.int(-752)); |
|
|
|
subArray.AddItem(__().box.int(-752)); |
|
|
|
subArray.AddItem(__().ref.bool(true)); |
|
|
|
subArray.AddItem(__().ref.bool(true)); |
|
|
|
subArray.AddItem(__().box.float(3.44)); |
|
|
|
subArray.AddItem(__().box.float(3.44)); |
|
|
@ -239,7 +239,7 @@ protected static function SubTest_ArrayPrint() |
|
|
|
array.AddItem(__().text.FromString(" ")); |
|
|
|
array.AddItem(__().text.FromString(" ")); |
|
|
|
Issue("JSON arrays are not printed as expected."); |
|
|
|
Issue("JSON arrays are not printed as expected."); |
|
|
|
TEST_ExpectTrue( |
|
|
|
TEST_ExpectTrue( |
|
|
|
__().json.PrintArray(array).ToString() |
|
|
|
__().json.PrintArrayList(array).ToString() |
|
|
|
== "[34.1,null,[-752,true,3.44,\"\\\"quoted text\\\"\"],\"\\t\"]"); |
|
|
|
== "[34.1,null,[-752,true,3.44,\"\\\"quoted text\\\"\"],\"\\t\"]"); |
|
|
|
TEST_ExpectTrue( |
|
|
|
TEST_ExpectTrue( |
|
|
|
__().json.Print(array).ToString() |
|
|
|
__().json.Print(array).ToString() |
|
|
@ -461,19 +461,19 @@ protected static function SubTest_ParseString() |
|
|
|
|
|
|
|
|
|
|
|
protected static function SubTest_ParseArraySuccess() |
|
|
|
protected static function SubTest_ParseArraySuccess() |
|
|
|
{ |
|
|
|
{ |
|
|
|
local Parser parser; |
|
|
|
local Parser parser; |
|
|
|
local DynamicArray result; |
|
|
|
local ArrayList result; |
|
|
|
Issue("`ParseArrayWith()` fails to parse empty JSON array."); |
|
|
|
Issue("`ParseArrayListWith()` fails to parse empty JSON array."); |
|
|
|
parser = __().text.ParseString("[]"); |
|
|
|
parser = __().text.ParseString("[]"); |
|
|
|
result = __().json.ParseArrayWith(parser); |
|
|
|
result = __().json.ParseArrayListWith(parser); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectTrue(parser.OK()); |
|
|
|
TEST_ExpectTrue(parser.OK()); |
|
|
|
TEST_ExpectTrue(result.GetLength() == 0); |
|
|
|
TEST_ExpectTrue(result.GetLength() == 0); |
|
|
|
|
|
|
|
|
|
|
|
Issue("`ParseArrayWith()` fails to parse correct JSON arrays" |
|
|
|
Issue("`ParseArrayListWith()` fails to parse correct JSON arrays" |
|
|
|
@ "(as immutable)."); |
|
|
|
@ "(as immutable)."); |
|
|
|
parser = __().text.ParseString("[true, 76.4, \"val\", null, 5]"); |
|
|
|
parser = __().text.ParseString("[true, 76.4, \"val\", null, 5]"); |
|
|
|
result = __().json.ParseArrayWith(parser); |
|
|
|
result = __().json.ParseArrayListWith(parser); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectTrue(parser.OK()); |
|
|
|
TEST_ExpectTrue(parser.OK()); |
|
|
|
TEST_ExpectTrue(result.GetLength() == 5); |
|
|
|
TEST_ExpectTrue(result.GetLength() == 5); |
|
|
@ -483,9 +483,9 @@ protected static function SubTest_ParseArraySuccess() |
|
|
|
TEST_ExpectNone(result.GetItem(3)); |
|
|
|
TEST_ExpectNone(result.GetItem(3)); |
|
|
|
TEST_ExpectTrue(IntBox(result.GetItem(4)).Get() == 5); |
|
|
|
TEST_ExpectTrue(IntBox(result.GetItem(4)).Get() == 5); |
|
|
|
|
|
|
|
|
|
|
|
Issue("`ParseArrayWith()` fails to parse correct JSON arrays" |
|
|
|
Issue("`ParseArrayListWith()` fails to parse correct JSON arrays" |
|
|
|
@ "(as mutable)."); |
|
|
|
@ "(as mutable)."); |
|
|
|
result = __().json.ParseArrayWith(parser.R(), true); |
|
|
|
result = __().json.ParseArrayListWith(parser.R(), true); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectTrue(parser.OK()); |
|
|
|
TEST_ExpectTrue(parser.OK()); |
|
|
|
TEST_ExpectTrue(result.GetLength() == 5); |
|
|
|
TEST_ExpectTrue(result.GetLength() == 5); |
|
|
@ -498,22 +498,22 @@ protected static function SubTest_ParseArraySuccess() |
|
|
|
|
|
|
|
|
|
|
|
protected static function SubTest_ParseArrayFailure() |
|
|
|
protected static function SubTest_ParseArrayFailure() |
|
|
|
{ |
|
|
|
{ |
|
|
|
local Parser parser; |
|
|
|
local Parser parser; |
|
|
|
local DynamicArray result; |
|
|
|
local ArrayList result; |
|
|
|
Issue("`ParseArrayWith()` incorrectly handles parsing invalid" |
|
|
|
Issue("`ParseArrayListWith()` incorrectly handles parsing invalid" |
|
|
|
@ "JSON arrays."); |
|
|
|
@ "JSON arrays."); |
|
|
|
parser = __().text.ParseString("[,]"); |
|
|
|
parser = __().text.ParseString("[,]"); |
|
|
|
result = __().json.ParseArrayWith(parser); |
|
|
|
result = __().json.ParseArrayListWith(parser); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
|
|
|
|
|
|
|
|
parser = __().text.ParseString("[true, 76.4, \"val\", null, 5"); |
|
|
|
parser = __().text.ParseString("[true, 76.4, \"val\", null, 5"); |
|
|
|
result = __().json.ParseArrayWith(parser); |
|
|
|
result = __().json.ParseArrayListWith(parser); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
|
|
|
|
|
|
|
|
parser = __().text.ParseString("[true, 76.4, \"val\", null,]"); |
|
|
|
parser = __().text.ParseString("[true, 76.4, \"val\", null,]"); |
|
|
|
result = __().json.ParseArrayWith(parser, true); |
|
|
|
result = __().json.ParseArrayListWith(parser, true); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
} |
|
|
|
} |
|
|
@ -525,17 +525,17 @@ protected static function SubTest_ParseSimpleValueSuccess() |
|
|
|
api = __().json; |
|
|
|
api = __().json; |
|
|
|
Issue("`ParseWith()` fails to parse correct JSON values."); |
|
|
|
Issue("`ParseWith()` fails to parse correct JSON values."); |
|
|
|
parser = __().text.ParseString("false, 98.2, 42, \"hmmm\", null"); |
|
|
|
parser = __().text.ParseString("false, 98.2, 42, \"hmmm\", null"); |
|
|
|
TEST_ExpectFalse(BoolBox(api.ParseWith(parser)).Get()); |
|
|
|
TEST_ExpectFalse(BoolBox(api.ParseWith(parser,, true)).Get()); |
|
|
|
parser.MatchS(",").Skip(); |
|
|
|
parser.MatchS(",").Skip(); |
|
|
|
TEST_ExpectTrue(FloatBox(api.ParseWith(parser)).Get() == 98.2); |
|
|
|
TEST_ExpectTrue(FloatBox(api.ParseWith(parser,, true)).Get() == 98.2); |
|
|
|
parser.MatchS(",").Skip(); |
|
|
|
parser.MatchS(",").Skip(); |
|
|
|
TEST_ExpectTrue(IntRef(api.ParseWith(parser, true)).Get() == 42); |
|
|
|
TEST_ExpectTrue(IntRef(api.ParseWith(parser, true, true)).Get() == 42); |
|
|
|
parser.MatchS(",").Skip(); |
|
|
|
parser.MatchS(",").Skip(); |
|
|
|
TEST_ExpectTrue( |
|
|
|
TEST_ExpectTrue( |
|
|
|
MutableText(api.ParseWith(parser, true)).ToString() |
|
|
|
MutableText(api.ParseWith(parser, true, true)).ToString() |
|
|
|
== "hmmm"); |
|
|
|
== "hmmm"); |
|
|
|
parser.MatchS(",").Skip(); |
|
|
|
parser.MatchS(",").Skip(); |
|
|
|
TEST_ExpectNone(api.ParseWith(parser)); |
|
|
|
TEST_ExpectNone(api.ParseWith(parser,, true)); |
|
|
|
TEST_ExpectTrue(parser.Ok()); |
|
|
|
TEST_ExpectTrue(parser.Ok()); |
|
|
|
} |
|
|
|
} |
|
|
|
protected static function SubTest_ParseSimpleValueFailure() |
|
|
|
protected static function SubTest_ParseSimpleValueFailure() |
|
|
@ -546,31 +546,31 @@ protected static function SubTest_ParseSimpleValueFailure() |
|
|
|
Issue("`ParseWith()` does not correctly handle parsing invalid" |
|
|
|
Issue("`ParseWith()` does not correctly handle parsing invalid" |
|
|
|
@ "JSON values."); |
|
|
|
@ "JSON values."); |
|
|
|
parser = __().text.ParseString("tru"); |
|
|
|
parser = __().text.ParseString("tru"); |
|
|
|
TEST_ExpectNone(api.ParseWith(parser)); |
|
|
|
TEST_ExpectNone(api.ParseWith(parser,, true)); |
|
|
|
TEST_ExpectFalse(parser.Ok()); |
|
|
|
TEST_ExpectFalse(parser.Ok()); |
|
|
|
parser = __().text.ParseString(""); |
|
|
|
parser = __().text.ParseString(""); |
|
|
|
TEST_ExpectNone(api.ParseWith(parser)); |
|
|
|
TEST_ExpectNone(api.ParseWith(parser,, true)); |
|
|
|
TEST_ExpectFalse(parser.Ok()); |
|
|
|
TEST_ExpectFalse(parser.Ok()); |
|
|
|
parser = __().text.ParseString("NUL"); |
|
|
|
parser = __().text.ParseString("NUL"); |
|
|
|
TEST_ExpectNone(api.ParseWith(parser)); |
|
|
|
TEST_ExpectNone(api.ParseWith(parser,, true)); |
|
|
|
TEST_ExpectFalse(parser.Ok()); |
|
|
|
TEST_ExpectFalse(parser.Ok()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static function SubTest_ParseObjectSuccess() |
|
|
|
protected static function SubTest_ParseObjectSuccess() |
|
|
|
{ |
|
|
|
{ |
|
|
|
local Parser parser; |
|
|
|
local Parser parser; |
|
|
|
local AssociativeArray result; |
|
|
|
local HashTable result; |
|
|
|
Issue("`ParseObjectWith()` fails to parse empty JSON object."); |
|
|
|
Issue("`ParseHashTableWith()` fails to parse empty JSON object."); |
|
|
|
parser = __().text.ParseString("{ }"); |
|
|
|
parser = __().text.ParseString("{ }"); |
|
|
|
result = __().json.ParseObjectWith(parser); |
|
|
|
result = __().json.ParseHashTableWith(parser); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectTrue(parser.OK()); |
|
|
|
TEST_ExpectTrue(parser.OK()); |
|
|
|
TEST_ExpectTrue(result.GetLength() == 0); |
|
|
|
TEST_ExpectTrue(result.GetLength() == 0); |
|
|
|
|
|
|
|
|
|
|
|
Issue("`ParseObjectWith()` fails to parse correct JSON objects" |
|
|
|
Issue("`ParseHashTableWith()` fails to parse correct JSON objects" |
|
|
|
@ "(as immutable)."); |
|
|
|
@ "(as immutable)."); |
|
|
|
parser = __().text.ParseString(default.simpleJSONObject); |
|
|
|
parser = __().text.ParseString(default.simpleJSONObject); |
|
|
|
result = __().json.ParseObjectWith(parser); |
|
|
|
result = __().json.ParseHashTableWith(parser); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectTrue(parser.OK()); |
|
|
|
TEST_ExpectTrue(parser.OK()); |
|
|
|
TEST_ExpectTrue(result.GetLength() == 4); |
|
|
|
TEST_ExpectTrue(result.GetLength() == 4); |
|
|
@ -581,9 +581,9 @@ protected static function SubTest_ParseObjectSuccess() |
|
|
|
TEST_ExpectNone(MutableText(result.GetItem(P("string one")))); |
|
|
|
TEST_ExpectNone(MutableText(result.GetItem(P("string one")))); |
|
|
|
TEST_ExpectNone(result.GetItem(P("last"))); |
|
|
|
TEST_ExpectNone(result.GetItem(P("last"))); |
|
|
|
|
|
|
|
|
|
|
|
Issue("`ParseObjectWith()` fails to parse correct JSON objects" |
|
|
|
Issue("`ParseHashTableWith()` fails to parse correct JSON objects" |
|
|
|
@ "(as mutable)."); |
|
|
|
@ "(as mutable)."); |
|
|
|
result = __().json.ParseObjectWith(parser.R(), true); |
|
|
|
result = __().json.ParseHashTableWith(parser.R(), true); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectNotNone(result); |
|
|
|
TEST_ExpectTrue(IntRef(result.GetItem(P("var"))).Get() == 13); |
|
|
|
TEST_ExpectTrue(IntRef(result.GetItem(P("var"))).Get() == 13); |
|
|
|
TEST_ExpectTrue(BoolRef(result.GetItem(P("another"))).Get() == true); |
|
|
|
TEST_ExpectTrue(BoolRef(result.GetItem(P("another"))).Get() == true); |
|
|
@ -595,52 +595,52 @@ protected static function SubTest_ParseObjectSuccess() |
|
|
|
|
|
|
|
|
|
|
|
protected static function SubTest_ParseObjectFailure() |
|
|
|
protected static function SubTest_ParseObjectFailure() |
|
|
|
{ |
|
|
|
{ |
|
|
|
local Parser parser; |
|
|
|
local Parser parser; |
|
|
|
local AssociativeArray result; |
|
|
|
local HashTable result; |
|
|
|
Issue("`ParseObjectWith()` incorrectly handles parsing invalid" |
|
|
|
Issue("`ParseHashTableWith()` incorrectly handles parsing invalid" |
|
|
|
@ "JSON objects."); |
|
|
|
@ "JSON objects."); |
|
|
|
parser = __().text.ParseString("{,}"); |
|
|
|
parser = __().text.ParseString("{,}"); |
|
|
|
result = __().json.ParseObjectWith(parser); |
|
|
|
result = __().json.ParseHashTableWith(parser); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
parser = __().text.ParseString("{var:null}"); |
|
|
|
parser = __().text.ParseString("{var:null}"); |
|
|
|
result = __().json.ParseObjectWith(parser); |
|
|
|
result = __().json.ParseHashTableWith(parser); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
parser = __().text.ParseString("{\"var\":57,}"); |
|
|
|
parser = __().text.ParseString("{\"var\":57,}"); |
|
|
|
result = __().json.ParseObjectWith(parser); |
|
|
|
result = __().json.ParseHashTableWith(parser); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
parser = __().text.ParseString("{,\"var\":true}"); |
|
|
|
parser = __().text.ParseString("{,\"var\":true}"); |
|
|
|
result = __().json.ParseObjectWith(parser); |
|
|
|
result = __().json.ParseHashTableWith(parser); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectNone(result); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
TEST_ExpectFalse(parser.OK()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static function SubTest_ParseComplex() |
|
|
|
protected static function SubTest_ParseComplex() |
|
|
|
{ |
|
|
|
{ |
|
|
|
local Parser parser; |
|
|
|
local Parser parser; |
|
|
|
local DynamicArray subArr; |
|
|
|
local ArrayList subArr; |
|
|
|
local AssociativeArray root, mainObj, subObj, inner; |
|
|
|
local HashTable root, mainObj, subObj, inner; |
|
|
|
Issue("`ParseObjectWith()` cannot handle complex values."); |
|
|
|
Issue("`ParseHashTableWith()` cannot handle complex values."); |
|
|
|
parser = __().text.ParseString(default.complexJSONObject); |
|
|
|
parser = __().text.ParseString(default.complexJSONObject); |
|
|
|
root = AssociativeArray(__().json.ParseWith(parser)); |
|
|
|
root = HashTable(__().json.ParseWith(parser,, true)); |
|
|
|
TEST_ExpectTrue(root.GetLength() == 3); |
|
|
|
TEST_ExpectTrue(root.GetLength() == 3); |
|
|
|
TEST_ExpectTrue(FloatBox(root.GetItem(P("some_var"))).Get() == -7.32); |
|
|
|
TEST_ExpectTrue(FloatBox(root.GetItem(P("some_var"))).Get() == -7.32); |
|
|
|
TEST_ExpectTrue( Text(root.GetItem(P("another_var"))).ToString() |
|
|
|
TEST_ExpectTrue( Text(root.GetItem(P("another_var"))).ToString() |
|
|
|
== "aye!"); |
|
|
|
== "aye!"); |
|
|
|
mainObj = AssociativeArray(root.GetItem(P("innerObject"))); |
|
|
|
mainObj = HashTable(root.GetItem(P("innerObject"))); |
|
|
|
TEST_ExpectTrue(root.GetLength() == 3); |
|
|
|
TEST_ExpectTrue(root.GetLength() == 3); |
|
|
|
TEST_ExpectTrue(BoolBox(mainObj.GetItem(P("my_bool"))).Get() == true); |
|
|
|
TEST_ExpectTrue(BoolBox(mainObj.GetItem(P("my_bool"))).Get() == true); |
|
|
|
TEST_ExpectTrue(IntBox(mainObj.GetItem(P("my_int"))).Get() == -9823452); |
|
|
|
TEST_ExpectTrue(IntBox(mainObj.GetItem(P("my_int"))).Get() == -9823452); |
|
|
|
subObj = AssociativeArray(mainObj.GetItem(P("one more"))); |
|
|
|
subObj = HashTable(mainObj.GetItem(P("one more"))); |
|
|
|
subArr = DynamicArray(mainObj.GetItem(P("array"))); |
|
|
|
subArr = ArrayList(mainObj.GetItem(P("array"))); |
|
|
|
TEST_ExpectTrue(subObj.GetLength() == 3); |
|
|
|
TEST_ExpectTrue(subObj.GetLength() == 3); |
|
|
|
TEST_ExpectTrue(IntBox(subObj.GetItem(P("nope"))).Get() == 324532); |
|
|
|
TEST_ExpectTrue(IntBox(subObj.GetItem(P("nope"))).Get() == 324532); |
|
|
|
TEST_ExpectTrue(BoolBox(subObj.GetItem(P("whatever"))).Get() == false); |
|
|
|
TEST_ExpectTrue(BoolBox(subObj.GetItem(P("whatever"))).Get() == false); |
|
|
|
TEST_ExpectTrue( Text(subObj.GetItem(P("o rly?"))).ToString() |
|
|
|
TEST_ExpectTrue( Text(subObj.GetItem(P("o rly?"))).ToString() |
|
|
|
== "ya rly"); |
|
|
|
== "ya rly"); |
|
|
|
inner = AssociativeArray(subArr.GetItem(3)); |
|
|
|
inner = HashTable(subArr.GetItem(3)); |
|
|
|
TEST_ExpectTrue(Text(subArr.GetItem(0)).ToString() == "Engine.Actor"); |
|
|
|
TEST_ExpectTrue(Text(subArr.GetItem(0)).ToString() == "Engine.Actor"); |
|
|
|
TEST_ExpectTrue(BoolBox(subArr.GetItem(1)).Get() == false); |
|
|
|
TEST_ExpectTrue(BoolBox(subArr.GetItem(1)).Get() == false); |
|
|
|
TEST_ExpectNone(subArr.GetItem(2)); |
|
|
|
TEST_ExpectNone(subArr.GetItem(2)); |
|
|
|