Switch to new API - close #8
The new API is more C-like and will allow consistency across all future supported language targets.
This commit is contained in:
1 parent
e0e5e87338
commit
7a1b4064c1
15 files changed
+611
-481
No files matched your search
+25
-24
@@ -10,44 +10,45 @@ int main()
|
||||
unittest
|
||||
{
|
||||
string input = ``;
|
||||
auto parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
p_context_t context;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
|
||||
input = `{}`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONObject)parser.result);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONObject)p_result(&context));
|
||||
|
||||
input = `[]`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONArray)parser.result);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONArray)p_result(&context));
|
||||
|
||||
input = `-45.6`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONNumber)parser.result);
|
||||
assert((cast(JSONNumber)parser.result).value == -45.6);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONNumber)p_result(&context));
|
||||
assert((cast(JSONNumber)p_result(&context)).value == -45.6);
|
||||
|
||||
input = `2E-2`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONNumber)parser.result);
|
||||
assert((cast(JSONNumber)parser.result).value == 0.02);
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONNumber)p_result(&context));
|
||||
assert((cast(JSONNumber)p_result(&context)).value == 0.02);
|
||||
|
||||
input = `{"hi":true}`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONObject)parser.result);
|
||||
JSONObject o = cast(JSONObject)parser.result;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONObject)p_result(&context));
|
||||
JSONObject o = cast(JSONObject)p_result(&context);
|
||||
assert(o.value["hi"]);
|
||||
assert(cast(JSONTrue)o.value["hi"]);
|
||||
|
||||
input = `{"ff": false, "nn": null}`;
|
||||
parser = new Parser(input);
|
||||
assert(parser.parse() == P_SUCCESS);
|
||||
assert(cast(JSONObject)parser.result);
|
||||
o = cast(JSONObject)parser.result;
|
||||
p_context_init(&context, input);
|
||||
assert(p_parse(&context) == P_SUCCESS);
|
||||
assert(cast(JSONObject)p_result(&context));
|
||||
o = cast(JSONObject)p_result(&context);
|
||||
assert(o.value["ff"]);
|
||||
assert(cast(JSONFalse)o.value["ff"]);
|
||||
assert(o.value["nn"]);
|
||||
|
||||
Reference in new issue
Block a user