comparison src/testdir/test_json.vim @ 7732:4a4f1dd1abe8 v7.4.1164

commit https://github.com/vim/vim/commit/6039c7f05376f0e470cf62bf2757e653aea357f3 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 24 15:05:32 2016 +0100 patch 7.4.1164 Problem: No tests for comparing special variables. Error in jsondecode() not reported. test_json does not work Japanse system. Solution: Set scriptencoding. (Ken Takata) Add a few more tests. Add error.
author Christian Brabandt <cb@256bit.org>
date Sun, 24 Jan 2016 15:15:04 +0100
parents 6ebd8bdf41bc
children f2ddad8cbce7
comparison
equal deleted inserted replaced
7731:c0b0e9255b13 7732:4a4f1dd1abe8
1 " Test for JSON functions. 1 " Test for JSON functions.
2 scriptencoding utf-8
2 3
3 let s:json1 = '"str\"in\\g"' 4 let s:json1 = '"str\"in\\g"'
4 let s:var1 = "str\"in\\g" 5 let s:var1 = "str\"in\\g"
5 let s:json2 = '"\u0001\u0002\u0003\u0004\u0005\u0006\u0007"' 6 let s:json2 = '"\u0001\u0002\u0003\u0004\u0005\u0006\u0007"'
6 let s:var2 = "\x01\x02\x03\x04\x05\x06\x07" 7 let s:var2 = "\x01\x02\x03\x04\x05\x06\x07"
93 call assert_equal(type(v:true), type(jsondecode('true'))) 94 call assert_equal(type(v:true), type(jsondecode('true')))
94 call assert_equal(v:none, jsondecode('')) 95 call assert_equal(v:none, jsondecode(''))
95 call assert_equal(type(v:none), type(jsondecode(''))) 96 call assert_equal(type(v:none), type(jsondecode('')))
96 call assert_equal("", jsondecode('""')) 97 call assert_equal("", jsondecode('""'))
97 98
99 call assert_equal({'n': 1}, jsondecode('{"n":1,}'))
100
98 call assert_fails('call jsondecode("\"")', "E474:") 101 call assert_fails('call jsondecode("\"")', "E474:")
99 call assert_fails('call jsondecode("{-}")', "E474:")
100 call assert_fails('call jsondecode("blah")', "E474:") 102 call assert_fails('call jsondecode("blah")', "E474:")
101 call assert_fails('call jsondecode("true blah")', "E474:") 103 call assert_fails('call jsondecode("true blah")', "E474:")
102 call assert_fails('call jsondecode("<foobar>")', "E474:") 104 call assert_fails('call jsondecode("<foobar>")', "E474:")
105
106 call assert_fails('call jsondecode("{")', "E474:")
107 call assert_fails('call jsondecode("{foobar}")', "E474:")
108 call assert_fails('call jsondecode("{\"n\",")', "E474:")
109 call assert_fails('call jsondecode("{\"n\":")', "E474:")
110 call assert_fails('call jsondecode("{\"n\":1")', "E474:")
111 call assert_fails('call jsondecode("{\"n\":1,")', "E474:")
112 call assert_fails('call jsondecode("{\"n\",1}")', "E474:")
113 call assert_fails('call jsondecode("{-}")', "E474:")
114
103 call assert_fails('call jsondecode("[foobar]")', "E474:") 115 call assert_fails('call jsondecode("[foobar]")', "E474:")
104 call assert_fails('call jsondecode("{foobar}")', "E474:") 116 call assert_fails('call jsondecode("[")', "E474:")
117 call assert_fails('call jsondecode("[1")', "E474:")
118 call assert_fails('call jsondecode("[1,")', "E474:")
119 call assert_fails('call jsondecode("[1 2]")', "E474:")
105 endfunc 120 endfunc