annotate src/testdir/test_vim9_builtin.vim @ 24258:8b4159943d9a v8.2.2670

patch 8.2.2670: Vim9: error for append(0, text) Commit: https://github.com/vim/vim/commit/b2ac7d0663ef31a335c50c6afca042ed9ace5059 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 28 15:46:16 2021 +0200 patch 8.2.2670: Vim9: error for append(0, text) Problem: Vim9: error for append(0, text). Solution: Check for negative number. (closes https://github.com/vim/vim/issues/8022)
author Bram Moolenaar <Bram@vim.org>
date Sun, 28 Mar 2021 16:00:03 +0200
parents 0868ac82ef18
children 21c72f782ae1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Test using builtin functions in the Vim9 script language.
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 source check.vim
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 source vim9.vim
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 " Test for passing too many or too few arguments to builtin functions
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 func Test_internalfunc_arg_error()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 let l =<< trim END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 def! FArgErr(): float
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 return ceil(1.1, 2)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 defcompile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 call writefile(l, 'Xinvalidarg')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 call assert_fails('so Xinvalidarg', 'E118:', '', 1, 'FArgErr')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 let l =<< trim END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 def! FArgErr(): float
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 return ceil()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 defcompile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 call writefile(l, 'Xinvalidarg')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 call assert_fails('so Xinvalidarg', 'E119:', '', 1, 'FArgErr')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 call delete('Xinvalidarg')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 endfunc
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 " Test for builtin functions returning different types
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 func Test_InternalFuncRetType()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 let lines =<< trim END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 def RetFloat(): float
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 return ceil(1.456)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 def RetListAny(): list<any>
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
35 return items({k: 'v'})
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 def RetListString(): list<string>
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 return split('a:b:c', ':')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 def RetListDictAny(): list<dict<any>>
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 return getbufinfo()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 def RetDictNumber(): dict<number>
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 return wordcount()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 def RetDictString(): dict<string>
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 return environ()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 call writefile(lines, 'Xscript')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 source Xscript
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 call RetFloat()->assert_equal(2.0)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 call RetListAny()->assert_equal([['k', 'v']])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 call RetListString()->assert_equal(['a', 'b', 'c'])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 call RetListDictAny()->assert_notequal([])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 call RetDictNumber()->assert_notequal({})
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 call RetDictString()->assert_notequal({})
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 call delete('Xscript')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 endfunc
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 def Test_abs()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 assert_equal(0, abs(0))
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 assert_equal(2, abs(-2))
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 assert_equal(3, abs(3))
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 CheckDefFailure(['abs("text")'], 'E1013: Argument 1: type mismatch, expected number but got string', 1)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 if has('float')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 assert_equal(0, abs(0))
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 assert_equal(2.0, abs(-2.0))
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 assert_equal(3.0, abs(3.0))
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 endif
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 def Test_add_list()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 var l: list<number> # defaults to empty list
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 add(l, 9)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 assert_equal([9], l)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 var lines =<< trim END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 var l: list<number>
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 add(l, "x")
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 CheckDefFailure(lines, 'E1012:', 2)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 lines =<< trim END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 var l: list<number> = test_null_list()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 add(l, 123)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 CheckDefExecFailure(lines, 'E1130:', 2)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 def Test_add_blob()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 var b1: blob = 0z12
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 add(b1, 0x34)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 assert_equal(0z1234, b1)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 var b2: blob # defaults to empty blob
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 add(b2, 0x67)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 assert_equal(0z67, b2)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 var lines =<< trim END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 var b: blob
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 add(b, "x")
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 CheckDefFailure(lines, 'E1012:', 2)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 lines =<< trim END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 var b: blob = test_null_blob()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 add(b, 123)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 END
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 CheckDefExecFailure(lines, 'E1131:', 2)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117
23654
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
118 def Test_append()
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
119 new
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
120 setline(1, range(3))
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
121 var res1: number = append(1, 'one')
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
122 assert_equal(0, res1)
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
123 var res2: bool = append(3, 'two')
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
124 assert_equal(false, res2)
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
125 assert_equal(['0', 'one', '1', 'two', '2'], getline(1, 6))
24258
8b4159943d9a patch 8.2.2670: Vim9: error for append(0, text)
Bram Moolenaar <Bram@vim.org>
parents: 24254
diff changeset
126
8b4159943d9a patch 8.2.2670: Vim9: error for append(0, text)
Bram Moolenaar <Bram@vim.org>
parents: 24254
diff changeset
127 append(0, 'zero')
8b4159943d9a patch 8.2.2670: Vim9: error for append(0, text)
Bram Moolenaar <Bram@vim.org>
parents: 24254
diff changeset
128 assert_equal('zero', getline(1))
8b4159943d9a patch 8.2.2670: Vim9: error for append(0, text)
Bram Moolenaar <Bram@vim.org>
parents: 24254
diff changeset
129 bwipe!
23654
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
130 enddef
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
131
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
132 def Test_balloon_show()
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
133 CheckGui
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
134 CheckFeature balloon_eval
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
135
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
136 assert_fails('balloon_show(true)', 'E1174:')
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
137 enddef
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
138
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
139 def Test_balloon_split()
24248
883d7ceffd97 patch 8.2.2665: test failures
Bram Moolenaar <Bram@vim.org>
parents: 24246
diff changeset
140 CheckFeature balloon_eval_term
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
141
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
142 assert_fails('balloon_split(true)', 'E1174:')
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
143 enddef
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
144
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
145 def Test_browse()
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
146 CheckFeature browse
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
147
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
148 var lines =<< trim END
24254
0868ac82ef18 patch 8.2.2668: Vim9: omitting "call" for "confirm()" does not give an error
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
149 browse(1, 2, 3, 4)
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
150 END
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
151 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 2')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
152 lines =<< trim END
24254
0868ac82ef18 patch 8.2.2668: Vim9: omitting "call" for "confirm()" does not give an error
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
153 browse(1, 'title', 3, 4)
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
154 END
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
155 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 3')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
156 lines =<< trim END
24254
0868ac82ef18 patch 8.2.2668: Vim9: omitting "call" for "confirm()" does not give an error
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
157 browse(1, 'title', 'dir', 4)
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
158 END
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
159 CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 4')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
160 enddef
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
161
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
162 def Test_bufexists()
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
163 assert_fails('bufexists(true)', 'E1174')
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
164 enddef
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
165
23654
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
166 def Test_buflisted()
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
167 var res: bool = buflisted('asdf')
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
168 assert_equal(false, res)
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
169 assert_fails('buflisted(true)', 'E1174')
23654
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
170 enddef
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
171
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 def Test_bufname()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 split SomeFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 bufname('%')->assert_equal('SomeFile')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 edit OtherFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 bufname('#')->assert_equal('SomeFile')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 close
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 def Test_bufnr()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 var buf = bufnr()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 bufnr('%')->assert_equal(buf)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 buf = bufnr('Xdummy', true)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 buf->assert_notequal(-1)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 exe 'bwipe! ' .. buf
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 def Test_bufwinid()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 var origwin = win_getid()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 below split SomeFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 var SomeFileID = win_getid()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 below split OtherFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 below split SomeFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 bufwinid('SomeFile')->assert_equal(SomeFileID)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 win_gotoid(origwin)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 only
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 bwipe SomeFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 bwipe OtherFile
24246
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
201
35603c7991d7 patch 8.2.2664: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24222
diff changeset
202 assert_fails('bufwinid(true)', 'E1138')
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 def Test_call_call()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 var l = [3, 2, 1]
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 call('reverse', [l])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 l->assert_equal([1, 2, 3])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210
24250
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
211 def Test_ch_logfile()
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
212 assert_fails('ch_logfile(true)', 'E1174')
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
213 assert_fails('ch_logfile("foo", true)', 'E1174')
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
214 enddef
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
215
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 def Test_char2nr()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 char2nr('あ', true)->assert_equal(12354)
24250
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
218
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
219 assert_fails('char2nr(true)', 'E1174')
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
220 enddef
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
221
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
222 def Test_charclass()
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
223 assert_fails('charclass(true)', 'E1174')
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
224 enddef
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
225
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
226 def Test_chdir()
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
227 assert_fails('chdir(true)', 'E1174')
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 def Test_col()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 setline(1, 'asdf')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 col([1, '$'])->assert_equal(5)
24250
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
234
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
235 assert_fails('col(true)', 'E1174')
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
236 enddef
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
237
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
238 def Test_confirm()
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
239 if !has('dialog_con') && !has('dialog_gui')
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
240 CheckFeature dialog_con
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
241 endif
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
242
24254
0868ac82ef18 patch 8.2.2668: Vim9: omitting "call" for "confirm()" does not give an error
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
243 assert_fails('confirm(true)', 'E1174')
0868ac82ef18 patch 8.2.2668: Vim9: omitting "call" for "confirm()" does not give an error
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
244 assert_fails('confirm("yes", true)', 'E1174')
0868ac82ef18 patch 8.2.2668: Vim9: omitting "call" for "confirm()" does not give an error
Bram Moolenaar <Bram@vim.org>
parents: 24250
diff changeset
245 assert_fails('confirm("yes", "maybe", 2, true)', 'E1174')
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 def Test_copy_return_type()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 var l = copy([1, 2, 3])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 var res = 0
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 for n in l
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 res->assert_equal(6)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 var dl = deepcopy([1, 2, 3])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 res = 0
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 for n in dl
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 res->assert_equal(6)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 dl = deepcopy([1, 2, 3], true)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 def Test_count()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 count('ABC ABC ABC', 'b', true)->assert_equal(3)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 count('ABC ABC ABC', 'b', false)->assert_equal(0)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270
23276
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
271 def Test_cursor()
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
272 new
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
273 setline(1, range(4))
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
274 cursor(2, 1)
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
275 assert_equal(2, getcurpos()[1])
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
276 cursor('$', 1)
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
277 assert_equal(4, getcurpos()[1])
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
278
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
279 var lines =<< trim END
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
280 cursor('2', 1)
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
281 END
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
282 CheckDefExecAndScriptFailure(lines, 'E475:')
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
283 enddef
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
284
23654
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
285 def Test_delete()
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
286 var res: bool = delete('doesnotexist')
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
287 assert_equal(true, res)
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
288 enddef
1974c5122506 patch 8.2.2369: Vim9: functions return true/false but can't be used as bool
Bram Moolenaar <Bram@vim.org>
parents: 23646
diff changeset
289
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
290 def Test_executable()
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
291 assert_false(executable(""))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
292 assert_false(executable(test_null_string()))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
293
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
294 CheckDefExecFailure(['echo executable(123)'], 'E1174:')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
295 CheckDefExecFailure(['echo executable(true)'], 'E1174:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
296 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
297
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
298 def Test_exepath()
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
299 CheckDefExecFailure(['echo exepath(true)'], 'E1174:')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
300 CheckDefExecFailure(['echo exepath(v:null)'], 'E1174:')
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
301 CheckDefExecFailure(['echo exepath("")'], 'E1175:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
302 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
303
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 def Test_expand()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 split SomeFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 expand('%', true, true)->assert_equal(['SomeFile'])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 close
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309
22766
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
310 def Test_extend_arg_types()
23800
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
311 g:number_one = 1
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
312 g:string_keep = 'keep'
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
313 var lines =<< trim END
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
314 assert_equal([1, 2, 3], extend([1, 2], [3]))
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
315 assert_equal([3, 1, 2], extend([1, 2], [3], 0))
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
316 assert_equal([1, 3, 2], extend([1, 2], [3], 1))
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
317 assert_equal([1, 3, 2], extend([1, 2], [3], g:number_one))
22766
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
318
23800
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
319 assert_equal({a: 1, b: 2, c: 3}, extend({a: 1, b: 2}, {c: 3}))
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
320 assert_equal({a: 1, b: 4}, extend({a: 1, b: 2}, {b: 4}))
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
321 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, 'keep'))
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
322 assert_equal({a: 1, b: 2}, extend({a: 1, b: 2}, {b: 4}, g:string_keep))
22898
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22766
diff changeset
323
23800
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
324 var res: list<dict<any>>
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
325 extend(res, mapnew([1, 2], (_, v) => ({})))
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
326 assert_equal([{}, {}], res)
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
327 END
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
328 CheckDefAndScriptSuccess(lines)
22766
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
329
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
330 CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
331 CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
332 CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
333
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
334 CheckDefFailure(['extend({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
335 CheckDefFailure(['extend({a: 1}, {b: "x"})'], 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>')
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
336 CheckDefFailure(['extend({a: 1}, {b: 2}, 1)'], 'E1013: Argument 3: type mismatch, expected string but got number')
23640
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
337
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
338 CheckDefFailure(['extend([1], ["b"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
23691
0d56d4f107d8 patch 8.2.2387: runtime type check does not mention argument index
Bram Moolenaar <Bram@vim.org>
parents: 23654
diff changeset
339 CheckDefExecFailure(['extend([1], ["b", 1])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<any>')
22766
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
340 enddef
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
341
23588
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
342 def Test_extendnew()
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
343 assert_equal([1, 2, 'a'], extendnew([1, 2], ['a']))
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
344 assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'}))
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
345
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
346 CheckDefFailure(['extendnew({a: 1}, 42)'], 'E1013: Argument 2: type mismatch, expected dict<number> but got number')
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
347 CheckDefFailure(['extendnew({a: 1}, [42])'], 'E1013: Argument 2: type mismatch, expected dict<number> but got list<number>')
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
348 CheckDefFailure(['extendnew([1, 2], "x")'], 'E1013: Argument 2: type mismatch, expected list<number> but got string')
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
349 CheckDefFailure(['extendnew([1, 2], {x: 1})'], 'E1013: Argument 2: type mismatch, expected list<number> but got dict<number>')
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
350 enddef
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
351
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 def Test_extend_return_type()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 var l = extend([1, 2], [3])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 var res = 0
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 for n in l
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 res->assert_equal(6)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
361 func g:ExtendDict(d)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
362 call extend(a:d, #{xx: 'x'})
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
363 endfunc
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
364
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
365 def Test_extend_dict_item_type()
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
366 var lines =<< trim END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
367 var d: dict<number> = {a: 1}
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
368 extend(d, {b: 2})
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
369 END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
370 CheckDefAndScriptSuccess(lines)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
371
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
372 lines =<< trim END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
373 var d: dict<number> = {a: 1}
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
374 extend(d, {b: 'x'})
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
375 END
23800
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
376 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>', 2)
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
377
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
378 lines =<< trim END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
379 var d: dict<number> = {a: 1}
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
380 g:ExtendDict(d)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
381 END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
382 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
383 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
384 enddef
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
385
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
386 func g:ExtendList(l)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
387 call extend(a:l, ['x'])
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
388 endfunc
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
389
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
390 def Test_extend_list_item_type()
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
391 var lines =<< trim END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
392 var l: list<number> = [1]
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
393 extend(l, [2])
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
394 END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
395 CheckDefAndScriptSuccess(lines)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
396
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
397 lines =<< trim END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
398 var l: list<number> = [1]
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
399 extend(l, ['x'])
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
400 END
23800
57f0e3fd7c05 patch 8.2.2441: Vim9: extend() does not give an error for a type mismatch
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
401 CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>', 2)
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
402
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
403 lines =<< trim END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
404 var l: list<number> = [1]
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
405 g:ExtendList(l)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
406 END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
407 CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got string', 0)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
408 CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
409 enddef
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410
24118
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
411 def Test_extend_with_error_function()
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
412 var lines =<< trim END
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
413 vim9script
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
414 def F()
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
415 {
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
416 var m = 10
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
417 }
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
418 echo m
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
419 enddef
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
420
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
421 def Test()
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
422 var d: dict<any> = {}
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
423 d->extend({A: 10, Func: function('F', [])})
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
424 enddef
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
425
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
426 Test()
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
427 END
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
428 CheckScriptFailure(lines, 'E1001: Variable not found: m')
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
429 enddef
1027495445bc patch 8.2.2600: Vim9: crash when putting an unknown type in a dictionary
Bram Moolenaar <Bram@vim.org>
parents: 24083
diff changeset
430
23592
2322b643e329 patch 8.2.2338: Vim9: no error if using job_info() result wrongly
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
431 def Test_job_info_return_type()
2322b643e329 patch 8.2.2338: Vim9: no error if using job_info() result wrongly
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
432 if has('job')
2322b643e329 patch 8.2.2338: Vim9: no error if using job_info() result wrongly
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
433 job_start(&shell)
2322b643e329 patch 8.2.2338: Vim9: no error if using job_info() result wrongly
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
434 var jobs = job_info()
23594
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23592
diff changeset
435 assert_equal('list<job>', typename(jobs))
d3e064f54890 patch 8.2.2339: cannot get the type of a value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23592
diff changeset
436 assert_equal('dict<any>', typename(job_info(jobs[0])))
23592
2322b643e329 patch 8.2.2338: Vim9: no error if using job_info() result wrongly
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
437 job_stop(jobs[0])
2322b643e329 patch 8.2.2338: Vim9: no error if using job_info() result wrongly
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
438 endif
2322b643e329 patch 8.2.2338: Vim9: no error if using job_info() result wrongly
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
439 enddef
2322b643e329 patch 8.2.2338: Vim9: no error if using job_info() result wrongly
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
440
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
441 def Test_filereadable()
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
442 assert_false(filereadable(""))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
443 assert_false(filereadable(test_null_string()))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
444
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
445 CheckDefExecFailure(['echo filereadable(123)'], 'E1174:')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
446 CheckDefExecFailure(['echo filereadable(true)'], 'E1174:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
447 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
448
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
449 def Test_filewritable()
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
450 assert_false(filewritable(""))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
451 assert_false(filewritable(test_null_string()))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
452
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
453 CheckDefExecFailure(['echo filewritable(123)'], 'E1174:')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
454 CheckDefExecFailure(['echo filewritable(true)'], 'E1174:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
455 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
456
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
457 def Test_finddir()
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
458 CheckDefExecFailure(['echo finddir(true)'], 'E1174:')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
459 CheckDefExecFailure(['echo finddir(v:null)'], 'E1174:')
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
460 CheckDefExecFailure(['echo finddir("")'], 'E1175:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
461 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
462
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
463 def Test_findfile()
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
464 CheckDefExecFailure(['echo findfile(true)'], 'E1174:')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
465 CheckDefExecFailure(['echo findfile(v:null)'], 'E1174:')
24222
a2e6029d354e patch 8.2.2652: Vim9: can use command modifier without an effect
Bram Moolenaar <Bram@vim.org>
parents: 24210
diff changeset
466 CheckDefExecFailure(['echo findfile("")'], 'E1175:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
467 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
468
23816
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
469 def Test_flattennew()
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
470 var lines =<< trim END
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
471 var l = [1, [2, [3, 4]], 5]
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
472 call assert_equal([1, 2, 3, 4, 5], flattennew(l))
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
473 call assert_equal([1, [2, [3, 4]], 5], l)
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
474
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
475 call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1))
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
476 call assert_equal([1, [2, [3, 4]], 5], l)
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
477 END
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
478 CheckDefAndScriptSuccess(lines)
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
479
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
480 lines =<< trim END
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
481 echo flatten([1, 2, 3])
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
482 END
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
483 CheckDefAndScriptFailure(lines, 'E1158:')
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
484 enddef
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
485
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
486 def Test_fnamemodify()
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
487 CheckDefSuccess(['echo fnamemodify(test_null_string(), ":p")'])
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
488 CheckDefSuccess(['echo fnamemodify("", ":p")'])
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
489 CheckDefSuccess(['echo fnamemodify("file", test_null_string())'])
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
490 CheckDefSuccess(['echo fnamemodify("file", "")'])
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
491
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
492 CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E1174: String required for argument 1')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
493 CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E1174: String required for argument 1')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
494 CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E1174: String required for argument 2')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
495 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
496
23827
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
497 def Wrong_dict_key_type(items: list<number>): list<number>
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
498 return filter(items, (_, val) => get({[val]: 1}, 'x'))
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
499 enddef
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
500
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 def Test_filter_wrong_dict_key_type()
23827
7e0d8f1cae7d patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 23816
diff changeset
502 assert_fails('Wrong_dict_key_type([1, v:null, 3])', 'E1013:')
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 def Test_filter_return_type()
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
506 var l = filter([1, 2, 3], () => 1)
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 var res = 0
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 for n in l
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 res->assert_equal(6)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513
23350
9b86957ddd95 patch 8.2.2218: Vim9: failure if passing more args to lambda than expected
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
514 def Test_filter_missing_argument()
9b86957ddd95 patch 8.2.2218: Vim9: failure if passing more args to lambda than expected
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
515 var dict = {aa: [1], ab: [2], ac: [3], de: [4]}
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
516 var res = dict->filter((k) => k =~ 'a' && k !~ 'b')
23350
9b86957ddd95 patch 8.2.2218: Vim9: failure if passing more args to lambda than expected
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
517 res->assert_equal({aa: [1], ac: [3]})
9b86957ddd95 patch 8.2.2218: Vim9: failure if passing more args to lambda than expected
Bram Moolenaar <Bram@vim.org>
parents: 23276
diff changeset
518 enddef
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 def Test_garbagecollect()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 garbagecollect(true)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 def Test_getbufinfo()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 var bufinfo = getbufinfo(bufnr())
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 getbufinfo('%')->assert_equal(bufinfo)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 edit Xtestfile1
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 hide edit Xtestfile2
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 hide enew
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
531 getbufinfo({bufloaded: true, buflisted: true, bufmodified: false})
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 ->len()->assert_equal(3)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 bwipe Xtestfile1 Xtestfile2
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 def Test_getbufline()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 e SomeFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 var buf = bufnr()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 e #
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 var lines = ['aaa', 'bbb', 'ccc']
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 setbufline(buf, 1, lines)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 getbufline('#', 1, '$')->assert_equal(lines)
22679
9fa3f92248f6 patch 8.2.1888: Vim9: getbufline(-1, 1, '$') gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
543 getbufline(-1, '$', '$')->assert_equal([])
9fa3f92248f6 patch 8.2.1888: Vim9: getbufline(-1, 1, '$') gives an error
Bram Moolenaar <Bram@vim.org>
parents: 22661
diff changeset
544 getbufline(-1, 1, '$')->assert_equal([])
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 bwipe!
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 def Test_getchangelist()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 setline(1, 'some text')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 var changelist = bufnr()->getchangelist()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 getchangelist('%')->assert_equal(changelist)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 bwipe!
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 def Test_getchar()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 while getchar(0)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 endwhile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 getchar(true)->assert_equal(0)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562
24083
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
563 def Test_getenv()
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
564 if getenv('does-not_exist') == ''
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
565 assert_report('getenv() should return null')
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
566 endif
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
567 if getenv('does-not_exist') == null
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
568 else
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
569 assert_report('getenv() should return null')
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
570 endif
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
571 $SOMEENVVAR = 'some'
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
572 assert_equal('some', getenv('SOMEENVVAR'))
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
573 unlet $SOMEENVVAR
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
574 enddef
1765b5b0f08d patch 8.2.2583: Vim9: cannot compare result of getenv() with null
Bram Moolenaar <Bram@vim.org>
parents: 23990
diff changeset
575
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 def Test_getcompletion()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 set wildignore=*.vim,*~
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 var l = getcompletion('run', 'file', true)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 l->assert_equal([])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 set wildignore&
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 def Test_getloclist_return_type()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 var l = getloclist(1)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 l->assert_equal([])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
587 var d = getloclist(1, {items: 0})
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
588 d->assert_equal({items: []})
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
591 def Test_getfperm()
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
592 assert_equal('', getfperm(""))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
593 assert_equal('', getfperm(test_null_string()))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
594
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
595 CheckDefExecFailure(['echo getfperm(true)'], 'E1174:')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
596 CheckDefExecFailure(['echo getfperm(v:null)'], 'E1174:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
597 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
598
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
599 def Test_getfsize()
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
600 assert_equal(-1, getfsize(""))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
601 assert_equal(-1, getfsize(test_null_string()))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
602
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
603 CheckDefExecFailure(['echo getfsize(true)'], 'E1174:')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
604 CheckDefExecFailure(['echo getfsize(v:null)'], 'E1174:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
605 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
606
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
607 def Test_getftime()
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
608 assert_equal(-1, getftime(""))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
609 assert_equal(-1, getftime(test_null_string()))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
610
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
611 CheckDefExecFailure(['echo getftime(true)'], 'E1174:')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
612 CheckDefExecFailure(['echo getftime(v:null)'], 'E1174:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
613 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
614
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
615 def Test_getftype()
23175
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
616 assert_equal('', getftype(""))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
617 assert_equal('', getftype(test_null_string()))
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
618
24210
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
619 CheckDefExecFailure(['echo getftype(true)'], 'E1174:')
083f07f99e20 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument
Bram Moolenaar <Bram@vim.org>
parents: 24118
diff changeset
620 CheckDefExecFailure(['echo getftype(v:null)'], 'E1174:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
621 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
622
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 def Test_getqflist_return_type()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 var l = getqflist()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 l->assert_equal([])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
627 var d = getqflist({items: 0})
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
628 d->assert_equal({items: []})
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 def Test_getreg()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 var lines = ['aaa', 'bbb', 'ccc']
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 setreg('a', lines)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 getreg('a', true, true)->assert_equal(lines)
23909
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
635 assert_fails('getreg("ab")', 'E1162:')
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 def Test_getreg_return_type()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 var s1: string = getreg('"')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 var s2: string = getreg('"', 1)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 var s3: list<string> = getreg('"', 1, 1)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643
23909
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
644 def Test_getreginfo()
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
645 var text = 'abc'
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
646 setreg('a', text)
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
647 getreginfo('a')->assert_equal({regcontents: [text], regtype: 'v', isunnamed: false})
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
648 assert_fails('getreginfo("ab")', 'E1162:')
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
649 enddef
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
650
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
651 def Test_getregtype()
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
652 var lines = ['aaa', 'bbb', 'ccc']
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
653 setreg('a', lines)
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
654 getregtype('a')->assert_equal('V')
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
655 assert_fails('getregtype("ab")', 'E1162:')
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
656 enddef
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
657
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 def Test_glob()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim'])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 def Test_globpath()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim'])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 def Test_has()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 has('eval', true)->assert_equal(1)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 def Test_hasmapto()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 hasmapto('foobar', 'i', true)->assert_equal(0)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 iabbrev foo foobar
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 hasmapto('foobar', 'i', true)->assert_equal(1)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 iunabbrev foo
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 def Test_index()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680
22898
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22766
diff changeset
681 let s:number_one = 1
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22766
diff changeset
682 let s:number_two = 2
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22766
diff changeset
683 let s:string_keep = 'keep'
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22766
diff changeset
684
22661
c6b17787a38f patch 8.2.1879: Vim9: argument types of insert() not checked when compiling
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
685 def Test_insert()
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 var l = insert([2, 1], 3)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 var res = 0
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 for n in l
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 res->assert_equal(6)
22661
c6b17787a38f patch 8.2.1879: Vim9: argument types of insert() not checked when compiling
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
692
c6b17787a38f patch 8.2.1879: Vim9: argument types of insert() not checked when compiling
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
693 assert_equal([1, 2, 3], insert([2, 3], 1))
22898
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22766
diff changeset
694 assert_equal([1, 2, 3], insert([2, 3], s:number_one))
22661
c6b17787a38f patch 8.2.1879: Vim9: argument types of insert() not checked when compiling
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
695 assert_equal([1, 2, 3], insert([1, 2], 3, 2))
22898
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22766
diff changeset
696 assert_equal([1, 2, 3], insert([1, 2], 3, s:number_two))
22661
c6b17787a38f patch 8.2.1879: Vim9: argument types of insert() not checked when compiling
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
697 assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a'))
c6b17787a38f patch 8.2.1879: Vim9: argument types of insert() not checked when compiling
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
698 assert_equal(0z1234, insert(0z34, 0x12))
22898
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22766
diff changeset
699
22661
c6b17787a38f patch 8.2.1879: Vim9: argument types of insert() not checked when compiling
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
700 CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1)
c6b17787a38f patch 8.2.1879: Vim9: argument types of insert() not checked when compiling
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
701 CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1)
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 def Test_keys_return_type()
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
705 const var: list<string> = {a: 1, b: 2}->keys()
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 var->assert_equal(['a', 'b'])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708
24250
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
709 def Test_line()
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
710 assert_fails('line(true)', 'E1174')
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
711 enddef
01b274c3f69b patch 8.2.2666: Vim9: not enough function arguments checked for string
Bram Moolenaar <Bram@vim.org>
parents: 24248
diff changeset
712
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 def Test_list2str_str2list_utf8()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 var s = "\u3042\u3044"
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 var l = [0x3042, 0x3044]
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 str2list(s, true)->assert_equal(l)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 list2str(l, true)->assert_equal(s)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 def SID(): number
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 return expand('<SID>')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 ->matchstr('<SNR>\zs\d\+\ze_$')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 ->str2nr()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725
23646
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
726 def Test_map_function_arg()
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
727 var lines =<< trim END
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
728 def MapOne(i: number, v: string): string
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
729 return i .. ':' .. v
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
730 enddef
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
731 var l = ['a', 'b', 'c']
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
732 map(l, MapOne)
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
733 assert_equal(['0:a', '1:b', '2:c'], l)
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
734 END
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
735 CheckDefAndScriptSuccess(lines)
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
736 enddef
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
737
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
738 def Test_map_item_type()
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
739 var lines =<< trim END
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
740 var l = ['a', 'b', 'c']
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
741 map(l, (k, v) => k .. '/' .. v )
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
742 assert_equal(['0/a', '1/b', '2/c'], l)
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
743 END
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
744 CheckDefAndScriptSuccess(lines)
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
745
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
746 lines =<< trim END
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
747 var l: list<number> = [0]
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
748 echo map(l, (_, v) => [])
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
749 END
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
750 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
751
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
752 lines =<< trim END
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
753 var l: list<number> = range(2)
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
754 echo map(l, (_, v) => [])
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
755 END
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
756 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
757
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
758 lines =<< trim END
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
759 var d: dict<number> = {key: 0}
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
760 echo map(d, (_, v) => [])
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
761 END
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
762 CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got list<unknown>', 2)
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
763 enddef
5d77a7587927 patch 8.2.2365: Vim9: no check for map() changing item type at script level
Bram Moolenaar <Bram@vim.org>
parents: 23640
diff changeset
764
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 def Test_maparg()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 var lnum = str2nr(expand('<sflnum>'))
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 map foo bar
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
768 maparg('foo', '', false, true)->assert_equal({
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 lnum: lnum + 1,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 script: 0,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 mode: ' ',
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 silent: 0,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 noremap: 0,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 lhs: 'foo',
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 lhsraw: 'foo',
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 nowait: 0,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 expr: 0,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 sid: SID(),
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 rhs: 'bar',
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 buffer: 0})
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 unmap foo
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 def Test_mapcheck()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 iabbrev foo foobar
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 mapcheck('foo', 'i', true)->assert_equal('foobar')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 iunabbrev foo
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 def Test_maparg_mapset()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 nnoremap <F3> :echo "hit F3"<CR>
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 var mapsave = maparg('<F3>', 'n', false, true)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 mapset('n', false, mapsave)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 nunmap <F3>
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797
23990
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
798 def Test_map_failure()
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
799 CheckFeature job
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
800
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
801 var lines =<< trim END
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
802 vim9script
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
803 writefile([], 'Xtmpfile')
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
804 silent e Xtmpfile
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
805 var d = {[bufnr('%')]: {a: 0}}
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
806 au BufReadPost * Func()
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
807 def Func()
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
808 if d->has_key('')
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
809 endif
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
810 eval d[expand('<abuf>')]->mapnew((_, v: dict<job>) => 0)
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
811 enddef
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
812 e
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
813 END
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
814 CheckScriptFailure(lines, 'E1013:')
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
815 au! BufReadPost
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
816 delete('Xtmpfile')
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
817 enddef
06da0685077b patch 8.2.2537: Vim9: crash when map() fails
Bram Moolenaar <Bram@vim.org>
parents: 23909
diff changeset
818
23705
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
819 def Test_max()
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
820 g:flag = true
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
821 var l1: list<number> = g:flag
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
822 ? [1, max([2, 3])]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
823 : [4, 5]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
824 assert_equal([1, 3], l1)
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
825
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
826 g:flag = false
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
827 var l2: list<number> = g:flag
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
828 ? [1, max([2, 3])]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
829 : [4, 5]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
830 assert_equal([4, 5], l2)
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
831 enddef
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
832
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
833 def Test_min()
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
834 g:flag = true
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
835 var l1: list<number> = g:flag
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
836 ? [1, min([2, 3])]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
837 : [4, 5]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
838 assert_equal([1, 2], l1)
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
839
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
840 g:flag = false
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
841 var l2: list<number> = g:flag
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
842 ? [1, min([2, 3])]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
843 : [4, 5]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
844 assert_equal([4, 5], l2)
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
845 enddef
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
846
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 def Test_nr2char()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 nr2char(97, true)->assert_equal('a')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 def Test_readdir()
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
852 eval expand('sautest')->readdir((e) => e[0] !=# '.')
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
853 eval expand('sautest')->readdirex((e) => e.name[0] !=# '.')
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855
23602
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
856 def Test_readblob()
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
857 var blob = 0z12341234
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
858 writefile(blob, 'Xreadblob')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
859 var read: blob = readblob('Xreadblob')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
860 assert_equal(blob, read)
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
861
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
862 var lines =<< trim END
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
863 var read: list<string> = readblob('Xreadblob')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
864 END
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
865 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1)
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
866 delete('Xreadblob')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
867 enddef
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
868
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
869 def Test_readfile()
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
870 var text = ['aaa', 'bbb', 'ccc']
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
871 writefile(text, 'Xreadfile')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
872 var read: list<string> = readfile('Xreadfile')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
873 assert_equal(text, read)
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
874
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
875 var lines =<< trim END
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
876 var read: dict<string> = readfile('Xreadfile')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
877 END
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
878 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1)
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
879 delete('Xreadfile')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
880 enddef
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
881
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 def Test_remove_return_type()
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
883 var l = remove({one: [1, 2], two: [3, 4]}, 'one')
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 var res = 0
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 for n in l
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 res->assert_equal(3)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 def Test_reverse_return_type()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 var l = reverse([1, 2, 3])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 var res = 0
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 for n in l
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 res->assert_equal(6)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 def Test_search()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 setline(1, ['foo', 'bar'])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 var val = 0
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 # skip expr returns boolean
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
905 search('bar', 'W', 0, 0, () => val == 1)->assert_equal(2)
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 :1
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
907 search('bar', 'W', 0, 0, () => val == 0)->assert_equal(0)
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 # skip expr returns number, only 0 and 1 are accepted
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 :1
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
910 search('bar', 'W', 0, 0, () => 0)->assert_equal(2)
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 :1
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
912 search('bar', 'W', 0, 0, () => 1)->assert_equal(0)
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
913 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
914 assert_fails("search('bar', '', 0, 0, () => -1)", 'E1023:')
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 def Test_searchcount()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 setline(1, "foo bar")
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 :/foo
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
921 searchcount({recompute: true})
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
922 ->assert_equal({
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 exact_match: 1,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 current: 1,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 total: 1,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 maxcount: 99,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 incomplete: 0})
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 bwipe!
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
931 def Test_set_get_bufline()
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
932 # similar to Test_setbufline_getbufline()
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
933 var lines =<< trim END
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
934 new
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
935 var b = bufnr('%')
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
936 hide
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
937 assert_equal(0, setbufline(b, 1, ['foo', 'bar']))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
938 assert_equal(['foo'], getbufline(b, 1))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
939 assert_equal(['bar'], getbufline(b, '$'))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
940 assert_equal(['foo', 'bar'], getbufline(b, 1, 2))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
941 exe "bd!" b
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
942 assert_equal([], getbufline(b, 1, 2))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
943
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
944 split Xtest
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
945 setline(1, ['a', 'b', 'c'])
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
946 b = bufnr('%')
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
947 wincmd w
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
948
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
949 assert_equal(1, setbufline(b, 5, 'x'))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
950 assert_equal(1, setbufline(b, 5, ['x']))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
951 assert_equal(1, setbufline(b, 5, []))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
952 assert_equal(1, setbufline(b, 5, test_null_list()))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
953
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
954 assert_equal(1, 'x'->setbufline(bufnr('$') + 1, 1))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
955 assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
956 assert_equal(1, []->setbufline(bufnr('$') + 1, 1))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
957 assert_equal(1, test_null_list()->setbufline(bufnr('$') + 1, 1))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
958
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
959 assert_equal(['a', 'b', 'c'], getbufline(b, 1, '$'))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
960
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
961 assert_equal(0, setbufline(b, 4, ['d', 'e']))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
962 assert_equal(['c'], b->getbufline(3))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
963 assert_equal(['d'], getbufline(b, 4))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
964 assert_equal(['e'], getbufline(b, 5))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
965 assert_equal([], getbufline(b, 6))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
966 assert_equal([], getbufline(b, 2, 1))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
967
23875
54b583156d53 patch 8.2.2479: set/getbufline test fails without the job feature
Bram Moolenaar <Bram@vim.org>
parents: 23827
diff changeset
968 if has('job')
54b583156d53 patch 8.2.2479: set/getbufline test fails without the job feature
Bram Moolenaar <Bram@vim.org>
parents: 23827
diff changeset
969 setbufline(b, 2, [function('eval'), {key: 123}, test_null_job()])
54b583156d53 patch 8.2.2479: set/getbufline test fails without the job feature
Bram Moolenaar <Bram@vim.org>
parents: 23827
diff changeset
970 assert_equal(["function('eval')",
54b583156d53 patch 8.2.2479: set/getbufline test fails without the job feature
Bram Moolenaar <Bram@vim.org>
parents: 23827
diff changeset
971 "{'key': 123}",
54b583156d53 patch 8.2.2479: set/getbufline test fails without the job feature
Bram Moolenaar <Bram@vim.org>
parents: 23827
diff changeset
972 "no process"],
54b583156d53 patch 8.2.2479: set/getbufline test fails without the job feature
Bram Moolenaar <Bram@vim.org>
parents: 23827
diff changeset
973 getbufline(b, 2, 4))
54b583156d53 patch 8.2.2479: set/getbufline test fails without the job feature
Bram Moolenaar <Bram@vim.org>
parents: 23827
diff changeset
974 endif
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
975
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
976 exe 'bwipe! ' .. b
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
977 END
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
978 CheckDefAndScriptSuccess(lines)
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
979 enddef
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
980
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 def Test_searchdecl()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 searchdecl('blah', true, true)->assert_equal(1)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 def Test_setbufvar()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 setbufvar(bufnr('%'), '&syntax', 'vim')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 &syntax->assert_equal('vim')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 setbufvar(bufnr('%'), '&ts', 16)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 &ts->assert_equal(16)
23483
ce7d6b461660 patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
990 setbufvar(bufnr('%'), '&ai', true)
ce7d6b461660 patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
991 &ai->assert_equal(true)
ce7d6b461660 patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
992 setbufvar(bufnr('%'), '&ft', 'filetype')
ce7d6b461660 patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
993 &ft->assert_equal('filetype')
ce7d6b461660 patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
994
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 settabwinvar(1, 1, '&syntax', 'vam')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 &syntax->assert_equal('vam')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 settabwinvar(1, 1, '&ts', 15)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 &ts->assert_equal(15)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 setlocal ts=8
23485
198ad7ef2420 patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents: 23483
diff changeset
1000 settabwinvar(1, 1, '&list', false)
198ad7ef2420 patch 8.2.2285: Vim9: cannot set an option to a false
Bram Moolenaar <Bram@vim.org>
parents: 23483
diff changeset
1001 &list->assert_equal(false)
23483
ce7d6b461660 patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1002 settabwinvar(1, 1, '&list', true)
ce7d6b461660 patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1003 &list->assert_equal(true)
ce7d6b461660 patch 8.2.2284: Vim9: cannot set an option to a boolean value
Bram Moolenaar <Bram@vim.org>
parents: 23458
diff changeset
1004 setlocal list&
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 setbufvar('%', 'myvar', 123)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 getbufvar('%', 'myvar')->assert_equal(123)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 def Test_setloclist()
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
1011 var items = [{filename: '/tmp/file', lnum: 1, valid: true}]
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
1012 var what = {items: items}
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 setqflist([], ' ', what)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 setloclist(0, [], ' ', what)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 def Test_setreg()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 setreg('a', ['aaa', 'bbb', 'ccc'])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 var reginfo = getreginfo('a')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 setreg('a', reginfo)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 getreginfo('a')->assert_equal(reginfo)
23909
5db7d275543c patch 8.2.2497: no error when using more than one character for a register
Bram Moolenaar <Bram@vim.org>
parents: 23875
diff changeset
1022 assert_fails('setreg("ab", 0)', 'E1162:')
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1025 def Test_slice()
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1026 assert_equal('12345', slice('012345', 1))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1027 assert_equal('123', slice('012345', 1, 4))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1028 assert_equal('1234', slice('012345', 1, -1))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1029 assert_equal('1', slice('012345', 1, -4))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1030 assert_equal('', slice('012345', 1, -5))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1031 assert_equal('', slice('012345', 1, -6))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1032
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1033 assert_equal([1, 2, 3, 4, 5], slice(range(6), 1))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1034 assert_equal([1, 2, 3], slice(range(6), 1, 4))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1035 assert_equal([1, 2, 3, 4], slice(range(6), 1, -1))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1036 assert_equal([1], slice(range(6), 1, -4))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1037 assert_equal([], slice(range(6), 1, -5))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1038 assert_equal([], slice(range(6), 1, -6))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1039
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1040 assert_equal(0z1122334455, slice(0z001122334455, 1))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1041 assert_equal(0z112233, slice(0z001122334455, 1, 4))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1042 assert_equal(0z11223344, slice(0z001122334455, 1, -1))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1043 assert_equal(0z11, slice(0z001122334455, 1, -4))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1044 assert_equal(0z, slice(0z001122334455, 1, -5))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1045 assert_equal(0z, slice(0z001122334455, 1, -6))
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1046 enddef
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
1047
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 def Test_spellsuggest()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 if !has('spell')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 MissingFeature 'spell'
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 else
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 spellsuggest('marrch', 1, true)->assert_equal(['March'])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 endif
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 def Test_sort_return_type()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 var res: list<number>
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 res = [1, 2, 3]->sort()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 def Test_sort_argument()
23104
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1062 var lines =<< trim END
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1063 var res = ['b', 'a', 'c']->sort('i')
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1064 res->assert_equal(['a', 'b', 'c'])
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1065
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1066 def Compare(a: number, b: number): number
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1067 return a - b
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1068 enddef
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1069 var l = [3, 6, 7, 1, 8, 2, 4, 5]
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1070 sort(l, Compare)
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1071 assert_equal([1, 2, 3, 4, 5, 6, 7, 8], l)
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1072 END
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
1073 CheckDefAndScriptSuccess(lines)
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 def Test_split()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', ''])
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079
23804
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1080 def Run_str2float()
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1081 if !has('float')
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1082 MissingFeature 'float'
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1083 endif
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1084 str2float("1.00")->assert_equal(1.00)
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1085 str2float("2e-2")->assert_equal(0.02)
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1086
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1087 CheckDefFailure(['echo str2float(123)'], 'E1013:')
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1088 CheckScriptFailure(['vim9script', 'echo str2float(123)'], 'E1024:')
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1089 endif
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1090 enddef
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
1091
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 def Test_str2nr()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 str2nr("1'000'000", 10, true)->assert_equal(1000000)
23786
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23705
diff changeset
1094
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23705
diff changeset
1095 CheckDefFailure(['echo str2nr(123)'], 'E1013:')
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23705
diff changeset
1096 CheckScriptFailure(['vim9script', 'echo str2nr(123)'], 'E1024:')
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23705
diff changeset
1097 CheckDefFailure(['echo str2nr("123", "x")'], 'E1013:')
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23705
diff changeset
1098 CheckScriptFailure(['vim9script', 'echo str2nr("123", "x")'], 'E1030:')
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23705
diff changeset
1099 CheckDefFailure(['echo str2nr("123", 10, "x")'], 'E1013:')
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23705
diff changeset
1100 CheckScriptFailure(['vim9script', 'echo str2nr("123", 10, "x")'], 'E1135:')
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 def Test_strchars()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 strchars("A\u20dd", true)->assert_equal(1)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 def Test_submatch()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 var pat = 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)'
23565
34aa2907082a patch 8.2.2325: Vim9: crash if map() changes the item type
Bram Moolenaar <Bram@vim.org>
parents: 23535
diff changeset
1109 var Rep = () => range(10)->mapnew((_, v) => submatch(v, true))->string()
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 var actual = substitute('A123456789', pat, Rep, '')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]"
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 actual->assert_equal(expected)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 def Test_synID()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 setline(1, "text")
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 synID(1, 1, true)->assert_equal(0)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 bwipe!
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 def Test_term_gettty()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 if !has('terminal')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 MissingFeature 'terminal'
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 else
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 var buf = Run_shell_in_terminal({})
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 term_gettty(buf, true)->assert_notequal('')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 StopShellInTerminal(buf)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 endif
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 def Test_term_start()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 if !has('terminal')
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 MissingFeature 'terminal'
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 else
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 botright new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 var winnr = winnr()
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
1138 term_start(&shell, {curwin: true})
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 winnr()->assert_equal(winnr)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 bwipe!
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 endif
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 def Test_timer_paused()
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
1145 var id = timer_start(50, () => 0)
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 timer_pause(id, true)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 var info = timer_info(id)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 info[0]['paused']->assert_equal(1)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 timer_stop(id)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151
23596
9fa72351c18f patch 8.2.2340: win_execute() unexpectedly returns number zero when failing
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
1152 def Test_win_execute()
9fa72351c18f patch 8.2.2340: win_execute() unexpectedly returns number zero when failing
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
1153 assert_equal("\n" .. winnr(), win_execute(win_getid(), 'echo winnr()'))
9fa72351c18f patch 8.2.2340: win_execute() unexpectedly returns number zero when failing
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
1154 assert_equal('', win_execute(342343, 'echo winnr()'))
9fa72351c18f patch 8.2.2340: win_execute() unexpectedly returns number zero when failing
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
1155 enddef
9fa72351c18f patch 8.2.2340: win_execute() unexpectedly returns number zero when failing
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
1156
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 def Test_win_splitmove()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 split
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
1159 win_splitmove(1, 2, {vertical: true, rightbelow: true})
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 close
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162
23404
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1163 def Test_winrestcmd()
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1164 split
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1165 var cmd = winrestcmd()
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1166 wincmd _
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1167 exe cmd
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1168 assert_equal(cmd, winrestcmd())
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1169 close
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1170 enddef
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1171
23535
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1172 def Test_winsaveview()
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1173 var view: dict<number> = winsaveview()
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1174
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1175 var lines =<< trim END
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1176 var view: list<number> = winsaveview()
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1177 END
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1178 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<number> but got dict<number>', 1)
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1179 enddef
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1180
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1181
23404
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1182
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker