Skip to content

Commit ee19c93

Browse files
Update tests for new feature macros
1 parent de2b56a commit ee19c93

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

Makefile

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
# You can put your build options here
22
-include config.mk
33

4-
test: test_default test_strict test_links test_strict_links
4+
test: test_default test_nonstrict test_lowmem test_nonstrict_lowmem test_permissiveprims test_permissivestrs test_primkeys
55
test_default: test/tests.c jsmn.h
66
$(CC) $(CFLAGS) $(LDFLAGS) $< -o test/$@
77
./test/$@
8-
test_strict: test/tests.c jsmn.h
9-
$(CC) -DJSMN_STRICT=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@
8+
test_nonstrict: test/tests.c jsmn.h
9+
$(CC) -DJSMN_NON_STRICT=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@
1010
./test/$@
11-
test_links: test/tests.c jsmn.h
12-
$(CC) -DJSMN_PARENT_LINKS=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@
11+
test_lowmem: test/tests.c jsmn.h
12+
$(CC) -DJSMN_LOW_MEMORY=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@
1313
./test/$@
14-
test_strict_links: test/tests.c jsmn.h
15-
$(CC) -DJSMN_STRICT=1 -DJSMN_PARENT_LINKS=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@
14+
test_nonstrict_lowmem: test/tests.c jsmn.h
15+
$(CC) -DJSMN_NON_STRICT=1 -DJSMN_LOW_MEMORY=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@
16+
./test/$@
17+
test_permissiveprims: test/tests.c jsmn.h
18+
$(CC) -DJSMN_PERMISSIVE_PRIMITIVES=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@
19+
./test/$@
20+
test_permissivestrs: test/tests.c jsmn.h
21+
$(CC) -DJSMN_PERMISSIVE_STRINGS=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@
22+
./test/$@
23+
test_primkeys: test/tests.c jsmn.h
24+
$(CC) -DJSMN_PRIMITIVE_KEYS=1 $(CFLAGS) $(LDFLAGS) $< -o test/$@
1625
./test/$@
1726

1827
simple_example: example/simple.c jsmn.h
@@ -31,7 +40,7 @@ clean:
3140
rm -f *.o example/*.o
3241
rm -f simple_example
3342
rm -f jsondump
34-
rm -f test/test_default test/test_strict test/test_links test/test_strict_links
43+
rm -f test/test_default test/test_nonstrict test/test_lowmem test/test_nonstrict_lowmem test/test_permissiveprims test/test_permissivestrs test/test_primkeys
3544

3645
.PHONY: clean test
3746

jsmn.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ extern "C" {
4444
#endif
4545

4646
#ifdef JSMN_NON_STRICT
47-
#ifndef
47+
#ifndef JSMN_PERMISSIVE_PRIMITIVES
4848
#define JSMN_PERMISSIVE_PRIMITIVES
4949
#endif
50-
#ifndef
50+
#ifndef JSMN_PERMISSIVE_STRINGS
5151
#define JSMN_PERMISSIVE_STRINGS
5252
#endif
53-
#ifndef
53+
#ifndef JSMN_PRIMITIVE_KEYS
5454
#define JSMN_PRIMITIVE_KEYS
5555
#endif
5656
#endif

test/tests.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ int test_object(void) {
3030
JSMN_STRING, "a", 1, JSMN_PRIMITIVE, "0", JSMN_STRING, "b", 1,
3131
JSMN_STRING, "c", 0));
3232

33-
#ifdef JSMN_STRICT
33+
#ifndef JSMN_NON_STRICT
3434
check(parse("{\"a\"\n0}", JSMN_ERROR_INVAL, 3));
3535
check(parse("{\"a\", 0}", JSMN_ERROR_INVAL, 3));
3636
check(parse("{\"a\": {2}}", JSMN_ERROR_INVAL, 4));
37-
check(parse("{\"a\": {2: 3}}", JSMN_ERROR_INVAL, 5));
3837
check(parse("{\"a\": {\"a\": 2 3}}", JSMN_ERROR_INVAL, 6));
3938
check(parse("{\"a\"}", JSMN_ERROR_INVAL, 2));
4039
check(parse("{\"a\": 1, \"b\"}", JSMN_ERROR_INVAL, 4));
@@ -88,7 +87,7 @@ int test_primitive(void) {
8887
check(parse("{\"floatVar\" : 12e+6}", 3, 3, JSMN_OBJECT, -1, -1, 1,
8988
JSMN_STRING, "floatVar", 1, JSMN_PRIMITIVE, "12e+6"));
9089

91-
#ifdef JSMN_STRICT
90+
#ifndef JSMN_PERMISSIVE_PRIMITIVES
9291
check(parse("{\"boolVar\" : tru }", JSMN_ERROR_INVAL, 3));
9392
check(parse("{\"boolVar\" : falsee }", JSMN_ERROR_INVAL, 3));
9493
check(parse("{\"nullVar\" : nulm }", JSMN_ERROR_INVAL, 3));
@@ -145,7 +144,7 @@ int test_string(void) {
145144
check(parse("{\"a\":\"str\xc2\xa9\"}", 3, 3, JSMN_OBJECT, -1, -1, 1,
146145
JSMN_STRING, "a", 1, JSMN_STRING, "str\xc2\xa9", 0));
147146

148-
#ifdef JSMN_STRICT
147+
#ifndef JSMN_PERMISSIVE_STRINGS
149148
check(parse("{\"a\":\"str\nstr\"}", JSMN_ERROR_INVAL, 3));
150149
check(parse("{\"a\":\"str\\uFFGFstr\"}", JSMN_ERROR_INVAL, 3));
151150
check(parse("{\"a\":\"str\\u@FfF\"}", JSMN_ERROR_INVAL, 3));
@@ -236,20 +235,22 @@ int test_array_nomem(void) {
236235
}
237236

238237
int test_unquoted_keys(void) {
239-
#ifndef JSMN_STRICT
240238
int r;
241239
jsmn_parser p;
242240
jsmntok_t tok[10];
243241
const char *js;
244242

245243
jsmn_init(&p);
246-
js = "{key1: \"value\", key2 : 123}";
244+
js = "{123: \"value\", 456 : null}";
247245

248246
r = jsmn_parse(&p, js, strlen(js), tok, 10);
247+
#ifdef JSMN_PRIMITIVE_KEYS
249248
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);
253254
#endif
254255
return 0;
255256
}
@@ -349,7 +350,7 @@ int test_unenclosed(void) {
349350
check(parse(js, 1, 1, JSMN_PRIMITIVE, "false"));
350351

351352
js = "0garbage";
352-
#ifdef JSMN_STRICT
353+
#ifndef JSMN_PERMISSIVE_PRIMITIVES
353354
check(parse(js, JSMN_ERROR_INVAL, 1));
354355
#else
355356
check(parse(js, 1, 1, JSMN_PRIMITIVE, "0garbage"));
@@ -376,7 +377,7 @@ int test_unenclosed(void) {
376377
js = " 1234 ";
377378
check(parse(js, 1, 1, JSMN_PRIMITIVE, "1234"));
378379

379-
#ifdef JSMN_STRICT
380+
#ifndef JSMN_PERMISSIVE_PRIMITIVES
380381
js = "fal";
381382
check(parse(js, JSMN_ERROR_PART, 1));
382383

@@ -441,7 +442,7 @@ int test_object_key(void) {
441442
js = "{\"key\": 1}";
442443
check(parse(js, 3, 3, JSMN_OBJECT, 0, 10, 1, JSMN_STRING, "key", 1,
443444
JSMN_PRIMITIVE, "1"));
444-
#ifdef JSMN_STRICT
445+
#ifndef JSMN_PRIMITIVE_KEYS
445446
js = "{true: 1}";
446447
check(parse(js, JSMN_ERROR_INVAL, 3));
447448
js = "{1: 1}";
@@ -493,7 +494,7 @@ int main(void) {
493494
test(test_input_length, "test strings that are not null-terminated");
494495
test(test_issue_22, "test issue #22");
495496
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");
497498
test(test_unmatched_brackets, "test for unmatched brackets");
498499
test(test_object_key, "test for key type");
499500
test(test_multiple_objects, "test parsing multiple items at once");

0 commit comments

Comments
 (0)