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

update tsetcase for tokener_c #523

Merged
merged 1 commit into from Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/test_parse.c
Expand Up @@ -85,6 +85,12 @@ static void test_basic_parse()
single_basic_parse("True", 0);
single_basic_parse("False", 0);

/* not case sensitive */
single_basic_parse("tRue", 0);
single_basic_parse("fAlse", 0);
single_basic_parse("nAn", 0);
single_basic_parse("iNfinity", 0);

single_basic_parse("12", 0);
single_basic_parse("12.3", 0);
single_basic_parse("12.3.4", 0); /* non-sensical, returns null */
Expand Down Expand Up @@ -280,6 +286,7 @@ struct incremental_step {
{ "1234", 5, 4, json_tokener_success, 1 },

{ "Infinity9999", 8, 8, json_tokener_continue, 0 },

/* returns the Infinity loaded up by the previous call: */
{ "1234", 5, 0, json_tokener_success, 0 },
{ "1234", 5, 4, json_tokener_success, 1 },
Expand All @@ -290,6 +297,7 @@ struct incremental_step {
{ "naodle", 7, 2, json_tokener_error_parse_null, 1 },
/* offset=2 because "tr" is the start of "true". hmm... */
{ "track", 6, 2, json_tokener_error_parse_boolean, 1 },
{ "fail", 5, 2, json_tokener_error_parse_boolean, 1 },

/* Although they may initially look like they should fail,
the next few tests check that parsing multiple sequential
Expand Down Expand Up @@ -330,6 +338,13 @@ struct incremental_step {
{ "[1,2,3}", -1, 6, json_tokener_error_parse_array, 1 },
{ "{\"a\"}", -1, 4, json_tokener_error_parse_object_key_sep, 1 },
{ "{\"a\":1]", -1, 6, json_tokener_error_parse_object_value_sep, 1 },
{ "{\"a\"::1}", -1, 5, json_tokener_error_parse_unexpected, 1 },
{ "{\"a\":}", -1, 5, json_tokener_error_parse_unexpected, 1 },
{ "{\"a\":1,\"a\":2}",-1, -1, json_tokener_success, 1 },
{ "\"a\":1}", -1, 3, json_tokener_success, 1 },
{ "{\"a\":1", -1, -1, json_tokener_continue, 1 },
{ "[,]", -1, 1, json_tokener_error_parse_unexpected, 1 },
{ "[,1]", -1, 1, json_tokener_error_parse_unexpected, 1 },

/* This behaviour doesn't entirely follow the json spec, but until we have
a way to specify how strict to be we follow Postel's Law and be liberal
Expand Down
14 changes: 13 additions & 1 deletion tests/test_parse.expected
Expand Up @@ -34,6 +34,10 @@ new_obj.to_string(-Infinoodle)=null
new_obj.to_string(-InfinAAA)=null
new_obj.to_string(True)=true
new_obj.to_string(False)=false
new_obj.to_string(tRue)=true
new_obj.to_string(fAlse)=false
new_obj.to_string(nAn)=NaN
new_obj.to_string(iNfinity)=Infinity
new_obj.to_string(12)=12
new_obj.to_string(12.3)=12.3
new_obj.to_string(12.3.4)=null
Expand Down Expand Up @@ -144,6 +148,7 @@ json_tokener_parse_ex(tok, 1234 , 5) ... OK: got object of type [int]:
json_tokener_parse_ex(tok, noodle , 7) ... OK: got correct error: null expected
json_tokener_parse_ex(tok, naodle , 7) ... OK: got correct error: null expected
json_tokener_parse_ex(tok, track , 6) ... OK: got correct error: boolean expected
json_tokener_parse_ex(tok, fail , 5) ... OK: got correct error: boolean expected
json_tokener_parse_ex(tok, null123 , 9) ... OK: got object of type [null]: null
json_tokener_parse_ex(tok, 123 , 4) ... OK: got object of type [int]: 123
json_tokener_parse_ex(tok, nullx , 5) ... OK: got object of type [null]: null
Expand All @@ -167,9 +172,16 @@ json_tokener_parse_ex(tok, [1,2,3] , 7) ... OK: got object of type [array]
json_tokener_parse_ex(tok, [1,2,3} , 7) ... OK: got correct error: array value separator ',' expected
json_tokener_parse_ex(tok, {"a"} , 5) ... OK: got correct error: object property name separator ':' expected
json_tokener_parse_ex(tok, {"a":1] , 7) ... OK: got correct error: object value separator ',' expected
json_tokener_parse_ex(tok, {"a"::1} , 8) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, {"a":} , 6) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, {"a":1,"a":2}, 13) ... OK: got object of type [object]: { "a": 2 }
json_tokener_parse_ex(tok, "a":1} , 6) ... OK: got object of type [string]: "a"
json_tokener_parse_ex(tok, {"a":1 , 6) ... OK: got correct error: continue
json_tokener_parse_ex(tok, [,] , 3) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, [,1] , 4) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, [1,2,3,] , 8) ... OK: got object of type [array]: [ 1, 2, 3 ]
json_tokener_parse_ex(tok, [1,2,,3,] , 9) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, [1,2,3,] , 8) ... OK: got correct error: unexpected character
json_tokener_parse_ex(tok, {"a":1,} , 8) ... OK: got correct error: unexpected character
End Incremental Tests OK=97 ERROR=0
End Incremental Tests OK=105 ERROR=0
==================================