1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 static int test_passed = 0;
6 static int test_failed = 0;
7
8 /* Terminate current test with error */
9 #define fail() return __LINE__
10
11 /* Successfull end of the test case */
12 #define done() return 0
13
14 /* Check single condition */
15 #define check(cond) do { if (!(cond)) fail(); } while (0)
16
17 /* Test runner */
test(int (* func)(void),const char * name)18 static void test(int (*func)(void), const char *name) {
19 int r = func();
20 if (r == 0) {
21 test_passed++;
22 } else {
23 test_failed++;
24 printf("FAILED: %s (at line %d)\n", name, r);
25 }
26 }
27
28 #define TOKEN_EQ(t, tok_start, tok_end, tok_type) \
29 ((t).start == tok_start \
30 && (t).end == tok_end \
31 && (t).type == (tok_type))
32
33 #define TOKEN_STRING(js, t, s) \
34 (strncmp(js+(t).start, s, (t).end - (t).start) == 0 \
35 && strlen(s) == (t).end - (t).start)
36
37 #define TOKEN_PRINT(t) \
38 printf("start: %d, end: %d, type: %d, size: %d\n", \
39 (t).start, (t).end, (t).type, (t).size)
40
41 #define JSMN_STRICT
42 #include "jsmn.c"
43
test_empty()44 int test_empty() {
45 const char *js;
46 int r;
47 jsmn_parser p;
48 jsmntok_t t[10];
49
50 js = "{}";
51 jsmn_init(&p);
52 r = jsmn_parse(&p, js, strlen(js), t, 10);
53 check(r >= 0);
54 check(t[0].type == JSMN_OBJECT);
55 check(t[0].start == 0 && t[0].end == 2);
56
57 js = "[]";
58 jsmn_init(&p);
59 r = jsmn_parse(&p, js, strlen(js), t, 10);
60 check(r >= 0);
61 check(t[0].type == JSMN_ARRAY);
62 check(t[0].start == 0 && t[0].end == 2);
63
64 js = "{\"a\":[]}";
65 jsmn_init(&p);
66 r = jsmn_parse(&p, js, strlen(js), t, 10);
67 check(r >= 0);
68 check(t[0].type == JSMN_OBJECT && t[0].start == 0 && t[0].end == 8);
69 check(t[1].type == JSMN_STRING && t[1].start == 2 && t[1].end == 3);
70 check(t[2].type == JSMN_ARRAY && t[2].start == 5 && t[2].end == 7);
71
72 js = "[{},{}]";
73 jsmn_init(&p);
74 r = jsmn_parse(&p, js, strlen(js), t, 10);
75 check(r >= 0);
76 check(t[0].type == JSMN_ARRAY && t[0].start == 0 && t[0].end == 7);
77 check(t[1].type == JSMN_OBJECT && t[1].start == 1 && t[1].end == 3);
78 check(t[2].type == JSMN_OBJECT && t[2].start == 4 && t[2].end == 6);
79 return 0;
80 }
81
test_simple()82 int test_simple() {
83 const char *js;
84 int r;
85 jsmn_parser p;
86 jsmntok_t tokens[10];
87
88 js = "{\"a\": 0}";
89
90 jsmn_init(&p);
91 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
92 check(r >= 0);
93 check(TOKEN_EQ(tokens[0], 0, 8, JSMN_OBJECT));
94 check(TOKEN_EQ(tokens[1], 2, 3, JSMN_STRING));
95 check(TOKEN_EQ(tokens[2], 6, 7, JSMN_PRIMITIVE));
96
97 check(TOKEN_STRING(js, tokens[0], js));
98 check(TOKEN_STRING(js, tokens[1], "a"));
99 check(TOKEN_STRING(js, tokens[2], "0"));
100
101 jsmn_init(&p);
102 js = "[\"a\":{},\"b\":{}]";
103 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
104 check(r >= 0);
105
106 jsmn_init(&p);
107 js = "{\n \"Day\": 26,\n \"Month\": 9,\n \"Year\": 12\n }";
108 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
109 check(r >= 0);
110
111 return 0;
112 }
113
test_primitive()114 int test_primitive() {
115 #ifndef JSMN_STRICT
116 int r;
117 jsmn_parser p;
118 jsmntok_t tok[10];
119 const char *js;
120 js = "\"boolVar\" : true";
121 jsmn_init(&p);
122 r = jsmn_parse(&p, js, strlen(js), tok, 10);
123 check(r >= 0 && tok[0].type == JSMN_STRING
124 && tok[1].type == JSMN_PRIMITIVE);
125 check(TOKEN_STRING(js, tok[0], "boolVar"));
126 check(TOKEN_STRING(js, tok[1], "true"));
127
128 js = "\"boolVar\" : false";
129 jsmn_init(&p);
130 r = jsmn_parse(&p, js, strlen(js), tok, 10);
131 check(r >= 0 && tok[0].type == JSMN_STRING
132 && tok[1].type == JSMN_PRIMITIVE);
133 check(TOKEN_STRING(js, tok[0], "boolVar"));
134 check(TOKEN_STRING(js, tok[1], "false"));
135
136 js = "\"intVar\" : 12345";
137 jsmn_init(&p);
138 r = jsmn_parse(&p, js, strlen(js), tok, 10);
139 check(r >= 0 && tok[0].type == JSMN_STRING
140 && tok[1].type == JSMN_PRIMITIVE);
141 check(TOKEN_STRING(js, tok[0], "intVar"));
142 check(TOKEN_STRING(js, tok[1], "12345"));
143
144 js = "\"floatVar\" : 12.345";
145 jsmn_init(&p);
146 r = jsmn_parse(&p, js, strlen(js), tok, 10);
147 check(r >= 0 && tok[0].type == JSMN_STRING
148 && tok[1].type == JSMN_PRIMITIVE);
149 check(TOKEN_STRING(js, tok[0], "floatVar"));
150 check(TOKEN_STRING(js, tok[1], "12.345"));
151
152 js = "\"nullVar\" : null";
153 jsmn_init(&p);
154 r = jsmn_parse(&p, js, strlen(js), tok, 10);
155 check(r >= 0 && tok[0].type == JSMN_STRING
156 && tok[1].type == JSMN_PRIMITIVE);
157 check(TOKEN_STRING(js, tok[0], "nullVar"));
158 check(TOKEN_STRING(js, tok[1], "null"));
159 #endif
160 return 0;
161 }
162
test_string()163 int test_string() {
164 int r;
165 jsmn_parser p;
166 jsmntok_t tok[10];
167 const char *js;
168
169 js = "\"strVar\" : \"hello world\"";
170 jsmn_init(&p);
171 r = jsmn_parse(&p, js, strlen(js), tok, 10);
172 check(r >= 0 && tok[0].type == JSMN_STRING
173 && tok[1].type == JSMN_STRING);
174 check(TOKEN_STRING(js, tok[0], "strVar"));
175 check(TOKEN_STRING(js, tok[1], "hello world"));
176
177 js = "\"strVar\" : \"escapes: \\/\\r\\n\\t\\b\\f\\\"\\\\\"";
178 jsmn_init(&p);
179 r = jsmn_parse(&p, js, strlen(js), tok, 10);
180 check(r >= 0 && tok[0].type == JSMN_STRING
181 && tok[1].type == JSMN_STRING);
182 check(TOKEN_STRING(js, tok[0], "strVar"));
183 check(TOKEN_STRING(js, tok[1], "escapes: \\/\\r\\n\\t\\b\\f\\\"\\\\"));
184
185 js = "\"strVar\" : \"\"";
186 jsmn_init(&p);
187 r = jsmn_parse(&p, js, strlen(js), tok, 10);
188 check(r >= 0 && tok[0].type == JSMN_STRING
189 && tok[1].type == JSMN_STRING);
190 check(TOKEN_STRING(js, tok[0], "strVar"));
191 check(TOKEN_STRING(js, tok[1], ""));
192
193 return 0;
194 }
195
test_partial_string()196 int test_partial_string() {
197 int r;
198 jsmn_parser p;
199 jsmntok_t tok[10];
200 const char *js;
201
202 jsmn_init(&p);
203 js = "\"x\": \"va";
204 r = jsmn_parse(&p, js, strlen(js), tok, 10);
205 check(r == JSMN_ERROR_PART && tok[0].type == JSMN_STRING);
206 check(TOKEN_STRING(js, tok[0], "x"));
207 check(p.toknext == 1);
208
209 jsmn_init(&p);
210 char js_slash[9] = "\"x\": \"va\\";
211 r = jsmn_parse(&p, js_slash, sizeof(js_slash), tok, 10);
212 check(r == JSMN_ERROR_PART);
213
214 jsmn_init(&p);
215 char js_unicode[10] = "\"x\": \"va\\u";
216 r = jsmn_parse(&p, js_unicode, sizeof(js_unicode), tok, 10);
217 check(r == JSMN_ERROR_PART);
218
219 js = "\"x\": \"valu";
220 r = jsmn_parse(&p, js, strlen(js), tok, 10);
221 check(r == JSMN_ERROR_PART && tok[0].type == JSMN_STRING);
222 check(TOKEN_STRING(js, tok[0], "x"));
223 check(p.toknext == 1);
224
225 js = "\"x\": \"value\"";
226 r = jsmn_parse(&p, js, strlen(js), tok, 10);
227 check(r >= 0 && tok[0].type == JSMN_STRING
228 && tok[1].type == JSMN_STRING);
229 check(TOKEN_STRING(js, tok[0], "x"));
230 check(TOKEN_STRING(js, tok[1], "value"));
231
232 js = "\"x\": \"value\", \"y\": \"value y\"";
233 r = jsmn_parse(&p, js, strlen(js), tok, 10);
234 check(r >= 0 && tok[0].type == JSMN_STRING
235 && tok[1].type == JSMN_STRING && tok[2].type == JSMN_STRING
236 && tok[3].type == JSMN_STRING);
237 check(TOKEN_STRING(js, tok[0], "x"));
238 check(TOKEN_STRING(js, tok[1], "value"));
239 check(TOKEN_STRING(js, tok[2], "y"));
240 check(TOKEN_STRING(js, tok[3], "value y"));
241
242 return 0;
243 }
244
test_unquoted_keys()245 int test_unquoted_keys() {
246 #ifndef JSMN_STRICT
247 int r;
248 jsmn_parser p;
249 jsmntok_t tok[10];
250 const char *js;
251
252 jsmn_init(&p);
253 js = "key1: \"value\"\nkey2 : 123";
254
255 r = jsmn_parse(&p, js, strlen(js), tok, 10);
256 check(r >= 0 && tok[0].type == JSMN_PRIMITIVE
257 && tok[1].type == JSMN_STRING && tok[2].type == JSMN_PRIMITIVE
258 && tok[3].type == JSMN_PRIMITIVE);
259 check(TOKEN_STRING(js, tok[0], "key1"));
260 check(TOKEN_STRING(js, tok[1], "value"));
261 check(TOKEN_STRING(js, tok[2], "key2"));
262 check(TOKEN_STRING(js, tok[3], "123"));
263 #endif
264 return 0;
265 }
266
test_partial_array()267 int test_partial_array() {
268 int r;
269 jsmn_parser p;
270 jsmntok_t tok[10];
271 const char *js;
272
273 jsmn_init(&p);
274 js = " [ 1, true, ";
275 r = jsmn_parse(&p, js, strlen(js), tok, 10);
276 check(r == JSMN_ERROR_PART && tok[0].type == JSMN_ARRAY
277 && tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE);
278
279 js = " [ 1, true, [123, \"hello";
280 r = jsmn_parse(&p, js, strlen(js), tok, 10);
281 check(r == JSMN_ERROR_PART && tok[0].type == JSMN_ARRAY
282 && tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE
283 && tok[3].type == JSMN_ARRAY && tok[4].type == JSMN_PRIMITIVE);
284
285 js = " [ 1, true, [123, \"hello\"]";
286 r = jsmn_parse(&p, js, strlen(js), tok, 10);
287 check(r == JSMN_ERROR_PART && tok[0].type == JSMN_ARRAY
288 && tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE
289 && tok[3].type == JSMN_ARRAY && tok[4].type == JSMN_PRIMITIVE
290 && tok[5].type == JSMN_STRING);
291 /* check child nodes of the 2nd array */
292 check(tok[3].size == 2);
293
294 js = " [ 1, true, [123, \"hello\"]]";
295 r = jsmn_parse(&p, js, strlen(js), tok, 10);
296 check(r >= 0 && tok[0].type == JSMN_ARRAY
297 && tok[1].type == JSMN_PRIMITIVE && tok[2].type == JSMN_PRIMITIVE
298 && tok[3].type == JSMN_ARRAY && tok[4].type == JSMN_PRIMITIVE
299 && tok[5].type == JSMN_STRING);
300 check(tok[3].size == 2);
301 check(tok[0].size == 3);
302 return 0;
303 }
304
test_array_nomem()305 int test_array_nomem() {
306 int i;
307 int r;
308 jsmn_parser p;
309 jsmntok_t toksmall[10], toklarge[10];
310 const char *js;
311
312 js = " [ 1, true, [123, \"hello\"]]";
313
314 for (i = 0; i < 6; i++) {
315 jsmn_init(&p);
316 memset(toksmall, 0, sizeof(toksmall));
317 memset(toklarge, 0, sizeof(toklarge));
318 r = jsmn_parse(&p, js, strlen(js), toksmall, i);
319 check(r == JSMN_ERROR_NOMEM);
320
321 memcpy(toklarge, toksmall, sizeof(toksmall));
322
323 r = jsmn_parse(&p, js, strlen(js), toklarge, 10);
324 check(r >= 0);
325
326 check(toklarge[0].type == JSMN_ARRAY && toklarge[0].size == 3);
327 check(toklarge[3].type == JSMN_ARRAY && toklarge[3].size == 2);
328 }
329 return 0;
330 }
331
test_objects_arrays()332 int test_objects_arrays() {
333 int r;
334 jsmn_parser p;
335 jsmntok_t tokens[10];
336 const char *js;
337
338 js = "[10}";
339 jsmn_init(&p);
340 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
341 check(r == JSMN_ERROR_INVAL);
342
343 js = "[10]";
344 jsmn_init(&p);
345 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
346 check(r >= 0);
347
348 js = "{\"a\": 1]";
349 jsmn_init(&p);
350 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
351 check(r == JSMN_ERROR_INVAL);
352
353 js = "{\"a\": 1}";
354 jsmn_init(&p);
355 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
356 check(r >= 0);
357
358 return 0;
359 }
360
test_issue_22()361 int test_issue_22() {
362 int r;
363 jsmn_parser p;
364 jsmntok_t tokens[128];
365 const char *js;
366
367 js = "{ \"height\":10, \"layers\":[ { \"data\":[6,6], \"height\":10, "
368 "\"name\":\"Calque de Tile 1\", \"opacity\":1, \"type\":\"tilelayer\", "
369 "\"visible\":true, \"width\":10, \"x\":0, \"y\":0 }], "
370 "\"orientation\":\"orthogonal\", \"properties\": { }, \"tileheight\":32, "
371 "\"tilesets\":[ { \"firstgid\":1, \"image\":\"..\\/images\\/tiles.png\", "
372 "\"imageheight\":64, \"imagewidth\":160, \"margin\":0, \"name\":\"Tiles\", "
373 "\"properties\":{}, \"spacing\":0, \"tileheight\":32, \"tilewidth\":32 }], "
374 "\"tilewidth\":32, \"version\":1, \"width\":10 }";
375 jsmn_init(&p);
376 r = jsmn_parse(&p, js, strlen(js), tokens, 128);
377 check(r >= 0);
378 #if 0
379 for (i = 1; tokens[i].end < tokens[0].end; i++) {
380 if (tokens[i].type == JSMN_STRING || tokens[i].type == JSMN_PRIMITIVE) {
381 printf("%.*s\n", tokens[i].end - tokens[i].start, js + tokens[i].start);
382 } else if (tokens[i].type == JSMN_ARRAY) {
383 printf("[%d elems]\n", tokens[i].size);
384 } else if (tokens[i].type == JSMN_OBJECT) {
385 printf("{%d elems}\n", tokens[i].size);
386 } else {
387 TOKEN_PRINT(tokens[i]);
388 }
389 }
390 #endif
391 return 0;
392 }
393
test_unicode_characters()394 int test_unicode_characters() {
395 jsmn_parser p;
396 jsmntok_t tokens[10];
397 const char *js;
398
399 int r;
400 js = "{\"a\":\"\\uAbcD\"}";
401 jsmn_init(&p);
402 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
403 check(r >= 0);
404
405 js = "{\"a\":\"str\\u0000\"}";
406 jsmn_init(&p);
407 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
408 check(r >= 0);
409
410 js = "{\"a\":\"\\uFFFFstr\"}";
411 jsmn_init(&p);
412 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
413 check(r >= 0);
414
415 js = "{\"a\":\"str\\uFFGFstr\"}";
416 jsmn_init(&p);
417 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
418 check(r == JSMN_ERROR_INVAL);
419
420 js = "{\"a\":\"str\\u@FfF\"}";
421 jsmn_init(&p);
422 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
423 check(r == JSMN_ERROR_INVAL);
424
425 js = "{\"a\":[\"\\u028\"]}";
426 jsmn_init(&p);
427 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
428 check(r == JSMN_ERROR_INVAL);
429
430 js = "{\"a\":[\"\\u0280\"]}";
431 jsmn_init(&p);
432 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
433 check(r >= 0);
434
435 return 0;
436 }
437
test_input_length()438 int test_input_length() {
439 const char *js;
440 int r;
441 jsmn_parser p;
442 jsmntok_t tokens[10];
443
444 js = "{\"a\": 0}garbage";
445
446 jsmn_init(&p);
447 r = jsmn_parse(&p, js, 8, tokens, 10);
448 check(r == 3);
449 check(TOKEN_STRING(js, tokens[0], "{\"a\": 0}"));
450 check(TOKEN_STRING(js, tokens[1], "a"));
451 check(TOKEN_STRING(js, tokens[2], "0"));
452
453 return 0;
454 }
455
test_count()456 int test_count() {
457 jsmn_parser p;
458 const char *js;
459
460 js = "{}";
461 jsmn_init(&p);
462 check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 1);
463
464 js = "[]";
465 jsmn_init(&p);
466 check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 1);
467
468 js = "[[]]";
469 jsmn_init(&p);
470 check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 2);
471
472 js = "[[], []]";
473 jsmn_init(&p);
474 check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 3);
475
476 js = "[[], []]";
477 jsmn_init(&p);
478 check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 3);
479
480 js = "[[], [[]], [[], []]]";
481 jsmn_init(&p);
482 check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 7);
483
484 js = "[\"a\", [[], []]]";
485 jsmn_init(&p);
486 check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 5);
487
488 js = "[[], \"[], [[]]\", [[]]]";
489 jsmn_init(&p);
490 check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 5);
491
492 js = "[1, 2, 3]";
493 jsmn_init(&p);
494 check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 4);
495
496 js = "[1, 2, [3, \"a\"], null]";
497 jsmn_init(&p);
498 check(jsmn_parse(&p, js, strlen(js), NULL, 0) == 7);
499
500 return 0;
501 }
502
test_keyvalue()503 int test_keyvalue() {
504 const char *js;
505 int r;
506 jsmn_parser p;
507 jsmntok_t tokens[10];
508
509 js = "{\"a\": 0, \"b\": \"c\"}";
510
511 jsmn_init(&p);
512 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
513 check(r == 5);
514 check(tokens[0].size == 2); /* two keys */
515 check(tokens[1].size == 1 && tokens[3].size == 1); /* one value per key */
516 check(tokens[2].size == 0 && tokens[4].size == 0); /* values have zero size */
517
518 js = "{\"a\"\n0}";
519 jsmn_init(&p);
520 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
521 check(r == JSMN_ERROR_INVAL);
522
523 js = "{\"a\", 0}";
524 jsmn_init(&p);
525 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
526 check(r == JSMN_ERROR_INVAL);
527
528 js = "{\"a\": {2}}";
529 jsmn_init(&p);
530 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
531 check(r == JSMN_ERROR_INVAL);
532
533 js = "{\"a\": {2: 3}}";
534 jsmn_init(&p);
535 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
536 check(r == JSMN_ERROR_INVAL);
537
538
539 js = "{\"a\": {\"a\": 2 3}}";
540 jsmn_init(&p);
541 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
542 check(r == JSMN_ERROR_INVAL);
543 return 0;
544 }
545
546 /** A huge redefinition of everything to include jsmn in non-script mode */
547 #define jsmn_init jsmn_init_nonstrict
548 #define jsmn_parse jsmn_parse_nonstrict
549 #define jsmn_parser jsmn_parser_nonstrict
550 #define jsmn_alloc_token jsmn_alloc_token_nonstrict
551 #define jsmn_fill_token jsmn_fill_token_nonstrict
552 #define jsmn_parse_primitive jsmn_parse_primitive_nonstrict
553 #define jsmn_parse_string jsmn_parse_string_nonstrict
554 #define jsmntype_t jsmntype_nonstrict_t
555 #define jsmnerr_t jsmnerr_nonstrict_t
556 #define jsmntok_t jsmntok_nonstrict_t
557 #define JSMN_PRIMITIVE JSMN_PRIMITIVE_NONSTRICT
558 #define JSMN_OBJECT JSMN_OBJECT_NONSTRICT
559 #define JSMN_ARRAY JSMN_ARRAY_NONSTRICT
560 #define JSMN_STRING JSMN_STRING_NONSTRICT
561 #define JSMN_ERROR_NOMEM JSMN_ERROR_NOMEM_NONSTRICT
562 #define JSMN_ERROR_INVAL JSMN_ERROR_INVAL_NONSTRICT
563 #define JSMN_ERROR_PART JSMN_ERROR_PART_NONSTRICT
564 #undef __JSMN_H_
565 #undef JSMN_STRICT
566 #include "jsmn.c"
567
test_nonstrict()568 int test_nonstrict() {
569 const char *js;
570 int r;
571 jsmn_parser p;
572 jsmntok_t tokens[10];
573
574 js = "a: 0garbage";
575
576 jsmn_init(&p);
577 r = jsmn_parse(&p, js, 4, tokens, 10);
578 check(r == 2);
579 check(TOKEN_STRING(js, tokens[0], "a"));
580 check(TOKEN_STRING(js, tokens[1], "0"));
581
582 js = "Day : 26\nMonth : Sep\n\nYear: 12";
583 jsmn_init(&p);
584 r = jsmn_parse(&p, js, strlen(js), tokens, 10);
585 check(r == 6);
586 return 0;
587 }
588
main()589 int main() {
590 test(test_empty, "general test for a empty JSON objects/arrays");
591 test(test_simple, "general test for a simple JSON string");
592 test(test_primitive, "test primitive JSON data types");
593 test(test_string, "test string JSON data types");
594 test(test_partial_string, "test partial JSON string parsing");
595 test(test_partial_array, "test partial array reading");
596 test(test_array_nomem, "test array reading with a smaller number of tokens");
597 test(test_unquoted_keys, "test unquoted keys (like in JavaScript)");
598 test(test_objects_arrays, "test objects and arrays");
599 test(test_unicode_characters, "test unicode characters");
600 test(test_input_length, "test strings that are not null-terminated");
601 test(test_issue_22, "test issue #22");
602 test(test_count, "test tokens count estimation");
603 test(test_nonstrict, "test for non-strict mode");
604 test(test_keyvalue, "test for keys/values");
605 printf("\nPASSED: %d\nFAILED: %d\n", test_passed, test_failed);
606 return 0;
607 }
608
609