annotate src/testdir/test_vim9_builtin.vim @ 23827:7e0d8f1cae7d v8.2.2455

patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent Commit: https://github.com/vim/vim/commit/2e5910bfbb05957c10c9c69756dfa342557e9a8b Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 3 17:41:24 2021 +0100 patch 8.2.2455: Vim9: key type for literal dict and indexing is inconsistent Problem: Vim9: key type that can be used for literal dict and indexing is inconsistent. Solution: Allow using number and bool as key for a literal dict. (#7771)
author Bram Moolenaar <Bram@vim.org>
date Wed, 03 Feb 2021 17:45:06 +0100
parents 525c9e218c69
children 54b583156d53
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))
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
126 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
127
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
128 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
129 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
130 assert_equal(false, 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
131 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
132
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 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
134 split SomeFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 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
136 edit OtherFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 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
138 close
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 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
142 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
143 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
144
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 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
146 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
147 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
148 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 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
159 only
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 bwipe SomeFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 bwipe OtherFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 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
165 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
166 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
167 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
168 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 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
171 char2nr('あ', true)->assert_equal(12354)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 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
175 new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 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
177 col([1, '$'])->assert_equal(5)
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_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
181 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
182 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
183 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
184 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 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
187
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 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
189 res = 0
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 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
191 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 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
194
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 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
196 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 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
199 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
200 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
201 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202
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
203 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
204 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
205 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
206 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
207 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
208 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
209 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
210
b79cdad3ea2e patch 8.2.2184: Vim9: no error when using "2" for a line number
Bram Moolenaar <Bram@vim.org>
parents: 23175
diff changeset
211 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
212 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
213 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
214 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
215 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
216
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
217 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
218 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
219 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
220 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
221
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
222 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
223 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
224 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
225
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
226 CheckDefExecFailure(['echo executable(123)'], 'E928:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
227 CheckDefExecFailure(['echo executable(true)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
228 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
229
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
230 def Test_exepath()
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
231 CheckDefExecFailure(['echo exepath(true)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
232 CheckDefExecFailure(['echo exepath(v:null)'], 'E928:')
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
233 CheckDefExecFailure(['echo exepath("")'], 'E1142:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
234 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
235
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 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
237 split SomeFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 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
239 close
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241
22766
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250
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
251 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
252 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
253 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
254 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
255
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
256 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
257 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
258 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
259 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
260 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
261
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
262 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
263 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
264 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
265
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
266 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
267 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
268 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
269
8dcb2255ff9a patch 8.2.2362: Vim9: check of builtin function argument type is incomplete
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
270 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
271 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
272 enddef
a7082e865ffd patch 8.2.1931: Vim9: arguments of extend() not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents: 22679
diff changeset
273
23588
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
274 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
275 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
276 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
277
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
278 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
279 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
280 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
281 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
282 enddef
510088f8c66f patch 8.2.2336: Vim9: not possible to extend dictionary with different type
Bram Moolenaar <Bram@vim.org>
parents: 23565
diff changeset
283
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 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
285 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
286 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
287 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
288 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 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
291 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
293 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
294 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
295 endfunc
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
296
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
297 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
298 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
299 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
300 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
301 END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
302 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
303
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
304 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
305 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
306 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
307 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
308 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
309
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
310 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
311 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
312 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
313 END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
314 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
315 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
316 enddef
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
317
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
318 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
319 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
320 endfunc
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
321
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
322 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
323 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
324 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
325 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
326 END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
327 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
328
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
329 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
330 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
331 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
332 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
333 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
334
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
335 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
336 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
337 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
338 END
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23428
diff changeset
339 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
340 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
341 enddef
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342
23592
2322b643e329 patch 8.2.2338: Vim9: no error if using job_info() result wrongly
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
343 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
344 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
345 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
346 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
347 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
348 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
349 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
350 endif
2322b643e329 patch 8.2.2338: Vim9: no error if using job_info() result wrongly
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
351 enddef
2322b643e329 patch 8.2.2338: Vim9: no error if using job_info() result wrongly
Bram Moolenaar <Bram@vim.org>
parents: 23588
diff changeset
352
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
353 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
354 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
355 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
356
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
357 CheckDefExecFailure(['echo filereadable(123)'], 'E928:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
358 CheckDefExecFailure(['echo filereadable(true)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
359 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
360
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
361 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
362 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
363 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
364
d7294a6220ac patch 8.2.2133: Vim9: checking for a non-empty string is too strict
Bram Moolenaar <Bram@vim.org>
parents: 23142
diff changeset
365 CheckDefExecFailure(['echo filewritable(123)'], 'E928:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
366 CheckDefExecFailure(['echo filewritable(true)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
367 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
368
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
369 def Test_finddir()
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
370 CheckDefExecFailure(['echo finddir(true)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
371 CheckDefExecFailure(['echo finddir(v:null)'], 'E928:')
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
372 CheckDefExecFailure(['echo finddir("")'], 'E1142:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
373 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
374
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
375 def Test_findfile()
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
376 CheckDefExecFailure(['echo findfile(true)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
377 CheckDefExecFailure(['echo findfile(v:null)'], 'E928:')
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
378 CheckDefExecFailure(['echo findfile("")'], 'E1142:')
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
379 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
380
23816
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
381 def Test_flattennew()
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
382 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
383 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
384 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
385 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
386
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
387 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
388 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
389 END
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
390 CheckDefAndScriptSuccess(lines)
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
391
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
392 lines =<< trim END
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
393 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
394 END
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
395 CheckDefAndScriptFailure(lines, 'E1158:')
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
396 enddef
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 23804
diff changeset
397
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
398 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
399 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
400 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
401 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
402 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
403
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
404 CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
405 CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
406 CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
407 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
408
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
409 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
410 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
411 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
412
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 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
414 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
415 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 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
418 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
419 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
420 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
421 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 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
424 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425
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
426 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
427 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
428 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
429 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
430 enddef
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 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
433 garbagecollect(true)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 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
437 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
438 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
439
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 edit Xtestfile1
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 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
442 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
443 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
444 ->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
445 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
446 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 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
449 e SomeFile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 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
451 e #
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 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
453 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
454 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
455 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
456 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
457
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 bwipe!
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 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
462 new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 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
464 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
465 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
466 bwipe!
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 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
470 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
471 endwhile
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 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
473 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 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
476 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
477 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
478 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
479 set wildignore&
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 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
483 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
484 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
485
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
486 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
487 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
488 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
490 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
491 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
492 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
493
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
494 CheckDefExecFailure(['echo getfperm(true)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
495 CheckDefExecFailure(['echo getfperm(v:null)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
496 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
497
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
498 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
499 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
500 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
501
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
502 CheckDefExecFailure(['echo getfsize(true)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
503 CheckDefExecFailure(['echo getfsize(v:null)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
504 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
505
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
506 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
507 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
508 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
509
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
510 CheckDefExecFailure(['echo getftime(true)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
511 CheckDefExecFailure(['echo getftime(v:null)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
512 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
513
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
514 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
515 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
516 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
517
23142
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
518 CheckDefExecFailure(['echo getftype(true)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
519 CheckDefExecFailure(['echo getftype(v:null)'], 'E928:')
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
520 enddef
5f08d4a42898 patch 8.2.2117: some functions use any value as a string
Bram Moolenaar <Bram@vim.org>
parents: 23104
diff changeset
521
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 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
523 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
524 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
525
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
526 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
527 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
528 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 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
531 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
532 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
533 getreg('a', true, true)->assert_equal(lines)
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_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
537 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
538 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
539 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
540 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 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
543 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
544 enddef
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 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
547 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
548 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 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
551 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
552 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 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
555 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
556 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
557 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
558 iunabbrev foo
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 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
562 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
563 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564
22898
a8bccb0634bc patch 8.2.1996: Vim9: invalid error for argument of extend()
Bram Moolenaar <Bram@vim.org>
parents: 22766
diff changeset
565 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
566 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
567 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
568
22661
c6b17787a38f patch 8.2.1879: Vim9: argument types of insert() not checked when compiling
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
569 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
570 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
571 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
572 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
573 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 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
576
c6b17787a38f patch 8.2.1879: Vim9: argument types of insert() not checked when compiling
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
577 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
578 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
579 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
580 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
581 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
582 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
583
22661
c6b17787a38f patch 8.2.1879: Vim9: argument types of insert() not checked when compiling
Bram Moolenaar <Bram@vim.org>
parents: 22655
diff changeset
584 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
585 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
586 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 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
589 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
590 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
591 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 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
594 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
595 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
596 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
597 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
598 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 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
601 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
602 ->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
603 ->str2nr()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605
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
606 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
607 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
608 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
609 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
610 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
611 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
612 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
613 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
614 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
615 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
616 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
617
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
618 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
619 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
620 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
621 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
622 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
623 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
624 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
625
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
626 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
627 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
628 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
629 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
630 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
631
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
632 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
633 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
634 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
635 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
636 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
637
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
638 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
639 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
640 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
641 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
642 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
643 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
644
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 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
646 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
647 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
648 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
649 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
650 script: 0,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 mode: ' ',
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 silent: 0,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 noremap: 0,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 lhs: 'foo',
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 lhsraw: 'foo',
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 nowait: 0,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 expr: 0,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 sid: SID(),
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 rhs: 'bar',
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 buffer: 0})
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 unmap foo
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 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
665 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
666 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
667 iunabbrev foo
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_maparg_mapset()
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 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
672 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
673 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
674
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 nunmap <F3>
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677
23705
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
678 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
679 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
680 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
681 ? [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
682 : [4, 5]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
683 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
684
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
685 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
686 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
687 ? [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
688 : [4, 5]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
689 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
690 enddef
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
691
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
692 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
693 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
694 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
695 ? [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
696 : [4, 5]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
697 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
698
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
699 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
700 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
701 ? [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
702 : [4, 5]
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
703 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
704 enddef
9092d2a4422a patch 8.2.2394: Vim9: min() and max() return type is "any"
Bram Moolenaar <Bram@vim.org>
parents: 23691
diff changeset
705
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 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
707 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
708 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 def Test_readdir()
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
711 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
712 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
713 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714
23602
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
715 def Test_readblob()
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
716 var blob = 0z12341234
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
717 writefile(blob, 'Xreadblob')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
718 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
719 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
720
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
721 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
722 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
723 END
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
724 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
725 delete('Xreadblob')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
726 enddef
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
727
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
728 def Test_readfile()
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
729 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
730 writefile(text, 'Xreadfile')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
731 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
732 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
733
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
734 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
735 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
736 END
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
737 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
738 delete('Xreadfile')
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
739 enddef
7b3317e959e3 patch 8.2.2343: Vim9: return type of readfile() is any
Bram Moolenaar <Bram@vim.org>
parents: 23596
diff changeset
740
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 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
742 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
743 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
744 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
745 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 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
748 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 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
751 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
752 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
753 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
754 res += n
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 endfor
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 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
757 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 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
760 new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 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
762 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
763 # 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
764 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
765 :1
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
766 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
767 # 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
768 :1
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
769 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
770 :1
23428
5807e3958e38 patch 8.2.2257: Vim9: using -> for lambda is ambiguous
Bram Moolenaar <Bram@vim.org>
parents: 23404
diff changeset
771 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
772 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
773 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
774 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 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
777 new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 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
779 :/foo
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
780 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
781 ->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
782 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
783 current: 1,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 total: 1,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 maxcount: 99,
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 incomplete: 0})
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 bwipe!
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
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
790 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
791 # 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
792 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
793 new
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
794 var b = bufnr('%')
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
795 hide
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
796 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
797 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
798 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
799 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
800 exe "bd!" b
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
801 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
802
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
803 split Xtest
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
804 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
805 b = bufnr('%')
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
806 wincmd w
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
807
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
808 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
809 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
810 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
811 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
812
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
813 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
814 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
815 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
816 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
817
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
818 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
819
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
820 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
821 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
822 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
823 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
824 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
825 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
826
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
827 setbufline(b, 2, [function('eval'), {key: 123}, test_null_job()])
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
828 assert_equal(["function('eval')",
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
829 "{'key': 123}",
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
830 "no process"],
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
831 getbufline(b, 2, 4))
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
832
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
833 exe 'bwipe! ' .. b
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
834 END
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
835 CheckDefAndScriptSuccess(lines)
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
836 enddef
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23786
diff changeset
837
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 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
839 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
840 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 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
843 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
844 &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
845 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
846 &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
847 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
848 &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
849 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
850 &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
851
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 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
853 &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
854 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
855 &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
856 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
857 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
858 &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
859 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
860 &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
861 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
862
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 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
864 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
865 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 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
868 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
869 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
870 setqflist([], ' ', what)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 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
872 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 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
875 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
876 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
877 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
878 getreginfo('a')->assert_equal(reginfo)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
881 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
882 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
883 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
884 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
885 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
886 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
887 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
888
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
889 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
890 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
891 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
892 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
893 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
894 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
895
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
896 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
897 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
898 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
899 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
900 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
901 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
902 enddef
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23602
diff changeset
903
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 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
905 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
906 MissingFeature 'spell'
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 else
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 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
909 endif
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 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
913 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
914 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
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_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
918 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
919 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
920 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
921
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
922 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
923 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
924 enddef
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
925 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
926 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
927 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
928 END
1013a97d5dc0 patch 8.2.2098: Vim9: function argument of sort() and map() not tested
Bram Moolenaar <Bram@vim.org>
parents: 23072
diff changeset
929 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
930 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 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
933 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
934 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935
23804
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
936 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
937 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
938 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
939 endif
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
940 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
941 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
942
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
943 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
944 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
945 endif
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
946 enddef
007fa6365dfb patch 8.2.2443: Vim9: no compile time error for wrong str2float argument
Bram Moolenaar <Bram@vim.org>
parents: 23800
diff changeset
947
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 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
949 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
950
0512923e54e1 patch 8.2.2434: Vim9: no error when compiling str2nr() with a number
Bram Moolenaar <Bram@vim.org>
parents: 23705
diff changeset
951 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
952 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
953 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
954 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
955 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
956 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
957 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 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
960 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
961 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 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
964 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
965 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
966 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
967 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
968 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
969 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 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
972 new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 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
974 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
975 bwipe!
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 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
979 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
980 MissingFeature 'terminal'
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 else
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 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
983 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
984 StopShellInTerminal(buf)
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 endif
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 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
989 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
990 MissingFeature 'terminal'
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 else
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 botright new
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 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
994 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
995 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
996 bwipe!
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 endif
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 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
1001 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
1002 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
1003 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
1004 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
1005 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
1006 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007
23596
9fa72351c18f patch 8.2.2340: win_execute() unexpectedly returns number zero when failing
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
1008 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
1009 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
1010 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
1011 enddef
9fa72351c18f patch 8.2.2340: win_execute() unexpectedly returns number zero when failing
Bram Moolenaar <Bram@vim.org>
parents: 23594
diff changeset
1012
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 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
1014 split
23072
4b398a229b0b patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Bram Moolenaar <Bram@vim.org>
parents: 22936
diff changeset
1015 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
1016 close
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 enddef
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018
23404
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1019 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
1020 split
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1021 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
1022 wincmd _
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1023 exe cmd
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1024 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
1025 close
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1026 enddef
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1027
23535
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1028 def Test_winsaveview()
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1029 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
1030
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1031 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
1032 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
1033 END
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1034 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
1035 enddef
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1036
98185d3dd369 patch 8.2.2310: Vim9: winsaveview() return type is too generic
Bram Moolenaar <Bram@vim.org>
parents: 23485
diff changeset
1037
23404
a6b6bcc004f2 patch 8.2.2245: Vim9: return value of winrestcmd() cannot be executed
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1038
22655
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039
eabe2c1444ea patch 8.2.1876: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker