]> granicus.if.org Git - json-c/commitdiff
update tsetcase for tokener_c
authordota17 <chenguopingdota@163.com>
Thu, 2 Jan 2020 08:18:59 +0000 (16:18 +0800)
committerdota17 <chenguopingdota@163.com>
Thu, 2 Jan 2020 11:19:12 +0000 (19:19 +0800)
tests/test_parse.c
tests/test_parse.expected

index 44694986a3c760a2f66c65ac0308eeb94c9ab2d8..807b457d2cc5246040ce90627bcecc05ca4a69bf 100644 (file)
@@ -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 */
@@ -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 },
@@ -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
@@ -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
index f8c6b6269d064b9a23c577e599bb014ef78ec18b..af075b0368afbcd40d76c0161c4187f192b3e61c 100644 (file)
@@ -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
@@ -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
@@ -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
 ==================================