diff --git a/sources/Commands/Tests/MockCommandB.uc b/sources/Commands/Tests/MockCommandB.uc index 39db901..49b6896 100644 --- a/sources/Commands/Tests/MockCommandB.uc +++ b/sources/Commands/Tests/MockCommandB.uc @@ -43,6 +43,9 @@ protected function BuildData(CommandDataBuilder builder) .ParamBoolean(P("maybe")); builder.Option(P("remainder")) .ParamRemainder(P("everything")); + builder.SubCommand(P("json")) + .ParamJSON(P("first_json")) + .ParamJSONList(P("other_json")); } defaultproperties diff --git a/sources/Commands/Tests/TEST_Command.uc b/sources/Commands/Tests/TEST_Command.uc index 2dfbaba..05a0ac4 100644 --- a/sources/Commands/Tests/TEST_Command.uc +++ b/sources/Commands/Tests/TEST_Command.uc @@ -23,7 +23,7 @@ class TEST_Command extends TestCase var string queryASuccess1, queryASuccess2, queryASuccess3, queryASuccess4; var string queryAFailure1, queryAFailure2; -var string queryBSuccess1, queryBSuccess2, queryBSuccess3; +var string queryBSuccess1, queryBSuccess2, queryBSuccess3, queryBSuccess4; var string queryBFailure1, queryBFailure2, queryBFailure3; var string queryBFailureUnknownOptionLong, queryBFailureUnknownOptionShort; var string queryBFailureUnused; @@ -60,6 +60,7 @@ protected static function Test_MockB() SubTest_MockBQ1(); SubTest_MockBQ2(); SubTest_MockBQ3Remainder(); + SubTest_MockBQ4JSON(); } protected static function Test_CallDataErrors() @@ -413,6 +414,36 @@ protected static function SubTest_MockBQ3Remainder() == "--type \"value\" -va 8 -sV --forced -T \"\" 32"); } +protected static function SubTest_MockBQ4JSON() +{ + local Command.CallData result; + local ArrayList subArray; + local HashTable subObject; + + Issue("Cannot parse command queries with `CPT_JSON` type parameters."); + result = class'MockCommandB'.static.GetInstance() + .ParseInputWith(PRS(default.queryBSuccess4), none); + TEST_ExpectTrue(result.parameters.GetLength() == 2); + subObject = HashTable(result.parameters.GetItem(P("first_json"))); + TEST_ExpectTrue(subObject.GetBool(P("var")) == false); + TEST_ExpectTrue(subObject.GetItem(P("another")) == none); + subArray = ArrayList(result.parameters.GetItem(P("other_json"))); + //[7, 11] null true {} {\"t?\": \"d!\"}" + TEST_ExpectNotNone(ArrayList(subArray.GetItem(0))); + TEST_ExpectTrue(subArray.GetItem(1) == none); + TEST_ExpectTrue(BoolBox(subArray.GetItem(2)).Get() == true); + TEST_ExpectNotNone(HashTable(subArray.GetItem(3))); + TEST_ExpectNotNone(HashTable(subArray.GetItem(4))); + subObject = subArray.GetHashTable(3); + TEST_ExpectTrue(subObject.GetLength() == 0); + subObject = subArray.GetHashTable(4); + TEST_ExpectTrue(subObject.GetLength() == 1); + TEST_ExpectTrue(subObject.GetString(P("t?")) == "d!"); + subArray = ArrayList(subArray.GetItem(0)); + TEST_ExpectTrue(IntBox(subArray.GetItem(0)).Get() == 7); + TEST_ExpectTrue(IntBox(subArray.GetItem(1)).Get() == 11); +} + defaultproperties { caseName = "Command" @@ -428,6 +459,7 @@ defaultproperties queryBSuccess1 = "[7, null] --values 1 3 5 2 4 text" queryBSuccess2 = "do --type \"value\" -va 8 -sV --forced -T \"\" " queryBSuccess3 = "do 3 -76 -r --type \"value\" -va 8 -sV --forced -T \"\" 32" + queryBSuccess4 = "json {\"var\": false, \"another\": null} [7, 11] null true {} {\"t?\": \"d!\"}" // long then same as short queryBFailure1 = "[] 8 -tv 13" queryBFailure2 = "do 7 5 -sfV --forced yes"