annotate src/testdir/test_json.vim @ 24680:0072259ad95a

Added tag v8.2.2878 for changeset 80422f66978abad7721d5055d63015920b67c009
author Bram Moolenaar <Bram@vim.org>
date Sat, 22 May 2021 21:45:03 +0200
parents 650070143c56
children 0860b12c5788
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for JSON functions.
8312
1001ec135d6e commit https://github.com/vim/vim/commit/c5215e943bf5a045089693b60b8805a794d8c2f6
Christian Brabandt <cb@256bit.org>
parents: 8283
diff changeset
2
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 let s:json1 = '"str\"in\\g"'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 let s:var1 = "str\"in\\g"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 let s:json2 = '"\u0001\u0002\u0003\u0004\u0005\u0006\u0007"'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 let s:var2 = "\x01\x02\x03\x04\x05\x06\x07"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 let s:json3 = '"\b\t\n\u000b\f\r\u000e\u000f"'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 let s:var3 = "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 let s:json4 = '"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017"'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 let s:var4 = "\x10\x11\x12\x13\x14\x15\x16\x17"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 let s:json5 = '"\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f"'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 let s:var5 = "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
8283
b8a56d4d83e0 commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents: 8275
diff changeset
14 " surrogate pair
b8a56d4d83e0 commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents: 8275
diff changeset
15 let s:jsonsp1 = '"\ud83c\udf63"'
b8a56d4d83e0 commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents: 8275
diff changeset
16 let s:varsp1 = "\xf0\x9f\x8d\xa3"
b8a56d4d83e0 commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents: 8275
diff changeset
17 let s:jsonsp2 = '"\ud83c\u00a0"'
b8a56d4d83e0 commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents: 8275
diff changeset
18 let s:varsp2 = "\ud83c\u00a0"
b8a56d4d83e0 commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents: 8275
diff changeset
19
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 let s:jsonmb = '"s¢cĴgё"'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 let s:varmb = "s¢cĴgё"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 let s:jsonnr = '1234'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 let s:varnr = 1234
8228
a0e552c51c34 commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
24 if has('float')
a0e552c51c34 commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
25 let s:jsonfl = '12.34'
a0e552c51c34 commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
26 let s:varfl = 12.34
15446
8ac454818352 patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents: 13456
diff changeset
27 let s:jsonneginf = '-Infinity'
8ac454818352 patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents: 13456
diff changeset
28 let s:jsonposinf = 'Infinity'
8ac454818352 patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents: 13456
diff changeset
29 let s:varneginf = -1.0 / 0.0
8ac454818352 patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents: 13456
diff changeset
30 let s:varposinf = 1.0 / 0.0
8275
ff900e499f79 commit https://github.com/vim/vim/commit/7ce686c990ea8c490d16be7f1c6bd95eb48816f9
Christian Brabandt <cb@256bit.org>
parents: 8228
diff changeset
31 let s:jsonnan = 'NaN'
8228
a0e552c51c34 commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
32 let s:varnan = 0.0 / 0.0
a0e552c51c34 commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
33 endif
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 let s:jsonl1 = '[1,"a",3]'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 let s:varl1 = [1, "a", 3]
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 let s:jsonl2 = '[1,["a",[],"c"],3]'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 let s:jsonl2s = " [\r1 , [ \"a\" , [ ] , \"c\" ] , 3\<Tab>]\r\n"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 let s:varl2 = [1, 2, 3]
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 let l2 = ['a', s:varl2, 'c']
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 let s:varl2[1] = l2
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 let s:varl2x = [1, ["a", [], "c"], 3]
7736
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
43 let s:jsonl3 = '[[1,2],[1,2]]'
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
44 let l3 = [1, 2]
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
45 let s:varl3 = [l3, l3]
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 let s:jsond1 = '{"a":1,"b":"bee","c":[1,2]}'
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
48 let s:jsd1 = '{a:1,b:"bee",c:[1,2]}'
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 let s:vard1 = {"a": 1, "b": "bee","c": [1,2]}
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 let s:jsond2 = '{"1":1,"2":{"a":"aa","b":{},"c":"cc"},"3":3}'
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
51 let s:jsd2 = '{"1":1,"2":{a:"aa",b:{},c:"cc"},"3":3}'
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 let s:jsond2s = " { \"1\" : 1 , \"2\" :\n{ \"a\"\r: \"aa\" , \"b\" : {\<Tab>} , \"c\" : \"cc\" } , \"3\" : 3 }\r\n"
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
53 let s:jsd2s = " { \"1\" : 1 , \"2\" :\n{ a\r: \"aa\" , b : {\<Tab>} , c : \"cc\" } , \"3\" : 3 }\r\n"
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 let s:vard2 = {"1": 1, "2": 2, "3": 3}
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 let d2 = {"a": "aa", "b": s:vard2, "c": "cc"}
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 let s:vard2["2"] = d2
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 let s:vard2x = {"1": 1, "2": {"a": "aa", "b": {}, "c": "cc"}, "3": 3}
7736
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
58 let d3 = {"a": 1, "b": 2}
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
59 let s:vard3 = {"x": d3, "y": d3}
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
60 let s:jsond3 = '{"x":{"a":1,"b":2},"y":{"a":1,"b":2}}'
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
61 let s:jsd3 = '{x:{a:1,b:2},y:{a:1,b:2}}'
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
62 let s:vard4 = {"key": v:none}
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
63 let s:vard4x = {"key": v:null}
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
64 let s:jsond4 = '{"key":null}'
22629
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
65 let s:jsd4 = '{key:null}' " js_encode puts no quotes around simple key.
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
66 let s:vard5 = {"key!": v:none}
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
67 let s:vard5x = {"key!": v:null}
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
68 let s:jsond5 = '{"key!":null}'
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
69 let s:jsd5 = '{"key!":null}' " js_encode puts quotes around non-simple key.
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
71 let s:jsonvals = '[true,false,null,null]'
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
72 let s:varvals = [v:true, v:false, v:null, v:null]
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
74 func Test_json_encode()
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
75 call assert_equal(s:json1, json_encode(s:var1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
76 call assert_equal(s:json2, json_encode(s:var2))
17916
2e53305f2239 patch 8.1.1954: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
77 call assert_equal(s:json3, s:var3->json_encode())
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
78 call assert_equal(s:json4, json_encode(s:var4))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
79 call assert_equal(s:json5, json_encode(s:var5))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80
15607
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
81 call assert_equal(s:jsonmb, json_encode(s:varmb))
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
82 " no test for surrogate pair, json_encode() doesn't create them.
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
84 call assert_equal(s:jsonnr, json_encode(s:varnr))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 if has('float')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
86 call assert_equal(s:jsonfl, json_encode(s:varfl))
15446
8ac454818352 patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents: 13456
diff changeset
87 call assert_equal(s:jsonneginf, json_encode(s:varneginf))
8ac454818352 patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents: 13456
diff changeset
88 call assert_equal(s:jsonposinf, json_encode(s:varposinf))
8228
a0e552c51c34 commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
89 call assert_equal(s:jsonnan, json_encode(s:varnan))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 endif
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
92 call assert_equal(s:jsonl1, json_encode(s:varl1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
93 call assert_equal(s:jsonl2, json_encode(s:varl2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
94 call assert_equal(s:jsonl3, json_encode(s:varl3))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
96 call assert_equal(s:jsond1, json_encode(s:vard1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
97 call assert_equal(s:jsond2, json_encode(s:vard2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
98 call assert_equal(s:jsond3, json_encode(s:vard3))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
99 call assert_equal(s:jsond4, json_encode(s:vard4))
22629
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
100 call assert_equal(s:jsond5, json_encode(s:vard5))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
102 call assert_equal(s:jsonvals, json_encode(s:varvals))
7736
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
103
21261
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
104 " JSON is always encoded in utf-8 regardless of 'encoding' value.
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
105 let save_encoding = &encoding
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
106 set encoding=latin1
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
107 call assert_equal('"café"', json_encode("caf\xe9"))
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
108 let &encoding = save_encoding
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
109
23891
650070143c56 patch 8.2.2488: json_encode() gives generic argument error
Bram Moolenaar <Bram@vim.org>
parents: 22629
diff changeset
110 call assert_fails('echo json_encode(function("tr"))', 'E1161: Cannot json encode a func')
650070143c56 patch 8.2.2488: json_encode() gives generic argument error
Bram Moolenaar <Bram@vim.org>
parents: 22629
diff changeset
111 call assert_fails('echo json_encode([function("tr")])', 'E1161: Cannot json encode a func')
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7947
diff changeset
112
13031
c35d266308c2 patch 8.0.1391: encoding empty string to JSON sometimes gives "null"
Christian Brabandt <cb@256bit.org>
parents: 10839
diff changeset
113 call assert_equal('{"a":""}', json_encode({'a': test_null_string()}))
c35d266308c2 patch 8.0.1391: encoding empty string to JSON sometimes gives "null"
Christian Brabandt <cb@256bit.org>
parents: 10839
diff changeset
114 call assert_equal('{"a":[]}', json_encode({"a": test_null_list()}))
c35d266308c2 patch 8.0.1391: encoding empty string to JSON sometimes gives "null"
Christian Brabandt <cb@256bit.org>
parents: 10839
diff changeset
115 call assert_equal('{"a":{}}', json_encode({"a": test_null_dict()}))
c35d266308c2 patch 8.0.1391: encoding empty string to JSON sometimes gives "null"
Christian Brabandt <cb@256bit.org>
parents: 10839
diff changeset
116
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
117 silent! let res = json_encode(function("tr"))
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7947
diff changeset
118 call assert_equal("", res)
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 endfunc
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
120
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
121 func Test_json_decode()
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
122 call assert_equal(s:var1, json_decode(s:json1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
123 call assert_equal(s:var2, json_decode(s:json2))
17916
2e53305f2239 patch 8.1.1954: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
124 call assert_equal(s:var3, s:json3->json_decode())
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
125 call assert_equal(s:var4, json_decode(s:json4))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
126 call assert_equal(s:var5, json_decode(s:json5))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127
15607
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
128 call assert_equal(s:varmb, json_decode(s:jsonmb))
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
129 call assert_equal(s:varsp1, json_decode(s:jsonsp1))
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
130 call assert_equal(s:varsp2, json_decode(s:jsonsp2))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
132 call assert_equal(s:varnr, json_decode(s:jsonnr))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 if has('float')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
134 call assert_equal(s:varfl, json_decode(s:jsonfl))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 endif
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
137 call assert_equal(s:varl1, json_decode(s:jsonl1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
138 call assert_equal(s:varl2x, json_decode(s:jsonl2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
139 call assert_equal(s:varl2x, json_decode(s:jsonl2s))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
140 call assert_equal(s:varl3, json_decode(s:jsonl3))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
142 call assert_equal(s:vard1, json_decode(s:jsond1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
143 call assert_equal(s:vard2x, json_decode(s:jsond2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
144 call assert_equal(s:vard2x, json_decode(s:jsond2s))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
145 call assert_equal(s:vard3, json_decode(s:jsond3))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
146 call assert_equal(s:vard4x, json_decode(s:jsond4))
22629
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
147 call assert_equal(s:vard5x, json_decode(s:jsond5))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
149 call assert_equal(s:varvals, json_decode(s:jsonvals))
7718
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
150
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
151 call assert_equal(v:true, json_decode('true'))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
152 call assert_equal(type(v:true), type(json_decode('true')))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
153 call assert_equal(v:none, json_decode(''))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
154 call assert_equal(type(v:none), type(json_decode('')))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
155 call assert_equal("", json_decode('""'))
7718
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
156
21261
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
157 " Character in string after \ is ignored if not special.
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
158 call assert_equal("x", json_decode('"\x"'))
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
159
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
160 " JSON is always encoded in utf-8 regardless of 'encoding' value.
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
161 let save_encoding = &encoding
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
162 set encoding=latin1
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
163 call assert_equal("caf\xe9", json_decode('"café"'))
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
164 let &encoding = save_encoding
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
165
10839
287049007bbc patch 8.0.0309: cannot use an empty key in json
Christian Brabandt <cb@256bit.org>
parents: 10581
diff changeset
166 " empty key is OK
287049007bbc patch 8.0.0309: cannot use an empty key in json
Christian Brabandt <cb@256bit.org>
parents: 10581
diff changeset
167 call assert_equal({'': 'ok'}, json_decode('{"": "ok"}'))
287049007bbc patch 8.0.0309: cannot use an empty key in json
Christian Brabandt <cb@256bit.org>
parents: 10581
diff changeset
168 " but not twice
287049007bbc patch 8.0.0309: cannot use an empty key in json
Christian Brabandt <cb@256bit.org>
parents: 10581
diff changeset
169 call assert_fails("call json_decode('{\"\": \"ok\", \"\": \"bad\"}')", 'E938:')
287049007bbc patch 8.0.0309: cannot use an empty key in json
Christian Brabandt <cb@256bit.org>
parents: 10581
diff changeset
170
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
171 call assert_equal({'n': 1}, json_decode('{"n":1,}'))
20492
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
172 call assert_fails("call json_decode(\"{'n':'1',}\")", 'E491:')
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
173 call assert_fails("call json_decode(\"'n'\")", 'E491:')
7732
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
174
20492
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
175 call assert_fails('call json_decode("\"")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
176 call assert_fails('call json_decode("blah")', "E491:")
10553
f83b6a0b6148 patch 8.0.0166: JSON with a duplicate key gives an internal error
Christian Brabandt <cb@256bit.org>
parents: 9618
diff changeset
177 call assert_fails('call json_decode("true blah")', "E488:")
20492
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
178 call assert_fails('call json_decode("<foobar>")', "E491:")
10581
dffda1f9b501 patch 8.0.0180: error E937 is used twice
Christian Brabandt <cb@256bit.org>
parents: 10563
diff changeset
179 call assert_fails('call json_decode("{\"a\":1,\"a\":2}")', "E938:")
7732
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
180
20492
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
181 call assert_fails('call json_decode("{")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
182 call assert_fails('call json_decode("{foobar}")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
183 call assert_fails('call json_decode("{\"n\",")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
184 call assert_fails('call json_decode("{\"n\":")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
185 call assert_fails('call json_decode("{\"n\":1")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
186 call assert_fails('call json_decode("{\"n\":1,")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
187 call assert_fails('call json_decode("{\"n\",1}")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
188 call assert_fails('call json_decode("{-}")', "E491:")
21261
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
189 if has('float')
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
190 call assert_fails('call json_decode("{3.14:1}")', "E806:")
21261
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
191 endif
7732
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
192
20492
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
193 call assert_fails('call json_decode("[foobar]")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
194 call assert_fails('call json_decode("[")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
195 call assert_fails('call json_decode("[1")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
196 call assert_fails('call json_decode("[1,")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
197 call assert_fails('call json_decode("[1 2]")', "E491:")
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
198
20492
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
199 call assert_fails('call json_decode("[1,,2]")', "E491:")
13456
7495e3ee1a69 patch 8.0.1602: crash in parsing JSON
Christian Brabandt <cb@256bit.org>
parents: 13031
diff changeset
200
20492
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
201 call assert_fails('call json_decode("{{}:42}")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
202 call assert_fails('call json_decode("{[]:42}")', "E491:")
22629
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
203 call assert_fails('call json_decode("{1:1{")', "E491:")
16706
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 16306
diff changeset
204
21261
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
205 call assert_fails('call json_decode("-")', "E491:")
22510
7060df0b8ebf patch 8.2.1803: a few failures are not tested
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
206 call assert_fails('call json_decode("-1x")', "E491:")
21261
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
207 call assert_fails('call json_decode("infinit")', "E491:")
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
208
20492
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
209 call assert_fails('call json_decode("\"\\u111Z\"")', 'E491:')
16706
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 16306
diff changeset
210 call assert_equal('[😂]', json_decode('"[\uD83D\uDE02]"'))
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 16306
diff changeset
211 call assert_equal('a😂b', json_decode('"a\uD83D\uDE02b"'))
21275
c14e628cd4bb patch 8.2.1188: memory leak with invalid json input
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
212
c14e628cd4bb patch 8.2.1188: memory leak with invalid json input
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
213 call assert_fails('call json_decode("{\"\":{\"\":{")', 'E491:')
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
214 endfunc
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
215
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
216 let s:jsl5 = '[7,,,]'
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
217 let s:varl5 = [7, v:none, v:none]
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
218
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
219 func Test_js_encode()
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
220 call assert_equal(s:json1, js_encode(s:var1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
221 call assert_equal(s:json2, js_encode(s:var2))
17916
2e53305f2239 patch 8.1.1954: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
222 call assert_equal(s:json3, s:var3->js_encode())
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
223 call assert_equal(s:json4, js_encode(s:var4))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
224 call assert_equal(s:json5, js_encode(s:var5))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
225
15607
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
226 call assert_equal(s:jsonmb, js_encode(s:varmb))
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
227 " no test for surrogate pair, js_encode() doesn't create them.
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
228
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
229 call assert_equal(s:jsonnr, js_encode(s:varnr))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
230 if has('float')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
231 call assert_equal(s:jsonfl, js_encode(s:varfl))
15446
8ac454818352 patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents: 13456
diff changeset
232 call assert_equal(s:jsonneginf, js_encode(s:varneginf))
8ac454818352 patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents: 13456
diff changeset
233 call assert_equal(s:jsonposinf, js_encode(s:varposinf))
8275
ff900e499f79 commit https://github.com/vim/vim/commit/7ce686c990ea8c490d16be7f1c6bd95eb48816f9
Christian Brabandt <cb@256bit.org>
parents: 8228
diff changeset
234 call assert_equal(s:jsonnan, js_encode(s:varnan))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
235 endif
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
236
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
237 call assert_equal(s:jsonl1, js_encode(s:varl1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
238 call assert_equal(s:jsonl2, js_encode(s:varl2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
239 call assert_equal(s:jsonl3, js_encode(s:varl3))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
240
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
241 call assert_equal(s:jsd1, js_encode(s:vard1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
242 call assert_equal(s:jsd2, js_encode(s:vard2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
243 call assert_equal(s:jsd3, js_encode(s:vard3))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
244 call assert_equal(s:jsd4, js_encode(s:vard4))
22629
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
245 call assert_equal(s:jsd5, js_encode(s:vard5))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
246
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
247 call assert_equal(s:jsonvals, js_encode(s:varvals))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
248
23891
650070143c56 patch 8.2.2488: json_encode() gives generic argument error
Bram Moolenaar <Bram@vim.org>
parents: 22629
diff changeset
249 call assert_fails('echo js_encode(function("tr"))', 'E1161: Cannot json encode a func')
650070143c56 patch 8.2.2488: json_encode() gives generic argument error
Bram Moolenaar <Bram@vim.org>
parents: 22629
diff changeset
250 call assert_fails('echo js_encode([function("tr")])', 'E1161: Cannot json encode a func')
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
251
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
252 silent! let res = js_encode(function("tr"))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
253 call assert_equal("", res)
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
254
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
255 call assert_equal(s:jsl5, js_encode(s:varl5))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
256 endfunc
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
257
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
258 func Test_js_decode()
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
259 call assert_equal(s:var1, js_decode(s:json1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
260 call assert_equal(s:var2, js_decode(s:json2))
17916
2e53305f2239 patch 8.1.1954: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
261 call assert_equal(s:var3, s:json3->js_decode())
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
262 call assert_equal(s:var4, js_decode(s:json4))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
263 call assert_equal(s:var5, js_decode(s:json5))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
264
15607
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
265 call assert_equal(s:varmb, js_decode(s:jsonmb))
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
266 call assert_equal(s:varsp1, js_decode(s:jsonsp1))
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
267 call assert_equal(s:varsp2, js_decode(s:jsonsp2))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
268
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
269 call assert_equal(s:varnr, js_decode(s:jsonnr))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
270 if has('float')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
271 call assert_equal(s:varfl, js_decode(s:jsonfl))
15446
8ac454818352 patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents: 13456
diff changeset
272 call assert_equal(s:varneginf, js_decode(s:jsonneginf))
8ac454818352 patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents: 13456
diff changeset
273 call assert_equal(s:varposinf, js_decode(s:jsonposinf))
8275
ff900e499f79 commit https://github.com/vim/vim/commit/7ce686c990ea8c490d16be7f1c6bd95eb48816f9
Christian Brabandt <cb@256bit.org>
parents: 8228
diff changeset
274 call assert_true(isnan(js_decode(s:jsonnan)))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
275 endif
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
276
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
277 call assert_equal(s:varl1, js_decode(s:jsonl1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
278 call assert_equal(s:varl2x, js_decode(s:jsonl2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
279 call assert_equal(s:varl2x, js_decode(s:jsonl2s))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
280 call assert_equal(s:varl3, js_decode(s:jsonl3))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
281
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
282 call assert_equal(s:vard1, js_decode(s:jsond1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
283 call assert_equal(s:vard1, js_decode(s:jsd1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
284 call assert_equal(s:vard2x, js_decode(s:jsond2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
285 call assert_equal(s:vard2x, js_decode(s:jsd2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
286 call assert_equal(s:vard2x, js_decode(s:jsond2s))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
287 call assert_equal(s:vard2x, js_decode(s:jsd2s))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
288 call assert_equal(s:vard3, js_decode(s:jsond3))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
289 call assert_equal(s:vard3, js_decode(s:jsd3))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
290 call assert_equal(s:vard4x, js_decode(s:jsond4))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
291 call assert_equal(s:vard4x, js_decode(s:jsd4))
22629
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
292 call assert_equal(s:vard5x, js_decode(s:jsond5))
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
293 call assert_equal(s:vard5x, js_decode(s:jsd5))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
294
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
295 call assert_equal(s:varvals, js_decode(s:jsonvals))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
296
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
297 call assert_equal(v:true, js_decode('true'))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
298 call assert_equal(type(v:true), type(js_decode('true')))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
299 call assert_equal(v:none, js_decode(''))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
300 call assert_equal(type(v:none), type(js_decode('')))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
301 call assert_equal("", js_decode('""'))
10563
bac9cec298ed patch 8.0.0171: JS style JSON does not support single quotes
Christian Brabandt <cb@256bit.org>
parents: 10553
diff changeset
302 call assert_equal("", js_decode("''"))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
303
10563
bac9cec298ed patch 8.0.0171: JS style JSON does not support single quotes
Christian Brabandt <cb@256bit.org>
parents: 10553
diff changeset
304 call assert_equal('n', js_decode("'n'"))
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
305 call assert_equal({'n': 1}, js_decode('{"n":1,}'))
10563
bac9cec298ed patch 8.0.0171: JS style JSON does not support single quotes
Christian Brabandt <cb@256bit.org>
parents: 10553
diff changeset
306 call assert_equal({'n': '1'}, js_decode("{'n':'1',}"))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
307
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
308 call assert_fails('call js_decode("\"")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
309 call assert_fails('call js_decode("blah")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
310 call assert_fails('call js_decode("true blah")', "E488:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
311 call assert_fails('call js_decode("<foobar>")', "E491:")
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
312
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
313 call assert_fails('call js_decode("{")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
314 call assert_fails('call js_decode("{foobar}")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
315 call assert_fails('call js_decode("{\"n\",")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
316 call assert_fails('call js_decode("{\"n\":")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
317 call assert_fails('call js_decode("{\"n\":1")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
318 call assert_fails('call js_decode("{\"n\":1,")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
319 call assert_fails('call js_decode("{\"n\",1}")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
320 call assert_fails('call js_decode("{-}")', "E491:")
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
321
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
322 call assert_fails('call js_decode("[foobar]")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
323 call assert_fails('call js_decode("[")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
324 call assert_fails('call js_decode("[1")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
325 call assert_fails('call js_decode("[1,")', "E491:")
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
326 call assert_fails('call js_decode("[1 2]")', "E491:")
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
327
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
328 call assert_equal(s:varl5, js_decode(s:jsl5))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
329 endfunc
16306
a2c598cbe220 patch 8.1.1158: json encoded string is sometimes missing the final NUL
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
330
a2c598cbe220 patch 8.1.1158: json encoded string is sometimes missing the final NUL
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
331 func Test_json_encode_long()
a2c598cbe220 patch 8.1.1158: json encoded string is sometimes missing the final NUL
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
332 " The growarray uses a grow size of 4000, check that a result that is exactly
a2c598cbe220 patch 8.1.1158: json encoded string is sometimes missing the final NUL
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
333 " 4000 bytes long is not missing the final NUL.
a2c598cbe220 patch 8.1.1158: json encoded string is sometimes missing the final NUL
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
334 let json = json_encode([repeat('a', 3996)])
a2c598cbe220 patch 8.1.1158: json encoded string is sometimes missing the final NUL
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
335 call assert_equal(4000, len(json))
a2c598cbe220 patch 8.1.1158: json encoded string is sometimes missing the final NUL
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
336 endfunc
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21275
diff changeset
337
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21275
diff changeset
338 " vim: shiftwidth=2 sts=2 expandtab