annotate src/testdir/vim9.vim @ 35171:76c328389c46 default tip

Added tag v9.1.0411 for changeset ed3a90cecb19f1d38b0a9bbb9bf6ed60bace72f4
author Christian Brabandt <cb@256bit.org>
date Sun, 12 May 2024 09:30:05 +0200
parents 96131d0faead
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
1 vim9script
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
2
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
3 # Utility functions for testing vim9 script
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
5 # Use a different file name for each run.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
6 var sequence = 1
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
7
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
8 # Check that "lines" inside a ":def" function has no error when called.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
9 export func CheckDefSuccess(lines)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
10 let cwd = getcwd()
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
11 let fname = 'XdefSuccess' .. s:sequence
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
12 let s:sequence += 1
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
13 call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
14 try
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
15 exe 'so ' .. fname
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
16 call Func()
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
17 finally
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
18 call chdir(cwd)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
19 call delete(fname)
25609
f8bcd21e6e24 patch 8.2.3341: Vim9: function call aborted despite try/catch
Bram Moolenaar <Bram@vim.org>
parents: 25597
diff changeset
20 delfunc! Func
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
21 endtry
21733
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
22 endfunc
1bb5adfe5966 patch 8.2.1416: Vim9: boolean evaluation does not work as intended
Bram Moolenaar <Bram@vim.org>
parents: 20528
diff changeset
23
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
24 # Check that "lines" inside a ":def" function has no error when compiled.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
25 export func CheckDefCompileSuccess(lines)
26686
c04b28fad0cc patch 8.2.3872: Vim9: finddir() and uniq() return types can be more specific
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
26 let fname = 'XdefSuccess' .. s:sequence
c04b28fad0cc patch 8.2.3872: Vim9: finddir() and uniq() return types can be more specific
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
27 let s:sequence += 1
c04b28fad0cc patch 8.2.3872: Vim9: finddir() and uniq() return types can be more specific
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
28 call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
c04b28fad0cc patch 8.2.3872: Vim9: finddir() and uniq() return types can be more specific
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
29 try
c04b28fad0cc patch 8.2.3872: Vim9: finddir() and uniq() return types can be more specific
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
30 exe 'so ' .. fname
c04b28fad0cc patch 8.2.3872: Vim9: finddir() and uniq() return types can be more specific
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
31 finally
c04b28fad0cc patch 8.2.3872: Vim9: finddir() and uniq() return types can be more specific
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
32 call delete(fname)
c04b28fad0cc patch 8.2.3872: Vim9: finddir() and uniq() return types can be more specific
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
33 delfunc! Func
c04b28fad0cc patch 8.2.3872: Vim9: finddir() and uniq() return types can be more specific
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
34 endtry
c04b28fad0cc patch 8.2.3872: Vim9: finddir() and uniq() return types can be more specific
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
35 endfunc
c04b28fad0cc patch 8.2.3872: Vim9: finddir() and uniq() return types can be more specific
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
36
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
37 # Check that "lines" inside ":def" results in an "error" message.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
38 # If "lnum" is given check that the error is reported for this line.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
39 # Add a line before and after to make it less likely that the line number is
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
40 # accidentally correct.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
41 export func CheckDefFailure(lines, error, lnum = -3)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
42 let cwd = getcwd()
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
43 let fname = 'XdefFailure' .. s:sequence
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
44 let s:sequence += 1
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
45 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
46 try
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
47 call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
48 finally
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
49 call chdir(cwd)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
50 call delete(fname)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
51 delfunc! Func
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
52 endtry
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 endfunc
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
55 # Check that "lines" inside ":def" results in an "error" message when executed.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
56 # If "lnum" is given check that the error is reported for this line.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
57 # Add a line before and after to make it less likely that the line number is
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
58 # accidentally correct.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
59 export func CheckDefExecFailure(lines, error, lnum = -3)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
60 let cwd = getcwd()
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
61 let fname = 'XdefExecFailure' .. s:sequence
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
62 let s:sequence += 1
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
63 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], fname)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
64 try
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
65 exe 'so ' .. fname
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
66 call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
67 finally
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
68 call chdir(cwd)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
69 call delete(fname)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
70 delfunc! Func
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
71 endtry
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
72 endfunc
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
73
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
74 export def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
75 var cwd = getcwd()
27669
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
76 var fname = 'XScriptFailure' .. sequence
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
77 sequence += 1
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
78 writefile(lines, fname)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
79 try
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
80 assert_fails('so ' .. fname, error, lines, lnum)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
81 finally
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
82 chdir(cwd)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
83 delete(fname)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
84 endtry
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 enddef
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
87 export def CheckScriptFailureList(lines: list<string>, errors: list<string>, lnum = -3)
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23247
diff changeset
88 var cwd = getcwd()
27669
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
89 var fname = 'XScriptFailure' .. sequence
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
90 sequence += 1
23679
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23247
diff changeset
91 writefile(lines, fname)
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23247
diff changeset
92 try
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23247
diff changeset
93 assert_fails('so ' .. fname, errors, lines, lnum)
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23247
diff changeset
94 finally
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23247
diff changeset
95 chdir(cwd)
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23247
diff changeset
96 delete(fname)
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23247
diff changeset
97 endtry
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23247
diff changeset
98 enddef
e8c379b20765 patch 8.2.2381: Vim9: divide by zero does not abort expression execution
Bram Moolenaar <Bram@vim.org>
parents: 23247
diff changeset
99
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
100 export def CheckScriptSuccess(lines: list<string>)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
101 var cwd = getcwd()
27669
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
102 var fname = 'XScriptSuccess' .. sequence
5c4ab8d4472c patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
103 sequence += 1
23092
c713358da074 patch 8.2.2092: Vim9: unpredictable errors for script tests
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
104 writefile(lines, fname)
23247
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
105 try
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
106 exe 'so ' .. fname
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
107 finally
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
108 chdir(cwd)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
109 delete(fname)
f2d05fb28e54 patch 8.2.2169: Vim9: test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 23092
diff changeset
110 endtry
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 enddef
21909
a211bca98bc3 patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents: 21863
diff changeset
112
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
113 export def CheckDefAndScriptSuccess(lines: list<string>)
21937
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
114 CheckDefSuccess(lines)
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
115 CheckScriptSuccess(['vim9script'] + lines)
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
116 enddef
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
117
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
118 # Check that a command fails when used in a :def function and when used in
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
119 # Vim9 script.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
120 # When "error" is a string, both with the same error.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
121 # When "error" is a list, the :def function fails with "error[0]" , the script
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
122 # fails with "error[1]".
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
123 export def CheckDefAndScriptFailure(lines: list<string>, error: any, lnum = -3)
26650
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
124 var errorDef: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
125 var errorScript: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
126 if type(error) == v:t_string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
127 errorDef = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
128 errorScript = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
129 elseif type(error) == v:t_list && len(error) == 2
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
130 errorDef = error[0]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
131 errorScript = error[1]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
132 else
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
133 echoerr 'error argument must be a string or a list with two items'
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
134 return
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
135 endif
24339
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
136 CheckDefFailure(lines, errorDef, lnum)
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
137 CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1)
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
138 enddef
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
139
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
140 # Check that a command fails when executed in a :def function and when used in
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
141 # Vim9 script.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
142 # When "error" is a string, both with the same error.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
143 # When "error" is a list, the :def function fails with "error[0]" , the script
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
144 # fails with "error[1]".
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
145 export def CheckDefExecAndScriptFailure(lines: list<string>, error: any, lnum = -3)
26650
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
146 var errorDef: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
147 var errorScript: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
148 if type(error) == v:t_string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
149 errorDef = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
150 errorScript = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
151 elseif type(error) == v:t_list && len(error) == 2
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
152 errorDef = error[0]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
153 errorScript = error[1]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
154 else
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
155 echoerr 'error argument must be a string or a list with two items'
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
156 return
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
157 endif
24339
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
158 CheckDefExecFailure(lines, errorDef, lnum)
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
159 CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1)
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
160 enddef
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
161
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
162
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
163 # Check that "lines" inside a legacy function has no error.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
164 export func CheckLegacySuccess(lines)
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
165 let cwd = getcwd()
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
166 let fname = 'XlegacySuccess' .. s:sequence
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
167 let s:sequence += 1
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
168 call writefile(['func Func()'] + a:lines + ['endfunc'], fname)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
169 try
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
170 exe 'so ' .. fname
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
171 call Func()
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
172 finally
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
173 delfunc! Func
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
174 call chdir(cwd)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
175 call delete(fname)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
176 endtry
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
177 endfunc
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
178
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
179 # Check that "lines" inside a legacy function results in the expected error
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
180 export func CheckLegacyFailure(lines, error)
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
181 let cwd = getcwd()
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
182 let fname = 'XlegacyFails' .. s:sequence
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
183 let s:sequence += 1
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
184 call writefile(['func Func()'] + a:lines + ['endfunc', 'call Func()'], fname)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
185 try
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
186 call assert_fails('so ' .. fname, a:error)
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
187 finally
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
188 delfunc! Func
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
189 call chdir(cwd)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
190 call delete(fname)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
191 endtry
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
192 endfunc
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
193
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
194 # Execute "lines" in a legacy function, translated as in
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
195 # CheckLegacyAndVim9Success()
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
196 export def CheckTransLegacySuccess(lines: list<string>)
25593
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
197 var legacylines = lines->mapnew((_, v) =>
31849
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
198 v->substitute('\<VAR\>', 'let', 'g')
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
199 ->substitute('\<LET\>', 'let', 'g')
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
200 ->substitute('\<LSTART\>', '{', 'g')
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
201 ->substitute('\<LMIDDLE\>', '->', 'g')
25597
0fdacd8f0cf3 patch 8.2.3335: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25593
diff changeset
202 ->substitute('\<LEND\>', '}', 'g')
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
203 ->substitute('\<TRUE\>', '1', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
204 ->substitute('\<FALSE\>', '0', 'g')
31849
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
205 ->substitute('#"', ' "', 'g'))
25593
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
206 CheckLegacySuccess(legacylines)
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
207 enddef
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
208
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
209 export def Vim9Trans(lines: list<string>): list<string>
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
210 return lines->mapnew((_, v) =>
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
211 v->substitute('\<VAR\>', 'var', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
212 ->substitute('\<LET ', '', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
213 ->substitute('\<LSTART\>', '(', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
214 ->substitute('\<LMIDDLE\>', ') =>', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
215 ->substitute(' *\<LEND\> *', '', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
216 ->substitute('\<TRUE\>', 'true', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
217 ->substitute('\<FALSE\>', 'false', 'g'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
218 enddef
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
219
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
220 # Execute "lines" in a :def function, translated as in
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
221 # CheckLegacyAndVim9Success()
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
222 export def CheckTransDefSuccess(lines: list<string>)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
223 CheckDefSuccess(Vim9Trans(lines))
25593
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
224 enddef
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
225
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
226 # Execute "lines" in a Vim9 script, translated as in
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
227 # CheckLegacyAndVim9Success()
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
228 export def CheckTransVim9Success(lines: list<string>)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
229 CheckScriptSuccess(['vim9script'] + Vim9Trans(lines))
25593
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
230 enddef
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
231
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
232 # Execute "lines" in a legacy function, :def function and Vim9 script.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
233 # Use 'VAR' for a declaration.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
234 # Use 'LET' for an assignment
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
235 # Use ' #"' for a comment
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
236 # Use LSTART arg LMIDDLE expr LEND for lambda
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
237 # Use 'TRUE' for 1 in legacy, true in Vim9
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
238 # Use 'FALSE' for 0 in legacy, false in Vim9
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
239 export def CheckLegacyAndVim9Success(lines: list<string>)
25593
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
240 CheckTransLegacySuccess(lines)
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
241 CheckTransDefSuccess(lines)
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
242 CheckTransVim9Success(lines)
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
243 enddef
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
244
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
245 # Execute "lines" in a legacy function, :def function and Vim9 script.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
246 # Use 'VAR' for a declaration.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
247 # Use 'LET' for an assignment
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
248 # Use ' #"' for a comment
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
249 export def CheckLegacyAndVim9Failure(lines: list<string>, error: any)
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
250 var legacyError: string
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
251 var defError: string
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
252 var scriptError: string
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
253
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
254 if type(error) == type('string')
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
255 legacyError = error
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
256 defError = error
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
257 scriptError = error
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
258 else
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
259 legacyError = error[0]
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
260 defError = error[1]
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
261 scriptError = error[2]
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
262 endif
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
263
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
264 var legacylines = lines->mapnew((_, v) =>
31849
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
265 v->substitute('\<VAR\>', 'let', 'g')
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
266 ->substitute('\<LET\>', 'let', 'g')
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
267 ->substitute('#"', ' "', 'g'))
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
268 CheckLegacyFailure(legacylines, legacyError)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
269
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
270 var vim9lines = lines->mapnew((_, v) =>
31849
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
271 v->substitute('\<VAR\>', 'var', 'g')
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 27669
diff changeset
272 ->substitute('\<LET ', '', 'g'))
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
273 CheckDefExecFailure(vim9lines, defError)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
274 CheckScriptFailure(['vim9script'] + vim9lines, scriptError)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
275 enddef
35026
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
276
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
277 # :source a list of "lines" and check whether it fails with "error"
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
278 export def CheckSourceScriptFailure(lines: list<string>, error: string, lnum = -3)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
279 var cwd = getcwd()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
280 new
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
281 setline(1, lines)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
282 var bnr = bufnr()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
283 try
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
284 assert_fails('source', error, lines, lnum)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
285 finally
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
286 chdir(cwd)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
287 exe $':bw! {bnr}'
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
288 endtry
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
289 enddef
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
290
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
291 # :source a list of "lines" and check whether it fails with the list of
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
292 # "errors"
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
293 export def CheckSourceScriptFailureList(lines: list<string>, errors: list<string>, lnum = -3)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
294 var cwd = getcwd()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
295 new
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
296 var bnr = bufnr()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
297 setline(1, lines)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
298 try
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
299 assert_fails('source', errors, lines, lnum)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
300 finally
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
301 chdir(cwd)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
302 exe $':bw! {bnr}'
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
303 endtry
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
304 enddef
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
305
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
306 # :source a list of "lines" and check whether it succeeds
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
307 export def CheckSourceScriptSuccess(lines: list<string>)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
308 var cwd = getcwd()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
309 new
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
310 var bnr = bufnr()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
311 setline(1, lines)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
312 try
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
313 :source
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
314 finally
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
315 chdir(cwd)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
316 exe $':bw! {bnr}'
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
317 endtry
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
318 enddef
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
319
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
320 export def CheckSourceSuccess(lines: list<string>)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
321 CheckSourceScriptSuccess(lines)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
322 enddef
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
323
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
324 export def CheckSourceFailure(lines: list<string>, error: string, lnum = -3)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
325 CheckSourceScriptFailure(lines, error, lnum)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
326 enddef
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
327
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
328 export def CheckSourceFailureList(lines: list<string>, errors: list<string>, lnum = -3)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
329 CheckSourceScriptFailureList(lines, errors, lnum)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
330 enddef
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
331
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
332 # :source a List of "lines" inside a ":def" function and check that no error
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
333 # occurs when called.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
334 export func CheckSourceDefSuccess(lines)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
335 let cwd = getcwd()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
336 new
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
337 let bnr = bufnr()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
338 call setline(1, ['def Func()'] + a:lines + ['enddef', 'defcompile'])
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
339 try
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
340 source
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
341 call Func()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
342 finally
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
343 call chdir(cwd)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
344 delfunc! Func
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
345 exe $'bw! {bnr}'
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
346 endtry
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
347 endfunc
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
348
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
349 export def CheckSourceDefAndScriptSuccess(lines: list<string>)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
350 CheckSourceDefSuccess(lines)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
351 CheckSourceScriptSuccess(['vim9script'] + lines)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
352 enddef
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
353
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
354 # Check that "lines" inside a ":def" function has no error when compiled.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
355 export func CheckSourceDefCompileSuccess(lines)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
356 let cwd = getcwd()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
357 new
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
358 let bnr = bufnr()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
359 call setline(1, ['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'])
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
360 try
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
361 source
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
362 finally
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
363 call chdir(cwd)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
364 delfunc! Func
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
365 exe $':bw! {bnr}'
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
366 endtry
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
367 endfunc
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
368
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
369 # Check that "lines" inside ":def" results in an "error" message.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
370 # If "lnum" is given check that the error is reported for this line.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
371 # Add a line before and after to make it less likely that the line number is
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
372 # accidentally correct.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
373 export func CheckSourceDefFailure(lines, error, lnum = -3)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
374 let cwd = getcwd()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
375 new
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
376 let bnr = bufnr()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
377 call setline(1, ['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'])
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
378 try
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
379 call assert_fails('source', a:error, a:lines, a:lnum + 1)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
380 finally
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
381 call chdir(cwd)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
382 delfunc! Func
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
383 exe $':bw! {bnr}'
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
384 endtry
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
385 endfunc
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
386
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
387 # Check that "lines" inside ":def" results in an "error" message when executed.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
388 # If "lnum" is given check that the error is reported for this line.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
389 # Add a line before and after to make it less likely that the line number is
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
390 # accidentally correct.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
391 export func CheckSourceDefExecFailure(lines, error, lnum = -3)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
392 let cwd = getcwd()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
393 new
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
394 let bnr = bufnr()
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
395 call setline(1, ['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'])
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
396 try
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
397 source
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
398 call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
399 finally
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
400 call chdir(cwd)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
401 delfunc! Func
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
402 exe $':bw! {bnr}'
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
403 endtry
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
404 endfunc
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
405
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
406 # Check that a command fails when used in a :def function and when used in
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
407 # Vim9 script.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
408 # When "error" is a string, both with the same error.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
409 # When "error" is a list, the :def function fails with "error[0]" , the script
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
410 # fails with "error[1]".
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
411 export def CheckSourceDefAndScriptFailure(lines: list<string>, error: any, lnum = -3)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
412 var errorDef: string
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
413 var errorScript: string
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
414 if type(error) == v:t_string
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
415 errorDef = error
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
416 errorScript = error
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
417 elseif type(error) == v:t_list && len(error) == 2
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
418 errorDef = error[0]
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
419 errorScript = error[1]
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
420 else
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
421 echoerr 'error argument must be a string or a list with two items'
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
422 return
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
423 endif
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
424 CheckSourceDefFailure(lines, errorDef, lnum)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
425 CheckSourceScriptFailure(['vim9script'] + lines, errorScript, lnum + 1)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
426 enddef
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
427
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
428 # Check that a command fails when executed in a :def function and when used in
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
429 # Vim9 script.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
430 # When "error" is a string, both with the same error.
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
431 # When "error" is a list, the :def function fails with "error[0]" , the script
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
432 # fails with "error[1]".
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
433 export def CheckSourceDefExecAndScriptFailure(lines: list<string>, error: any, lnum = -3)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
434 var errorDef: string
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
435 var errorScript: string
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
436 if type(error) == v:t_string
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
437 errorDef = error
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
438 errorScript = error
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
439 elseif type(error) == v:t_list && len(error) == 2
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
440 errorDef = error[0]
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
441 errorScript = error[1]
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
442 else
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
443 echoerr 'error argument must be a string or a list with two items'
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
444 return
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
445 endif
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
446 CheckSourceDefExecFailure(lines, errorDef, lnum)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
447 CheckSourceScriptFailure(['vim9script'] + lines, errorScript, lnum + 1)
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
448 enddef
96131d0faead patch 9.1.0364: tests: test_vim9_builtin is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 34864
diff changeset
449