annotate src/testdir/test_json.vim @ 7877:7fbd2de703a9 v7.4.1235

commit https://github.com/vim/vim/commit/11e0afa00a8e6c0aa1d50f760b5d5cb62dade038 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Feb 1 22:41:00 2016 +0100 patch 7.4.1235 Problem: Missing change to eval.c. Solution: Include that change.
author Christian Brabandt <cb@256bit.org>
date Mon, 01 Feb 2016 22:45:06 +0100
parents f2ddad8cbce7
children b2922673917a
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.
7732
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
2 scriptencoding utf-8
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 let s:json1 = '"str\"in\\g"'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 let s:var1 = "str\"in\\g"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 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
7 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
8 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
9 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
10 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
11 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
12 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
13 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
14
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 let s:jsonmb = '"s¢cĴgё"'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 let s:varmb = "s¢cĴgё"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 let s:jsonnr = '1234'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 let s:varnr = 1234
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 let s:jsonfl = '12.34'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 let s:varfl = 12.34
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 let s:jsonl1 = '[1,"a",3]'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 let s:varl1 = [1, "a", 3]
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 let s:jsonl2 = '[1,["a",[],"c"],3]'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 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
26 let s:varl2 = [1, 2, 3]
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 let l2 = ['a', s:varl2, 'c']
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 let s:varl2[1] = l2
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 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
30 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
31 let l3 = [1, 2]
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
32 let s:varl3 = [l3, l3]
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 let s:jsond1 = '{"a":1,"b":"bee","c":[1,2]}'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 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
36 let s:jsond2 = '{"1":1,"2":{"a":"aa","b":{},"c":"cc"},"3":3}'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 let s:jsond2s = " { \"1\" : 1 , \"2\" :\n{ \"a\"\r: \"aa\" , \"b\" : {\<Tab>} , \"c\" : \"cc\" } , \"3\" : 3 }\r\n"
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 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
39 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
40 let s:vard2["2"] = d2
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 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
42 let d3 = {"a": 1, "b": 2}
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
43 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
44 let s:jsond3 = '{"x":{"a":1,"b":2},"y":{"a":1,"b":2}}'
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 let s:jsonvals = '[true,false,,null]'
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 let s:varvals = [v:true, v:false, v:none, v:null]
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 func Test_encode()
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 call assert_equal(s:json1, jsonencode(s:var1))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 call assert_equal(s:json2, jsonencode(s:var2))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 call assert_equal(s:json3, jsonencode(s:var3))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 call assert_equal(s:json4, jsonencode(s:var4))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 call assert_equal(s:json5, jsonencode(s:var5))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 if has('multi_byte')
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 call assert_equal(s:jsonmb, jsonencode(s:varmb))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 endif
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 call assert_equal(s:jsonnr, jsonencode(s:varnr))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 if has('float')
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 call assert_equal(s:jsonfl, jsonencode(s:varfl))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 endif
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 call assert_equal(s:jsonl1, jsonencode(s:varl1))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 call assert_equal(s:jsonl2, jsonencode(s:varl2))
7736
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
67 call assert_equal(s:jsonl3, jsonencode(s:varl3))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 call assert_equal(s:jsond1, jsonencode(s:vard1))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 call assert_equal(s:jsond2, jsonencode(s:vard2))
7736
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
71 call assert_equal(s:jsond3, jsonencode(s:vard3))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 call assert_equal(s:jsonvals, jsonencode(s:varvals))
7736
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
74
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
75 call assert_fails('echo jsonencode(function("tr"))', 'E474:')
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
76 call assert_fails('echo jsonencode([function("tr")])', 'E474:')
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 endfunc
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 func Test_decode()
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 call assert_equal(s:var1, jsondecode(s:json1))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 call assert_equal(s:var2, jsondecode(s:json2))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 call assert_equal(s:var3, jsondecode(s:json3))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 call assert_equal(s:var4, jsondecode(s:json4))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 call assert_equal(s:var5, jsondecode(s:json5))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 if has('multi_byte')
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 call assert_equal(s:varmb, jsondecode(s:jsonmb))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 endif
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 call assert_equal(s:varnr, jsondecode(s:jsonnr))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 if has('float')
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 call assert_equal(s:varfl, jsondecode(s:jsonfl))
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
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 call assert_equal(s:varl1, jsondecode(s:jsonl1))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 call assert_equal(s:varl2x, jsondecode(s:jsonl2))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 call assert_equal(s:varl2x, jsondecode(s:jsonl2s))
7736
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
98 call assert_equal(s:varl3, jsondecode(s:jsonl3))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 call assert_equal(s:vard1, jsondecode(s:jsond1))
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 call assert_equal(s:vard2x, jsondecode(s:jsond2))
7736
f2ddad8cbce7 commit https://github.com/vim/vim/commit/fcaaae6b3fdbf3421a1ff95a25ae16d82381c39a
Christian Brabandt <cb@256bit.org>
parents: 7732
diff changeset
102 call assert_equal(s:vard3, jsondecode(s:jsond3))
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 call assert_equal(s:varvals, jsondecode(s:jsonvals))
7718
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
105
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
106 call assert_equal(v:true, jsondecode('true'))
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
107 call assert_equal(type(v:true), type(jsondecode('true')))
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
108 call assert_equal(v:none, jsondecode(''))
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
109 call assert_equal(type(v:none), type(jsondecode('')))
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
110 call assert_equal("", jsondecode('""'))
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
111
7732
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
112 call assert_equal({'n': 1}, jsondecode('{"n":1,}'))
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
113
7718
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
114 call assert_fails('call jsondecode("\"")', "E474:")
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
115 call assert_fails('call jsondecode("blah")', "E474:")
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
116 call assert_fails('call jsondecode("true blah")', "E474:")
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
117 call assert_fails('call jsondecode("<foobar>")', "E474:")
7732
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
118
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
119 call assert_fails('call jsondecode("{")', "E474:")
7718
6ebd8bdf41bc commit https://github.com/vim/vim/commit/f95534c3d411084d1b6112fe64f6108bf7acbb92
Christian Brabandt <cb@256bit.org>
parents: 7712
diff changeset
120 call assert_fails('call jsondecode("{foobar}")', "E474:")
7732
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
121 call assert_fails('call jsondecode("{\"n\",")', "E474:")
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
122 call assert_fails('call jsondecode("{\"n\":")', "E474:")
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
123 call assert_fails('call jsondecode("{\"n\":1")', "E474:")
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
124 call assert_fails('call jsondecode("{\"n\":1,")', "E474:")
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
125 call assert_fails('call jsondecode("{\"n\",1}")', "E474:")
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
126 call assert_fails('call jsondecode("{-}")', "E474:")
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
127
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
128 call assert_fails('call jsondecode("[foobar]")', "E474:")
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
129 call assert_fails('call jsondecode("[")', "E474:")
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
130 call assert_fails('call jsondecode("[1")', "E474:")
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
131 call assert_fails('call jsondecode("[1,")', "E474:")
4a4f1dd1abe8 commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3
Christian Brabandt <cb@256bit.org>
parents: 7718
diff changeset
132 call assert_fails('call jsondecode("[1 2]")', "E474:")
7712
bce3b5ddb393 commit https://github.com/vim/vim/commit/520e1e41f35b063ede63b41738c82d6636e78c34
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 endfunc