annotate src/testdir/test_json.vim @ 31233:d80066065462 v9.0.0950

patch 9.0.0950: the pattern "_szs" matches at EOL Commit: https://github.com/vim/vim/commit/c96311b5be307f5a1d1b20a0ec930d63964e7335 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Nov 25 21:13:47 2022 +0000 patch 9.0.0950: the pattern "\_s\zs" matches at EOL Problem: The pattern "\_s\zs" matches at EOL. Solution: Make the pattern "\_s\zs" match at the start of the next line. (closes #11617)
author Bram Moolenaar <Bram@vim.org>
date Fri, 25 Nov 2022 22:15:03 +0100
parents 029c59bf78f1
children
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
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
24 let s:jsonfl = '12.34'
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
25 let s:varfl = 12.34
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
26 let s:jsonneginf = '-Infinity'
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
27 let s:jsonposinf = 'Infinity'
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
28 let s:varneginf = -1.0 / 0.0
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
29 let s:varposinf = 1.0 / 0.0
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
30 let s:jsonnan = 'NaN'
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
31 let s:varnan = 0.0 / 0.0
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 let s:jsonl1 = '[1,"a",3]'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 let s:varl1 = [1, "a", 3]
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 let s:jsonl2 = '[1,["a",[],"c"],3]'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 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
37 let s:varl2 = [1, 2, 3]
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 let l2 = ['a', s:varl2, 'c']
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 let s:varl2[1] = l2
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 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
41 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
42 let l3 = [1, 2]
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
43 let s:varl3 = [l3, l3]
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 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
46 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
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 let s:vard2["2"] = d2
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 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
56 let d3 = {"a": 1, "b": 2}
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
57 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
58 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
59 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
60 let s:vard4 = {"key": v:none}
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
61 let s:vard4x = {"key": v:null}
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
62 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
63 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
64 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
65 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
66 let s:jsond5 = '{"key!":null}'
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
67 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
68
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
69 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
70 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
71
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
72 func Test_json_encode()
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
73 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
74 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
75 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
76 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
77 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
78
15607
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
79 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
80 " 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
81
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
82 call assert_equal(s:jsonnr, json_encode(s:varnr))
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
83 call assert_equal(s:jsonfl, json_encode(s:varfl))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
84 call assert_equal(s:jsonneginf, json_encode(s:varneginf))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
85 call assert_equal(s:jsonposinf, json_encode(s:varposinf))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
86 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
87
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
88 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
89 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
90 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
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:jsond1, json_encode(s:vard1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
93 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
94 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
95 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
96 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
97
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
98 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
99
21261
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
100 " 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
101 let save_encoding = &encoding
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
102 set encoding=latin1
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
103 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
104 let &encoding = save_encoding
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
105
28339
0860b12c5788 patch 8.2.4695: JSON encoding could be faster
Bram Moolenaar <Bram@vim.org>
parents: 23891
diff changeset
106 " Invalid utf-8 sequences are replaced with U+FFFD (replacement character)
0860b12c5788 patch 8.2.4695: JSON encoding could be faster
Bram Moolenaar <Bram@vim.org>
parents: 23891
diff changeset
107 call assert_equal('"foo' . "\ufffd" . '"', json_encode("foo\xAB"))
0860b12c5788 patch 8.2.4695: JSON encoding could be faster
Bram Moolenaar <Bram@vim.org>
parents: 23891
diff changeset
108
23891
650070143c56 patch 8.2.2488: json_encode() gives generic argument error
Bram Moolenaar <Bram@vim.org>
parents: 22629
diff changeset
109 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
110 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
111
13031
c35d266308c2 patch 8.0.1391: encoding empty string to JSON sometimes gives "null"
Christian Brabandt <cb@256bit.org>
parents: 10839
diff changeset
112 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
113 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
114 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
115
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
116 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
117 call assert_equal("", res)
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118 endfunc
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
120 func Test_json_decode()
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
121 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
122 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
123 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
124 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
125 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
126
15607
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
127 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
128 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
129 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
130
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
131 call assert_equal(s:varnr, json_decode(s:jsonnr))
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
132 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
133
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
134 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
135 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
136 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
137 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
138
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
139 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
140 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
141 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
142 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
143 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
144 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
145
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
146 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
147
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
148 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
149 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
150 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
151 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
152 call assert_equal("", json_decode('""'))
7718
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
153
21261
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
154 " 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
155 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
156
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
157 " 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
158 let save_encoding = &encoding
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
159 set encoding=latin1
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
160 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
161 let &encoding = save_encoding
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
162
10839
287049007bbc patch 8.0.0309: cannot use an empty key in json
Christian Brabandt <cb@256bit.org>
parents: 10581
diff changeset
163 " 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
164 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
165 " but not twice
287049007bbc patch 8.0.0309: cannot use an empty key in json
Christian Brabandt <cb@256bit.org>
parents: 10581
diff changeset
166 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
167
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
168 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
169 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
170 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
171
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("\"")', "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("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
174 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
175 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
176 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
177
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("{")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
179 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
180 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
181 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
182 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
183 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
184 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
185 call assert_fails('call json_decode("{-}")', "E491:")
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
186 call assert_fails('call json_decode("{3.14:1}")', "E806:")
7732
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
187
20492
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("[foobar]")', "E491:")
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
189 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
190 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
191 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
192 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
193
20492
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("[1,,2]")', "E491:")
13456
7495e3ee1a69 patch 8.0.1602: crash in parsing JSON
Christian Brabandt <cb@256bit.org>
parents: 13031
diff changeset
195
20492
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("{{}:42}")', "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("{[]:42}")', "E491:")
22629
4fba373b59da patch 8.2.1863: json code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 22510
diff changeset
198 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
199
21261
018339de3099 patch 8.2.1181: json code not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20492
diff changeset
200 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
201 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
202 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
203
20492
947e50e438d3 patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
204 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
205 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
206 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
207
c14e628cd4bb patch 8.2.1188: memory leak with invalid json input
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
208 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
209 endfunc
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
210
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
211 let s:jsl5 = '[7,,,]'
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
212 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
213
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
214 func Test_js_encode()
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
215 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
216 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
217 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
218 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
219 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
220
15607
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
221 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
222 " 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
223
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
224 call assert_equal(s:jsonnr, js_encode(s:varnr))
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
225 call assert_equal(s:jsonfl, js_encode(s:varfl))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
226 call assert_equal(s:jsonneginf, js_encode(s:varneginf))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
227 call assert_equal(s:jsonposinf, js_encode(s:varposinf))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
228 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
229
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
230 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
231 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
232 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
233
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
234 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
235 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
236 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
237 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
238 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
239
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
240 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
241
23891
650070143c56 patch 8.2.2488: json_encode() gives generic argument error
Bram Moolenaar <Bram@vim.org>
parents: 22629
diff changeset
242 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
243 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
244
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
245 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
246 call assert_equal("", res)
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
247
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
248 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
249 endfunc
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
250
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
251 func Test_js_decode()
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
252 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
253 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
254 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
255 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
256 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
257
15607
2dcaa860e3fc patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15446
diff changeset
258 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
259 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
260 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
261
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
262 call assert_equal(s:varnr, js_decode(s:jsonnr))
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
263 call assert_equal(s:varfl, js_decode(s:jsonfl))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
264 call assert_equal(s:varneginf, js_decode(s:jsonneginf))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
265 call assert_equal(s:varposinf, js_decode(s:jsonposinf))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 28339
diff changeset
266 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
267
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
268 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
269 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
270 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
271 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
272
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
273 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
274 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
275 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
276 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
277 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
278 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
279 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
280 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
281 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
282 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
283 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
284 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
285
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
286 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
287
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
288 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
289 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
290 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
291 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
292 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
293 call assert_equal("", js_decode("''"))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
294
10563
bac9cec298ed patch 8.0.0171: JS style JSON does not support single quotes
Christian Brabandt <cb@256bit.org>
parents: 10553
diff changeset
295 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
296 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
297 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
298
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
299 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
300 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
301 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
302 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
303
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 21261
diff changeset
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311 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
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("[foobar]")', "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("[")', "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("[1")', "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("[1,")', "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("[1 2]")', "E491:")
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
318
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
319 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
320 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
321
a2c598cbe220 patch 8.1.1158: json encoded string is sometimes missing the final NUL
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
322 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
323 " 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
324 " 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
325 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
326 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
327 endfunc
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21275
diff changeset
328
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21275
diff changeset
329 " vim: shiftwidth=2 sts=2 expandtab