annotate src/json_test.c @ 7967:45ea5ebf3a98 v7.4.1279

commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 7 19:19:53 2016 +0100 patch 7.4.1279 Problem: jsonencode() is not producing strict JSON. Solution: Add jsencode() and jsdecode(). Make jsonencode() and jsondecode() strict.
author Christian Brabandt <cb@256bit.org>
date Sun, 07 Feb 2016 19:30:05 +0100
parents d14cf20b44dc
children 4aead6a9b7a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 *
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 *
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 /*
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 * json_test.c: Unittests for json.c
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 #undef NDEBUG
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 #include <assert.h>
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 /* Must include main.c because it contains much more than just main() */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 #define NO_VIM_MAIN
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 #include "main.c"
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 /* This file has to be included because the tested functions are static */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 #include "json.c"
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
7891
d14cf20b44dc commit https://github.com/vim/vim/commit/8d8c509ac8dea59ad07712971d74afae08521f79
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
24 #if defined(FEAT_EVAL)
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 /*
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 * Test json_find_end() with imcomplete items.
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 static void
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 test_decode_find_end(void)
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 {
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 js_read_T reader;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 reader.js_fill = NULL;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 reader.js_used = 0;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 /* string and incomplete string */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 reader.js_buf = (char_u *)"\"hello\"";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
38 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 reader.js_buf = (char_u *)" \"hello\" ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
40 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 reader.js_buf = (char_u *)"\"hello";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
42 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 /* number and dash (incomplete number) */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 reader.js_buf = (char_u *)"123";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
46 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 reader.js_buf = (char_u *)"-";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
48 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 /* false, true and null, also incomplete */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 reader.js_buf = (char_u *)"false";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
52 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 reader.js_buf = (char_u *)"f";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
54 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 reader.js_buf = (char_u *)"fa";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
56 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 reader.js_buf = (char_u *)"fal";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
58 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 reader.js_buf = (char_u *)"fals";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
60 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 reader.js_buf = (char_u *)"true";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
63 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 reader.js_buf = (char_u *)"t";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
65 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 reader.js_buf = (char_u *)"tr";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
67 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 reader.js_buf = (char_u *)"tru";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
69 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 reader.js_buf = (char_u *)"null";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
72 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 reader.js_buf = (char_u *)"n";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
74 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 reader.js_buf = (char_u *)"nu";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
76 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 reader.js_buf = (char_u *)"nul";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
78 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 /* object without white space */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 reader.js_buf = (char_u *)"{\"a\":123}";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
82 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 reader.js_buf = (char_u *)"{\"a\":123";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
84 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 reader.js_buf = (char_u *)"{\"a\":";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
86 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 reader.js_buf = (char_u *)"{\"a\"";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
88 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 reader.js_buf = (char_u *)"{\"a";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
90 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 reader.js_buf = (char_u *)"{\"";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
92 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 reader.js_buf = (char_u *)"{";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
94 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 /* object with white space */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 reader.js_buf = (char_u *)" { \"a\" : 123 } ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
98 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 reader.js_buf = (char_u *)" { \"a\" : 123 ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
100 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 reader.js_buf = (char_u *)" { \"a\" : ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
102 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 reader.js_buf = (char_u *)" { \"a\" ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
104 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 reader.js_buf = (char_u *)" { \"a ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
106 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 reader.js_buf = (char_u *)" { ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
108 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 /* array without white space */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 reader.js_buf = (char_u *)"[\"a\",123]";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
112 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 reader.js_buf = (char_u *)"[\"a\",123";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
114 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 reader.js_buf = (char_u *)"[\"a\",";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
116 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 reader.js_buf = (char_u *)"[\"a\"";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
118 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 reader.js_buf = (char_u *)"[\"a";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
120 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121 reader.js_buf = (char_u *)"[\"";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
122 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 reader.js_buf = (char_u *)"[";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
124 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 /* array with white space */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 reader.js_buf = (char_u *)" [ \"a\" , 123 ] ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
128 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129 reader.js_buf = (char_u *)" [ \"a\" , 123 ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
130 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 reader.js_buf = (char_u *)" [ \"a\" , ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
132 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 reader.js_buf = (char_u *)" [ \"a\" ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
134 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 reader.js_buf = (char_u *)" [ \"a ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
136 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 reader.js_buf = (char_u *)" [ ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
138 assert(json_find_end(&reader, 0) == MAYBE);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 }
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141 static int
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 fill_from_cookie(js_read_T *reader)
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143 {
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 reader->js_buf = reader->js_cookie;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 return TRUE;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146 }
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 /*
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 * Test json_find_end with an incomplete array, calling the fill function.
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 static void
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152 test_fill_called_on_find_end(void)
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
153 {
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 js_read_T reader;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 reader.js_fill = fill_from_cookie;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 reader.js_used = 0;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 reader.js_buf = (char_u *)" [ \"a\" , 123 ";
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 reader.js_cookie = " [ \"a\" , 123 ] ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
160 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161 reader.js_buf = (char_u *)" [ \"a\" , ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
162 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 reader.js_buf = (char_u *)" [ \"a\" ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
164 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 reader.js_buf = (char_u *)" [ \"a";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
166 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 reader.js_buf = (char_u *)" [ ";
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7891
diff changeset
168 assert(json_find_end(&reader, 0) == OK);
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 }
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171 /*
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172 * Test json_find_end with an incomplete string, calling the fill function.
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173 */
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174 static void
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175 test_fill_called_on_string(void)
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
176 {
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
177 js_read_T reader;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
178
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
179 reader.js_fill = fill_from_cookie;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180 reader.js_used = 0;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
181 reader.js_buf = (char_u *)" \"foo";
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182 reader.js_end = reader.js_buf + STRLEN(reader.js_buf);
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
183 reader.js_cookie = " \"foobar\" ";
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
184 assert(json_decode_string(&reader, NULL) == OK);
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
185 }
7891
d14cf20b44dc commit https://github.com/vim/vim/commit/8d8c509ac8dea59ad07712971d74afae08521f79
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
186 #endif
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
187
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
188 int
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
189 main(void)
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
190 {
7891
d14cf20b44dc commit https://github.com/vim/vim/commit/8d8c509ac8dea59ad07712971d74afae08521f79
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
191 #if defined(FEAT_EVAL)
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
192 test_decode_find_end();
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
193 test_fill_called_on_find_end();
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
194 test_fill_called_on_string();
7891
d14cf20b44dc commit https://github.com/vim/vim/commit/8d8c509ac8dea59ad07712971d74afae08521f79
Christian Brabandt <cb@256bit.org>
parents: 7883
diff changeset
195 #endif
7883
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
196 return 0;
98a96e0ca73b commit https://github.com/vim/vim/commit/56ead341a75e1a0395eee94a3280c67e2278a57e
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
197 }