@@ -30,11 +30,10 @@ int test_object(void) {
30
30
JSMN_STRING , "a" , 1 , JSMN_PRIMITIVE , "0" , JSMN_STRING , "b" , 1 ,
31
31
JSMN_STRING , "c" , 0 ));
32
32
33
- #ifdef JSMN_STRICT
33
+ #ifndef JSMN_NON_STRICT
34
34
check (parse ("{\"a\"\n0}" , JSMN_ERROR_INVAL , 3 ));
35
35
check (parse ("{\"a\", 0}" , JSMN_ERROR_INVAL , 3 ));
36
36
check (parse ("{\"a\": {2}}" , JSMN_ERROR_INVAL , 4 ));
37
- check (parse ("{\"a\": {2: 3}}" , JSMN_ERROR_INVAL , 5 ));
38
37
check (parse ("{\"a\": {\"a\": 2 3}}" , JSMN_ERROR_INVAL , 6 ));
39
38
check (parse ("{\"a\"}" , JSMN_ERROR_INVAL , 2 ));
40
39
check (parse ("{\"a\": 1, \"b\"}" , JSMN_ERROR_INVAL , 4 ));
@@ -88,7 +87,7 @@ int test_primitive(void) {
88
87
check (parse ("{\"floatVar\" : 12e+6}" , 3 , 3 , JSMN_OBJECT , -1 , -1 , 1 ,
89
88
JSMN_STRING , "floatVar" , 1 , JSMN_PRIMITIVE , "12e+6" ));
90
89
91
- #ifdef JSMN_STRICT
90
+ #ifndef JSMN_PERMISSIVE_PRIMITIVES
92
91
check (parse ("{\"boolVar\" : tru }" , JSMN_ERROR_INVAL , 3 ));
93
92
check (parse ("{\"boolVar\" : falsee }" , JSMN_ERROR_INVAL , 3 ));
94
93
check (parse ("{\"nullVar\" : nulm }" , JSMN_ERROR_INVAL , 3 ));
@@ -145,7 +144,7 @@ int test_string(void) {
145
144
check (parse ("{\"a\":\"str\xc2\xa9\"}" , 3 , 3 , JSMN_OBJECT , -1 , -1 , 1 ,
146
145
JSMN_STRING , "a" , 1 , JSMN_STRING , "str\xc2\xa9" , 0 ));
147
146
148
- #ifdef JSMN_STRICT
147
+ #ifndef JSMN_PERMISSIVE_STRINGS
149
148
check (parse ("{\"a\":\"str\nstr\"}" , JSMN_ERROR_INVAL , 3 ));
150
149
check (parse ("{\"a\":\"str\\uFFGFstr\"}" , JSMN_ERROR_INVAL , 3 ));
151
150
check (parse ("{\"a\":\"str\\u@FfF\"}" , JSMN_ERROR_INVAL , 3 ));
@@ -236,20 +235,22 @@ int test_array_nomem(void) {
236
235
}
237
236
238
237
int test_unquoted_keys (void ) {
239
- #ifndef JSMN_STRICT
240
238
int r ;
241
239
jsmn_parser p ;
242
240
jsmntok_t tok [10 ];
243
241
const char * js ;
244
242
245
243
jsmn_init (& p );
246
- js = "{key1 : \"value\", key2 : 123 }" ;
244
+ js = "{123 : \"value\", 456 : null }" ;
247
245
248
246
r = jsmn_parse (& p , js , strlen (js ), tok , 10 );
247
+ #ifdef JSMN_PRIMITIVE_KEYS
249
248
check (r >= 0 );
250
- check (tokeq (js , tok , 5 , JSMN_OBJECT , -1 , -1 , 2 , JSMN_PRIMITIVE , "key1" ,
251
- JSMN_STRING , "value" , 0 , JSMN_PRIMITIVE , "key2" ,
252
- JSMN_PRIMITIVE , "123" ));
249
+ check (tokeq (js , tok , 5 , JSMN_OBJECT , -1 , -1 , 2 , JSMN_PRIMITIVE , "123" ,
250
+ JSMN_STRING , "value" , 0 , JSMN_PRIMITIVE , "456" ,
251
+ JSMN_PRIMITIVE , "null" ));
252
+ #else
253
+ check (r == JSMN_ERROR_INVAL );
253
254
#endif
254
255
return 0 ;
255
256
}
@@ -349,7 +350,7 @@ int test_unenclosed(void) {
349
350
check (parse (js , 1 , 1 , JSMN_PRIMITIVE , "false" ));
350
351
351
352
js = "0garbage" ;
352
- #ifdef JSMN_STRICT
353
+ #ifndef JSMN_PERMISSIVE_PRIMITIVES
353
354
check (parse (js , JSMN_ERROR_INVAL , 1 ));
354
355
#else
355
356
check (parse (js , 1 , 1 , JSMN_PRIMITIVE , "0garbage" ));
@@ -376,7 +377,7 @@ int test_unenclosed(void) {
376
377
js = " 1234 " ;
377
378
check (parse (js , 1 , 1 , JSMN_PRIMITIVE , "1234" ));
378
379
379
- #ifdef JSMN_STRICT
380
+ #ifndef JSMN_PERMISSIVE_PRIMITIVES
380
381
js = "fal" ;
381
382
check (parse (js , JSMN_ERROR_PART , 1 ));
382
383
@@ -441,7 +442,7 @@ int test_object_key(void) {
441
442
js = "{\"key\": 1}" ;
442
443
check (parse (js , 3 , 3 , JSMN_OBJECT , 0 , 10 , 1 , JSMN_STRING , "key" , 1 ,
443
444
JSMN_PRIMITIVE , "1" ));
444
- #ifdef JSMN_STRICT
445
+ #ifndef JSMN_PRIMITIVE_KEYS
445
446
js = "{true: 1}" ;
446
447
check (parse (js , JSMN_ERROR_INVAL , 3 ));
447
448
js = "{1: 1}" ;
@@ -493,7 +494,7 @@ int main(void) {
493
494
test (test_input_length , "test strings that are not null-terminated" );
494
495
test (test_issue_22 , "test issue #22" );
495
496
test (test_count , "test tokens count estimation" );
496
- test (test_unenclosed , "test for non-strict mode" );
497
+ test (test_unenclosed , "test for non-strict mode" );
497
498
test (test_unmatched_brackets , "test for unmatched brackets" );
498
499
test (test_object_key , "test for key type" );
499
500
test (test_multiple_objects , "test parsing multiple items at once" );
0 commit comments