annotate src/testdir/test_json.vim @ 15508:69207f77754a v8.1.0762

patch 8.1.0762: compiler warning commit https://github.com/vim/vim/commit/e40742526e6ea272c64ca393d7364e4023f4122c Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 17 14:31:14 2019 +0100 patch 8.1.0762: compiler warning Problem: Compiler warning. Solution: Add type cast. (Mike Williams)
author Bram Moolenaar <Bram@vim.org>
date Thu, 17 Jan 2019 14:45:11 +0100
parents 8ac454818352
children 2dcaa860e3fc
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
9618
81ba6e4eb72b commit https://github.com/vim/vim/commit/ac105ed3c420660ddbddc501c97875c48220817e
Christian Brabandt <cb@256bit.org>
parents: 8326
diff changeset
3 " JSON requires using utf-8, because conversion breaks the asserts.
8312
1001ec135d6e commit https://github.com/vim/vim/commit/c5215e943bf5a045089693b60b8805a794d8c2f6
Christian Brabandt <cb@256bit.org>
parents: 8283
diff changeset
4 if !has('multi_byte')
1001ec135d6e commit https://github.com/vim/vim/commit/c5215e943bf5a045089693b60b8805a794d8c2f6
Christian Brabandt <cb@256bit.org>
parents: 8283
diff changeset
5 finish
1001ec135d6e commit https://github.com/vim/vim/commit/c5215e943bf5a045089693b60b8805a794d8c2f6
Christian Brabandt <cb@256bit.org>
parents: 8283
diff changeset
6 endif
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 let s:json1 = '"str\"in\\g"'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 let s:var1 = "str\"in\\g"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 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
11 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
12 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
13 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
14 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
15 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
16 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
17 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
18
8283
b8a56d4d83e0 commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents: 8275
diff changeset
19 " surrogate pair
b8a56d4d83e0 commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents: 8275
diff changeset
20 let s:jsonsp1 = '"\ud83c\udf63"'
b8a56d4d83e0 commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents: 8275
diff changeset
21 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
22 let s:jsonsp2 = '"\ud83c\u00a0"'
b8a56d4d83e0 commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents: 8275
diff changeset
23 let s:varsp2 = "\ud83c\u00a0"
b8a56d4d83e0 commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents: 8275
diff changeset
24
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 let s:jsonmb = '"s¢cĴgё"'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 let s:varmb = "s¢cĴgё"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 let s:jsonnr = '1234'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 let s:varnr = 1234
8228
a0e552c51c34 commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
29 if has('float')
a0e552c51c34 commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
30 let s:jsonfl = '12.34'
a0e552c51c34 commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
31 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
32 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
33 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
34 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
35 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
36 let s:jsonnan = 'NaN'
8228
a0e552c51c34 commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents: 8019
diff changeset
37 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
38 endif
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 let s:jsonl1 = '[1,"a",3]'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 let s:varl1 = [1, "a", 3]
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 let s:jsonl2 = '[1,["a",[],"c"],3]'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 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
44 let s:varl2 = [1, 2, 3]
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 let l2 = ['a', s:varl2, 'c']
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 let s:varl2[1] = l2
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 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
48 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
49 let l3 = [1, 2]
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
50 let s:varl3 = [l3, l3]
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60 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
61 let s:vard2["2"] = d2
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 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
63 let d3 = {"a": 1, "b": 2}
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
64 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
65 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
66 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
67 let s:vard4 = {"key": v:none}
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
68 let s:vard4x = {"key": v:null}
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
69 let s:jsond4 = '{"key":null}'
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
70 let s:jsd4 = '{key: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 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
73 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
74
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
75 func Test_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:json1, json_encode(s:var1))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
77 call assert_equal(s:json2, json_encode(s:var2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
78 call assert_equal(s:json3, json_encode(s:var3))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
79 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
80 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
81
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 if has('multi_byte')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
83 call assert_equal(s:jsonmb, json_encode(s:varmb))
8326
bec1dcfaa8be commit https://github.com/vim/vim/commit/fc2457e21d136cb366076edd448e67c9732dc40a
Christian Brabandt <cb@256bit.org>
parents: 8316
diff changeset
84 " 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
85 endif
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
87 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
88 if has('float')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
89 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
90 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
91 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
92 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
93 endif
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
95 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
96 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
97 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
98
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
99 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
100 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
101 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
102 call assert_equal(s:jsond4, json_encode(s:vard4))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
104 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
105
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
106 call assert_fails('echo json_encode(function("tr"))', 'E474:')
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
107 call assert_fails('echo json_encode([function("tr")])', 'E474:')
7965
646d5148fee2 commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Christian Brabandt <cb@256bit.org>
parents: 7947
diff changeset
108
13031
c35d266308c2 patch 8.0.1391: encoding empty string to JSON sometimes gives "null"
Christian Brabandt <cb@256bit.org>
parents: 10839
diff changeset
109 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
110 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
111 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
112
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
113 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
114 call assert_equal("", res)
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 endfunc
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
117 func Test_json_decode()
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
118 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
119 call assert_equal(s:var2, json_decode(s:json2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
120 call assert_equal(s:var3, json_decode(s:json3))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
121 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
122 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
123
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 if has('multi_byte')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
125 call assert_equal(s:varmb, json_decode(s:jsonmb))
8326
bec1dcfaa8be commit https://github.com/vim/vim/commit/fc2457e21d136cb366076edd448e67c9732dc40a
Christian Brabandt <cb@256bit.org>
parents: 8316
diff changeset
126 call assert_equal(s:varsp1, json_decode(s:jsonsp1))
bec1dcfaa8be commit https://github.com/vim/vim/commit/fc2457e21d136cb366076edd448e67c9732dc40a
Christian Brabandt <cb@256bit.org>
parents: 8316
diff changeset
127 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
128 endif
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
130 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
131 if has('float')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
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 endif
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
135 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
136 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
137 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
138 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
139
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
140 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
141 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
142 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
143 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
144 call assert_equal(s:vard4x, json_decode(s:jsond4))
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
10839
287049007bbc patch 8.0.0309: cannot use an empty key in json
Christian Brabandt <cb@256bit.org>
parents: 10581
diff changeset
154 " 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
155 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
156 " but not twice
287049007bbc patch 8.0.0309: cannot use an empty key in json
Christian Brabandt <cb@256bit.org>
parents: 10581
diff changeset
157 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
158
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
159 call assert_equal({'n': 1}, json_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
160 call assert_fails("call json_decode(\"{'n':'1',}\")", 'E474:')
bac9cec298ed patch 8.0.0171: JS style JSON does not support single quotes
Christian Brabandt <cb@256bit.org>
parents: 10553
diff changeset
161 call assert_fails("call json_decode(\"'n'\")", 'E474:')
7732
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
162
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
163 call assert_fails('call json_decode("\"")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
164 call assert_fails('call json_decode("blah")', "E474:")
10553
f83b6a0b6148 patch 8.0.0166: JSON with a duplicate key gives an internal error
Christian Brabandt <cb@256bit.org>
parents: 9618
diff changeset
165 call assert_fails('call json_decode("true blah")', "E488:")
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
166 call assert_fails('call json_decode("<foobar>")', "E474:")
10581
dffda1f9b501 patch 8.0.0180: error E937 is used twice
Christian Brabandt <cb@256bit.org>
parents: 10563
diff changeset
167 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
168
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
169 call assert_fails('call json_decode("{")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
170 call assert_fails('call json_decode("{foobar}")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
171 call assert_fails('call json_decode("{\"n\",")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
172 call assert_fails('call json_decode("{\"n\":")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
173 call assert_fails('call json_decode("{\"n\":1")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
174 call assert_fails('call json_decode("{\"n\":1,")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
175 call assert_fails('call json_decode("{\"n\",1}")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
176 call assert_fails('call json_decode("{-}")', "E474:")
7732
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
177
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
178 call assert_fails('call json_decode("[foobar]")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
179 call assert_fails('call json_decode("[")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
180 call assert_fails('call json_decode("[1")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
181 call assert_fails('call json_decode("[1,")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
182 call assert_fails('call json_decode("[1 2]")', "E474:")
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
183
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
184 call assert_fails('call json_decode("[1,,2]")', "E474:")
13456
7495e3ee1a69 patch 8.0.1602: crash in parsing JSON
Christian Brabandt <cb@256bit.org>
parents: 13031
diff changeset
185
7495e3ee1a69 patch 8.0.1602: crash in parsing JSON
Christian Brabandt <cb@256bit.org>
parents: 13031
diff changeset
186 call assert_fails('call json_decode("{{}:42}")', "E474:")
7495e3ee1a69 patch 8.0.1602: crash in parsing JSON
Christian Brabandt <cb@256bit.org>
parents: 13031
diff changeset
187 call assert_fails('call json_decode("{[]:42}")', "E474:")
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
188 endfunc
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
189
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
190 let s:jsl5 = '[7,,,]'
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
191 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
192
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
193 func Test_js_encode()
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
194 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
195 call assert_equal(s:json2, js_encode(s:var2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
196 call assert_equal(s:json3, js_encode(s:var3))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
197 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
198 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
199
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
200 if has('multi_byte')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
201 call assert_equal(s:jsonmb, js_encode(s:varmb))
8326
bec1dcfaa8be commit https://github.com/vim/vim/commit/fc2457e21d136cb366076edd448e67c9732dc40a
Christian Brabandt <cb@256bit.org>
parents: 8316
diff changeset
202 " 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
203 endif
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
204
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
205 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
206 if has('float')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
207 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
208 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
209 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
210 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
211 endif
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
212
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
213 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
214 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
215 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
216
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
217 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
218 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
219 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
220 call assert_equal(s:jsd4, js_encode(s:vard4))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
221
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
222 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
223
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
224 call assert_fails('echo js_encode(function("tr"))', 'E474:')
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
225 call assert_fails('echo js_encode([function("tr")])', 'E474:')
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
226
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
227 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
228 call assert_equal("", res)
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:jsl5, js_encode(s:varl5))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
231 endfunc
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
232
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
233 func Test_js_decode()
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
234 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
235 call assert_equal(s:var2, js_decode(s:json2))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
236 call assert_equal(s:var3, js_decode(s:json3))
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
237 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
238 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
239
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
240 if has('multi_byte')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
241 call assert_equal(s:varmb, js_decode(s:jsonmb))
8326
bec1dcfaa8be commit https://github.com/vim/vim/commit/fc2457e21d136cb366076edd448e67c9732dc40a
Christian Brabandt <cb@256bit.org>
parents: 8316
diff changeset
242 call assert_equal(s:varsp1, js_decode(s:jsonsp1))
bec1dcfaa8be commit https://github.com/vim/vim/commit/fc2457e21d136cb366076edd448e67c9732dc40a
Christian Brabandt <cb@256bit.org>
parents: 8316
diff changeset
243 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
244 endif
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
245
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
246 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
247 if has('float')
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
248 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
249 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
250 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
251 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
252 endif
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
253
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
254 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
255 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
256 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
257 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
258
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
259 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
260 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
261 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
262 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
263 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
264 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
265 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
266 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
267 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
268 call assert_equal(s:vard4x, js_decode(s:jsd4))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
269
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
270 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
271
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
272 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
273 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
274 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
275 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
276 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
277 call assert_equal("", js_decode("''"))
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
278
10563
bac9cec298ed patch 8.0.0171: JS style JSON does not support single quotes
Christian Brabandt <cb@256bit.org>
parents: 10553
diff changeset
279 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
280 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
281 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
282
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
283 call assert_fails('call js_decode("\"")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
284 call assert_fails('call js_decode("blah")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
285 call assert_fails('call js_decode("true blah")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
286 call assert_fails('call js_decode("<foobar>")', "E474:")
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_fails('call js_decode("{")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
289 call assert_fails('call js_decode("{foobar}")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
290 call assert_fails('call js_decode("{\"n\",")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
291 call assert_fails('call js_decode("{\"n\":")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
292 call assert_fails('call js_decode("{\"n\":1")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
293 call assert_fails('call js_decode("{\"n\":1,")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
294 call assert_fails('call js_decode("{\"n\",1}")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
295 call assert_fails('call js_decode("{-}")', "E474:")
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_fails('call js_decode("[foobar]")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
298 call assert_fails('call js_decode("[")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
299 call assert_fails('call js_decode("[1")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
300 call assert_fails('call js_decode("[1,")', "E474:")
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
301 call assert_fails('call js_decode("[1 2]")', "E474:")
7967
45ea5ebf3a98 commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents: 7965
diff changeset
302
8019
d685893d852e commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents: 7967
diff changeset
303 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
304 endfunc