|
|
@ -120,7 +120,7 @@ int test_primitive() {
|
|
|
|
js = "\"boolVar\" : true";
|
|
|
|
js = "\"boolVar\" : true";
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
check(TOKEN_STRING(js, tok[0], "boolVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[0], "boolVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "true"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "true"));
|
|
|
@ -128,7 +128,7 @@ int test_primitive() {
|
|
|
|
js = "\"boolVar\" : false";
|
|
|
|
js = "\"boolVar\" : false";
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
check(TOKEN_STRING(js, tok[0], "boolVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[0], "boolVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "false"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "false"));
|
|
|
@ -136,7 +136,7 @@ int test_primitive() {
|
|
|
|
js = "\"intVar\" : 12345";
|
|
|
|
js = "\"intVar\" : 12345";
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
check(TOKEN_STRING(js, tok[0], "intVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[0], "intVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "12345"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "12345"));
|
|
|
@ -144,7 +144,7 @@ int test_primitive() {
|
|
|
|
js = "\"floatVar\" : 12.345";
|
|
|
|
js = "\"floatVar\" : 12.345";
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
check(TOKEN_STRING(js, tok[0], "floatVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[0], "floatVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "12.345"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "12.345"));
|
|
|
@ -152,7 +152,7 @@ int test_primitive() {
|
|
|
|
js = "\"nullVar\" : null";
|
|
|
|
js = "\"nullVar\" : null";
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE);
|
|
|
|
check(TOKEN_STRING(js, tok[0], "nullVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[0], "nullVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "null"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "null"));
|
|
|
@ -169,7 +169,7 @@ int test_string() {
|
|
|
|
js = "\"strVar\" : \"hello world\"";
|
|
|
|
js = "\"strVar\" : \"hello world\"";
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
&& tok[1].type == JSMN_STRING);
|
|
|
|
&& tok[1].type == JSMN_STRING);
|
|
|
|
check(TOKEN_STRING(js, tok[0], "strVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[0], "strVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "hello world"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "hello world"));
|
|
|
@ -177,7 +177,7 @@ int test_string() {
|
|
|
|
js = "\"strVar\" : \"escapes: \\/\\r\\n\\t\\b\\f\\\"\\\\\"";
|
|
|
|
js = "\"strVar\" : \"escapes: \\/\\r\\n\\t\\b\\f\\\"\\\\\"";
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
&& tok[1].type == JSMN_STRING);
|
|
|
|
&& tok[1].type == JSMN_STRING);
|
|
|
|
check(TOKEN_STRING(js, tok[0], "strVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[0], "strVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "escapes: \\/\\r\\n\\t\\b\\f\\\"\\\\"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], "escapes: \\/\\r\\n\\t\\b\\f\\\"\\\\"));
|
|
|
@ -185,7 +185,7 @@ int test_string() {
|
|
|
|
js = "\"strVar\" : \"\"";
|
|
|
|
js = "\"strVar\" : \"\"";
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_STRING
|
|
|
|
&& tok[1].type == JSMN_STRING);
|
|
|
|
&& tok[1].type == JSMN_STRING);
|
|
|
|
check(TOKEN_STRING(js, tok[0], "strVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[0], "strVar"));
|
|
|
|
check(TOKEN_STRING(js, tok[1], ""));
|
|
|
|
check(TOKEN_STRING(js, tok[1], ""));
|
|
|
@ -263,18 +263,18 @@ int test_partial_array() {
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
js = " [ 1, true, ";
|
|
|
|
js = " [ 1, true, ";
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r == JSMN_ERROR_PART && tok[0].type == JSMN_ARRAY
|
|
|
|
check(r == JSMN_ERROR_PART && tok[0].type == JSMN_ARRAY
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE);
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE);
|
|
|
|
|
|
|
|
|
|
|
|
js = " [ 1, true, [123, \"hello";
|
|
|
|
js = " [ 1, true, [123, \"hello";
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r == JSMN_ERROR_PART && tok[0].type == JSMN_ARRAY
|
|
|
|
check(r == JSMN_ERROR_PART && tok[0].type == JSMN_ARRAY
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE
|
|
|
|
&& tok[3].type == JSMN_ARRAY && tok[4].type == JSMN_PRIMITIVE);
|
|
|
|
&& tok[3].type == JSMN_ARRAY && tok[4].type == JSMN_PRIMITIVE);
|
|
|
|
|
|
|
|
|
|
|
|
js = " [ 1, true, [123, \"hello\"]";
|
|
|
|
js = " [ 1, true, [123, \"hello\"]";
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r == JSMN_ERROR_PART && tok[0].type == JSMN_ARRAY
|
|
|
|
check(r == JSMN_ERROR_PART && tok[0].type == JSMN_ARRAY
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE
|
|
|
|
&& tok[3].type == JSMN_ARRAY && tok[4].type == JSMN_PRIMITIVE
|
|
|
|
&& tok[3].type == JSMN_ARRAY && tok[4].type == JSMN_PRIMITIVE
|
|
|
|
&& tok[5].type == JSMN_STRING);
|
|
|
|
&& tok[5].type == JSMN_STRING);
|
|
|
@ -283,7 +283,7 @@ int test_partial_array() {
|
|
|
|
|
|
|
|
|
|
|
|
js = " [ 1, true, [123, \"hello\"]]";
|
|
|
|
js = " [ 1, true, [123, \"hello\"]]";
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
r = jsmn_parse(&p, js, strlen(js), tok, 10);
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_ARRAY
|
|
|
|
check(r >= 0 && tok[0].type == JSMN_ARRAY
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE
|
|
|
|
&& tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE
|
|
|
|
&& tok[3].type == JSMN_ARRAY && tok[4].type == JSMN_PRIMITIVE
|
|
|
|
&& tok[3].type == JSMN_ARRAY && tok[4].type == JSMN_PRIMITIVE
|
|
|
|
&& tok[5].type == JSMN_STRING);
|
|
|
|
&& tok[5].type == JSMN_STRING);
|
|
|
@ -470,7 +470,7 @@ int test_count() {
|
|
|
|
js = "[[], [[]], [[], []]]";
|
|
|
|
js = "[[], [[]], [[], []]]";
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 7);
|
|
|
|
check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 7);
|
|
|
|
|
|
|
|
|
|
|
|
js = "[\"a\", [[], []]]";
|
|
|
|
js = "[\"a\", [[], []]]";
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 5);
|
|
|
|
check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 5);
|
|
|
@ -486,7 +486,7 @@ int test_count() {
|
|
|
|
js = "[1, 2, [3, \"a\"], null]";
|
|
|
|
js = "[1, 2, [3, \"a\"], null]";
|
|
|
|
jsmn_init(&p);
|
|
|
|
jsmn_init(&p);
|
|
|
|
check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 7);
|
|
|
|
check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 7);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|