summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorzlolik <lolikandr@gmail.com>2016-10-02 07:51:52 +0300
committerzlolik <lolikandr@gmail.com>2016-10-02 07:51:52 +0300
commita01d301373595892e2e5ff77dd4e7715f7897f11 (patch)
treedc18a88a3515e5fc469da7e76a1b0467a6160711 /test
parent4ce44040579e65755d14a3d7dabdae0913959a24 (diff)
some tests for unmatched brackets added
Diffstat (limited to 'test')
-rw-r--r--test/tests.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/tests.c b/test/tests.c
index a72689ec0..424703522 100644
--- a/test/tests.c
+++ b/test/tests.c
@@ -357,6 +357,27 @@ int test_nonstrict(void) {
return 0;
}
+int test_unmatched_brackets(void) {
+ const char *js;
+ js = "\"key 1\": 1234}";
+ check(parse(js, JSMN_ERROR_INVAL, 2));
+ js = "{\"key 1\": 1234";
+ check(parse(js, JSMN_ERROR_PART, 3));
+ js = "{\"key 1\": 1234}}";
+ check(parse(js, JSMN_ERROR_INVAL, 3));
+ js = "\"key 1\"}: 1234";
+ check(parse(js, JSMN_ERROR_INVAL, 3));
+ js = "\"key {1\": 1234";
+ check(parse(js, 2, 2,
+ JSMN_PRIMITIVE, "\"key {1\"",
+ JSMN_PRIMITIVE, "1234"));
+ js = "\"key 1\": {1234}";
+ check(parse(js, JSMN_ERROR_INVAL, 3));
+ js = "{\"key 1\"}: 1234";
+ check(parse(js, JSMN_ERROR_INVAL, 3));
+ return 0;
+}
+
int main(void) {
test(test_empty, "test for a empty JSON objects/arrays");
test(test_object, "test for a JSON objects");
@@ -373,6 +394,7 @@ int main(void) {
test(test_issue_27, "test issue #27");
test(test_count, "test tokens count estimation");
test(test_nonstrict, "test for non-strict mode");
+ test(test_unmatched_brackets, "test for unmatched brackets");
printf("\nPASSED: %d\nFAILED: %d\n", test_passed, test_failed);
return (test_failed > 0);
}