Mercurial > vim
annotate src/testdir/test_json.vim @ 20842:bacc2ab11810 v8.2.0973
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Commit: https://github.com/vim/vim/commit/34db91f7a47b7bd4aabf1e1dfbaa8a08278bf78d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jun 13 19:00:10 2020 +0200
patch 8.2.0973: Vim9: type is not checked when assigning to a script variable
Problem: Vim9: type is not checked when assigning to a script variable.
Solution: Check the type.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 13 Jun 2020 19:15:03 +0200 |
parents | 947e50e438d3 |
children | 018339de3099 |
rev | line source |
---|---|
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 " Test for JSON functions. |
8312
1001ec135d6e
commit https://github.com/vim/vim/commit/c5215e943bf5a045089693b60b8805a794d8c2f6
Christian Brabandt <cb@256bit.org>
parents:
8283
diff
changeset
|
2 |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 let s:json1 = '"str\"in\\g"' |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 let s:var1 = "str\"in\\g" |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 let s:json2 = '"\u0001\u0002\u0003\u0004\u0005\u0006\u0007"' |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 let s:var2 = "\x01\x02\x03\x04\x05\x06\x07" |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 let s:json3 = '"\b\t\n\u000b\f\r\u000e\u000f"' |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 let s:var3 = "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 let s:json4 = '"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017"' |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 let s:var4 = "\x10\x11\x12\x13\x14\x15\x16\x17" |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 let s:json5 = '"\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f"' |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 let s:var5 = "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 |
8283
b8a56d4d83e0
commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents:
8275
diff
changeset
|
14 " surrogate pair |
b8a56d4d83e0
commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents:
8275
diff
changeset
|
15 let s:jsonsp1 = '"\ud83c\udf63"' |
b8a56d4d83e0
commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents:
8275
diff
changeset
|
16 let s:varsp1 = "\xf0\x9f\x8d\xa3" |
b8a56d4d83e0
commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents:
8275
diff
changeset
|
17 let s:jsonsp2 = '"\ud83c\u00a0"' |
b8a56d4d83e0
commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents:
8275
diff
changeset
|
18 let s:varsp2 = "\ud83c\u00a0" |
b8a56d4d83e0
commit https://github.com/vim/vim/commit/b6ff81188d27fae774d9ad2dfb498f596d697d4b
Christian Brabandt <cb@256bit.org>
parents:
8275
diff
changeset
|
19 |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 let s:jsonmb = '"s¢cĴgё"' |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 let s:varmb = "s¢cĴgё" |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 let s:jsonnr = '1234' |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 let s:varnr = 1234 |
8228
a0e552c51c34
commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents:
8019
diff
changeset
|
24 if has('float') |
a0e552c51c34
commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents:
8019
diff
changeset
|
25 let s:jsonfl = '12.34' |
a0e552c51c34
commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents:
8019
diff
changeset
|
26 let s:varfl = 12.34 |
15446
8ac454818352
patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents:
13456
diff
changeset
|
27 let s:jsonneginf = '-Infinity' |
8ac454818352
patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents:
13456
diff
changeset
|
28 let s:jsonposinf = 'Infinity' |
8ac454818352
patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents:
13456
diff
changeset
|
29 let s:varneginf = -1.0 / 0.0 |
8ac454818352
patch 8.1.0731: JS encoding does not handle negative infinity
Bram Moolenaar <Bram@vim.org>
parents:
13456
diff
changeset
|
30 let s:varposinf = 1.0 / 0.0 |
8275
ff900e499f79
commit https://github.com/vim/vim/commit/7ce686c990ea8c490d16be7f1c6bd95eb48816f9
Christian Brabandt <cb@256bit.org>
parents:
8228
diff
changeset
|
31 let s:jsonnan = 'NaN' |
8228
a0e552c51c34
commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents:
8019
diff
changeset
|
32 let s:varnan = 0.0 / 0.0 |
a0e552c51c34
commit https://github.com/vim/vim/commit/f1b6ac72293e658bb6e68c5cfd926c405b1b6f34
Christian Brabandt <cb@256bit.org>
parents:
8019
diff
changeset
|
33 endif |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 let s:jsonl1 = '[1,"a",3]' |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 let s:varl1 = [1, "a", 3] |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 let s:jsonl2 = '[1,["a",[],"c"],3]' |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 let s:jsonl2s = " [\r1 , [ \"a\" , [ ] , \"c\" ] , 3\<Tab>]\r\n" |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 let s:varl2 = [1, 2, 3] |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 let l2 = ['a', s:varl2, 'c'] |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 let s:varl2[1] = l2 |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 let s:varl2x = [1, ["a", [], "c"], 3] |
7736
f2ddad8cbce7
commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents:
7732
diff
changeset
|
43 let s:jsonl3 = '[[1,2],[1,2]]' |
f2ddad8cbce7
commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents:
7732
diff
changeset
|
44 let l3 = [1, 2] |
f2ddad8cbce7
commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents:
7732
diff
changeset
|
45 let s:varl3 = [l3, l3] |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
46 |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
47 let s:jsond1 = '{"a":1,"b":"bee","c":[1,2]}' |
7967
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
48 let s:jsd1 = '{a:1,b:"bee",c:[1,2]}' |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
49 let s:vard1 = {"a": 1, "b": "bee","c": [1,2]} |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
50 let s:jsond2 = '{"1":1,"2":{"a":"aa","b":{},"c":"cc"},"3":3}' |
7967
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
51 let s:jsd2 = '{"1":1,"2":{a:"aa",b:{},c:"cc"},"3":3}' |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
52 let s:jsond2s = " { \"1\" : 1 , \"2\" :\n{ \"a\"\r: \"aa\" , \"b\" : {\<Tab>} , \"c\" : \"cc\" } , \"3\" : 3 }\r\n" |
7967
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
53 let s:jsd2s = " { \"1\" : 1 , \"2\" :\n{ a\r: \"aa\" , b : {\<Tab>} , c : \"cc\" } , \"3\" : 3 }\r\n" |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
54 let s:vard2 = {"1": 1, "2": 2, "3": 3} |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
55 let d2 = {"a": "aa", "b": s:vard2, "c": "cc"} |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
56 let s:vard2["2"] = d2 |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
57 let s:vard2x = {"1": 1, "2": {"a": "aa", "b": {}, "c": "cc"}, "3": 3} |
7736
f2ddad8cbce7
commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents:
7732
diff
changeset
|
58 let d3 = {"a": 1, "b": 2} |
f2ddad8cbce7
commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents:
7732
diff
changeset
|
59 let s:vard3 = {"x": d3, "y": d3} |
f2ddad8cbce7
commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents:
7732
diff
changeset
|
60 let s:jsond3 = '{"x":{"a":1,"b":2},"y":{"a":1,"b":2}}' |
7967
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
61 let s:jsd3 = '{x:{a:1,b:2},y:{a:1,b:2}}' |
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
62 let s:vard4 = {"key": v:none} |
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
63 let s:vard4x = {"key": v:null} |
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
64 let s:jsond4 = '{"key":null}' |
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
65 let s:jsd4 = '{key:null}' |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
66 |
7967
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
67 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
|
68 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
|
69 |
7967
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
70 func Test_json_encode() |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 |
15607
2dcaa860e3fc
patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15446
diff
changeset
|
77 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
|
78 " 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
|
79 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
80 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
|
81 if has('float') |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 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
|
86 endif |
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)) |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
96 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
97 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
|
98 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
99 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
|
100 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
|
101 |
13031
c35d266308c2
patch 8.0.1391: encoding empty string to JSON sometimes gives "null"
Christian Brabandt <cb@256bit.org>
parents:
10839
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
106 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
|
107 call assert_equal("", res) |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
108 endfunc |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
109 |
7967
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
110 func Test_json_decode() |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 |
15607
2dcaa860e3fc
patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15446
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
121 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
|
122 if has('float') |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
123 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
|
124 endif |
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
125 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
126 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
|
127 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
|
128 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
|
129 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
|
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:vard1, json_decode(s:jsond1)) |
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 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
|
136 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
137 call assert_equal(s:varvals, json_decode(s:jsonvals)) |
7718
6ebd8bdf41bc
commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents:
7712
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(v:true, json_decode('true')) |
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 call assert_equal("", json_decode('""')) |
7718
6ebd8bdf41bc
commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents:
7712
diff
changeset
|
144 |
10839
287049007bbc
patch 8.0.0309: cannot use an empty key in json
Christian Brabandt <cb@256bit.org>
parents:
10581
diff
changeset
|
145 " 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
|
146 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
|
147 " but not twice |
287049007bbc
patch 8.0.0309: cannot use an empty key in json
Christian Brabandt <cb@256bit.org>
parents:
10581
diff
changeset
|
148 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
|
149 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 |
20492
947e50e438d3
patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 |
20492
947e50e438d3
patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 call assert_fails('call json_decode("{-}")', "E491:") |
7732
4a4f1dd1abe8
commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents:
7718
diff
changeset
|
168 |
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("[foobar]")', "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("[")', "E491:") |
947e50e438d3
patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 |
20492
947e50e438d3
patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
175 call assert_fails('call json_decode("[1,,2]")', "E491:") |
13456
7495e3ee1a69
patch 8.0.1602: crash in parsing JSON
Christian Brabandt <cb@256bit.org>
parents:
13031
diff
changeset
|
176 |
20492
947e50e438d3
patch 8.2.0800: errors from failing test are unclear
Bram Moolenaar <Bram@vim.org>
parents:
17916
diff
changeset
|
177 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
|
178 call assert_fails('call json_decode("{[]:42}")', "E491:") |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16306
diff
changeset
|
179 |
20492
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("\"\\u111Z\"")', 'E491:') |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16306
diff
changeset
|
181 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
|
182 call assert_equal('a😂b', json_decode('"a\uD83D\uDE02b"')) |
7712
bce3b5ddb393
commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
183 endfunc |
7967
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
184 |
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
185 let s:jsl5 = '[7,,,]' |
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
186 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
|
187 |
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
188 func Test_js_encode() |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 |
15607
2dcaa860e3fc
patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15446
diff
changeset
|
195 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
|
196 " 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
|
197 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
198 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
|
199 if has('float') |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 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
|
204 endif |
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
205 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 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
|
214 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
215 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
|
216 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
217 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
|
218 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
|
219 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
220 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
|
221 call assert_equal("", res) |
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
222 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
223 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
|
224 endfunc |
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
225 |
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
226 func Test_js_decode() |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 |
15607
2dcaa860e3fc
patch 8.1.0811: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15446
diff
changeset
|
233 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
|
234 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
|
235 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
|
236 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
237 call assert_equal(s:varnr, js_decode(s:jsonnr)) |
7967
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
238 if has('float') |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 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
|
243 endif |
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 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
|
246 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
|
247 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
|
248 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
|
249 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
261 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
|
262 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 call assert_equal("", js_decode("''")) |
7967
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
269 |
10563
bac9cec298ed
patch 8.0.0171: JS style JSON does not support single quotes
Christian Brabandt <cb@256bit.org>
parents:
10553
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 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
|
278 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
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("[foobar]")', "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("[")', "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("[1")', "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("[1,")', "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("[1 2]")', "E474:") |
7967
45ea5ebf3a98
commit https://github.com/vim/vim/commit/595e64e259faefb330866852e1b9f6168544572a
Christian Brabandt <cb@256bit.org>
parents:
7965
diff
changeset
|
293 |
8019
d685893d852e
commit https://github.com/vim/vim/commit/7823a3bd2eed6ff9e544d201de96710bd5344aaf
Christian Brabandt <cb@256bit.org>
parents:
7967
diff
changeset
|
294 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
|
295 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
|
296 |
a2c598cbe220
patch 8.1.1158: json encoded string is sometimes missing the final NUL
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
297 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
|
298 " 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
|
299 " 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
|
300 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
|
301 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
|
302 endfunc |