comparison src/testdir/test_vim9_script.vim @ 20472:1338b4dcb885 v8.2.0790

patch 8.2.0790: Vim9: list index not well tested Commit: https://github.com/vim/vim/commit/843700875e50c03c94245bef1b2de147b9b3b585 Author: Bram Moolenaar <Bram@vim.org> Date: Mon May 18 14:20:36 2020 +0200 patch 8.2.0790: Vim9: list index not well tested Problem: Vim9: list index not well tested. Solution: Add a few more tests.
author Bram Moolenaar <Bram@vim.org>
date Mon, 18 May 2020 14:30:04 +0200
parents 61d2eb1413f2
children 7fb80f486aad
comparison
equal deleted inserted replaced
20471:5c2d85d852f1 20472:1338b4dcb885
21 let bool1: bool = true 21 let bool1: bool = true
22 assert_equal(v:true, bool1) 22 assert_equal(v:true, bool1)
23 let bool2: bool = false 23 let bool2: bool = false
24 assert_equal(v:false, bool2) 24 assert_equal(v:false, bool2)
25 25
26 let list1: list<bool> = [false, true, false]
27 let list2: list<number> = [1, 2, 3]
28 let list3: list<string> = ['sdf', 'asdf']
29 let list4: list<any> = ['yes', true, 1234]
30 let list5: list<blob> = [0z01, 0z02]
31
32 let listS: list<string> = []
33 let listN: list<number> = []
34
35 let dict1: dict<bool> = #{one: false, two: true}
36 let dict2: dict<number> = #{one: 1, two: 2}
37 let dict3: dict<string> = #{key: 'value'}
38 let dict4: dict<any> = #{one: 1, two: '2'}
39 let dict5: dict<blob> = #{one: 0z01, tw: 0z02}
40
41 call CheckDefFailure(['let x:string'], 'E1069:') 26 call CheckDefFailure(['let x:string'], 'E1069:')
42 call CheckDefFailure(['let x:string = "x"'], 'E1069:') 27 call CheckDefFailure(['let x:string = "x"'], 'E1069:')
43 call CheckDefFailure(['let a:string = "x"'], 'E1069:') 28 call CheckDefFailure(['let a:string = "x"'], 'E1069:')
44 29
45 let a: number = 6 30 let a: number = 6
54 let float1: float = 3.4 39 let float1: float = 3.4
55 endif 40 endif
56 let Funky1: func 41 let Funky1: func
57 let Funky2: func = function('len') 42 let Funky2: func = function('len')
58 let Party2: func = funcref('g:Test_syntax') 43 let Party2: func = funcref('g:Test_syntax')
59
60 # type becomes list<any>
61 let somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c']
62 # type becomes dict<any>
63 let somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'}
64 44
65 g:newvar = 'new' 45 g:newvar = 'new'
66 assert_equal('new', g:newvar) 46 assert_equal('new', g:newvar)
67 47
68 assert_equal('yes', g:existing) 48 assert_equal('yes', g:existing)
124 v:errmsg = 'none' 104 v:errmsg = 'none'
125 v:errmsg ..= 'again' 105 v:errmsg ..= 'again'
126 assert_equal('noneagain', v:errmsg) 106 assert_equal('noneagain', v:errmsg)
127 call CheckDefFailure(['v:errmsg += "more"'], 'E1013:') 107 call CheckDefFailure(['v:errmsg += "more"'], 'E1013:')
128 call CheckDefFailure(['v:errmsg += 123'], 'E1013:') 108 call CheckDefFailure(['v:errmsg += 123'], 'E1013:')
109 enddef
110
111 def Test_assignment_list()
112 let list1: list<bool> = [false, true, false]
113 let list2: list<number> = [1, 2, 3]
114 let list3: list<string> = ['sdf', 'asdf']
115 let list4: list<any> = ['yes', true, 1234]
116 let list5: list<blob> = [0z01, 0z02]
117
118 let listS: list<string> = []
119 let listN: list<number> = []
120
121 assert_equal([1, 2, 3], list2)
122 list2[-1] = 99
123 assert_equal([1, 2, 99], list2)
124 list2[-2] = 88
125 assert_equal([1, 88, 99], list2)
126 list2[-3] = 77
127 assert_equal([77, 88, 99], list2)
128 call CheckDefExecFailure(['let ll = [1, 2, 3]', 'll[-4] = 6'], 'E684:')
129
130 # type becomes list<any>
131 let somelist = rand() > 0 ? [1, 2, 3] : ['a', 'b', 'c']
132 enddef
133
134 def Test_assignment_dict()
135 let dict1: dict<bool> = #{one: false, two: true}
136 let dict2: dict<number> = #{one: 1, two: 2}
137 let dict3: dict<string> = #{key: 'value'}
138 let dict4: dict<any> = #{one: 1, two: '2'}
139 let dict5: dict<blob> = #{one: 0z01, tw: 0z02}
140
141 call CheckDefExecFailure(['let dd = {}', 'dd[""] = 6'], 'E713:')
142
143 # type becomes dict<any>
144 let somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'}
129 enddef 145 enddef
130 146
131 def Test_assignment_local() 147 def Test_assignment_local()
132 " Test in a separated file in order not to the current buffer/window/tab is 148 " Test in a separated file in order not to the current buffer/window/tab is
133 " changed. 149 " changed.