annotate src/testdir/vim9.vim @ 33863:3b8089d550eb v9.0.2141

patch 9.0.2141: [security]: buffer-overflow in suggest_trie_walk Commit: https://github.com/vim/vim/commit/0fb375aae608d7306b4baf9c1f906961f32e2abf Author: Christian Brabandt <cb@256bit.org> Date: Wed Nov 29 10:23:39 2023 +0100 patch 9.0.2141: [security]: buffer-overflow in suggest_trie_walk Problem: [security]: buffer-overflow in suggest_trie_walk Solution: Check n before using it as index into byts array Basically, n as an index into the byts array, can point to beyond the byts array. So let's double check, that n is within the expected range after incrementing it from sp->ts_curi and bail out if it would be invalid. Reported by @henices, thanks! Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 10 Dec 2023 15:16:03 +0100
parents aba1fa2b7d1e
children 3f9d9ee5cb7c
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
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
113 # :source a list of "lines" and check whether it fails with "error"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
114 export def CheckSourceFailure(lines: list<string>, error: string, lnum = -3)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
115 new
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
116 setline(1, lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
117 try
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
118 assert_fails('source', error, lines, lnum)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
119 finally
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
120 bw!
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
121 endtry
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
122 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
123
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
124 # :source a list of "lines" and check whether it fails with the list of
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
125 # "errors"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
126 export def CheckSourceFailureList(lines: list<string>, errors: list<string>, lnum = -3)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
127 new
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
128 setline(1, lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
129 try
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
130 assert_fails('source', errors, lines, lnum)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
131 finally
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
132 bw!
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
133 endtry
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
134 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
135
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
136 # :source a list of "lines" and check whether it succeeds
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
137 export def CheckSourceSuccess(lines: list<string>)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
138 new
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
139 setline(1, lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
140 try
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
141 :source
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
142 finally
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
143 bw!
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
144 endtry
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
145 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
146
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
147 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
148 CheckDefSuccess(lines)
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
149 CheckScriptSuccess(['vim9script'] + lines)
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
150 enddef
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
151
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
152 # 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
153 # Vim9 script.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
154 # 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
155 # 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
156 # 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
157 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
158 var errorDef: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
159 var errorScript: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
160 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
161 errorDef = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
162 errorScript = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
163 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
164 errorDef = error[0]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
165 errorScript = error[1]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
166 else
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
167 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
168 return
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
169 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
170 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
171 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
172 enddef
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
173
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
174 # 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
175 # Vim9 script.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
176 # 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
177 # 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
178 # 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
179 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
180 var errorDef: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
181 var errorScript: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
182 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
183 errorDef = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
184 errorScript = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
185 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
186 errorDef = error[0]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
187 errorScript = error[1]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
188 else
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
189 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
190 return
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
191 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
192 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
193 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
194 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
195
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
196
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
197 # 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
198 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
199 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
200 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
201 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
202 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
203 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
204 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
205 call Func()
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
206 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
207 delfunc! Func
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
208 call chdir(cwd)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
209 call delete(fname)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
210 endtry
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
211 endfunc
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
212
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
213 # 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
214 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
215 let cwd = getcwd()
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
216 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
217 let s:sequence += 1
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
218 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
219 try
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
220 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
221 finally
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
222 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
223 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
224 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
225 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
226 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
227
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
228 # 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
229 # CheckLegacyAndVim9Success()
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
230 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
231 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
232 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
233 ->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
234 ->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
235 ->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
236 ->substitute('\<LEND\>', '}', 'g')
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
237 ->substitute('\<TRUE\>', '1', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
238 ->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
239 ->substitute('#"', ' "', 'g'))
25593
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
240 CheckLegacySuccess(legacylines)
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
241 enddef
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
242
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
243 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
244 return lines->mapnew((_, v) =>
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
245 v->substitute('\<VAR\>', 'var', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
246 ->substitute('\<LET ', '', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
247 ->substitute('\<LSTART\>', '(', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
248 ->substitute('\<LMIDDLE\>', ') =>', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
249 ->substitute(' *\<LEND\> *', '', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
250 ->substitute('\<TRUE\>', 'true', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
251 ->substitute('\<FALSE\>', 'false', 'g'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
252 enddef
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
253
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
254 # 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
255 # CheckLegacyAndVim9Success()
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
256 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
257 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
258 enddef
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
259
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
260 # 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
261 # CheckLegacyAndVim9Success()
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
262 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
263 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
264 enddef
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
265
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
266 # 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
267 # 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
268 # 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
269 # 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
270 # 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
271 # 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
272 # 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
273 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
274 CheckTransLegacySuccess(lines)
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
275 CheckTransDefSuccess(lines)
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
276 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
277 enddef
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
278
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
279 # 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
280 # 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
281 # 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
282 # 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
283 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
284 var legacyError: string
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
285 var defError: string
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
286 var scriptError: string
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
287
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
288 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
289 legacyError = error
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
290 defError = error
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
291 scriptError = error
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
292 else
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
293 legacyError = error[0]
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
294 defError = error[1]
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
295 scriptError = error[2]
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
296 endif
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
297
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
298 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
299 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
300 ->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
301 ->substitute('#"', ' "', 'g'))
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
302 CheckLegacyFailure(legacylines, legacyError)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
303
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
304 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
305 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
306 ->substitute('\<LET ', '', 'g'))
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
307 CheckDefExecFailure(vim9lines, defError)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
308 CheckScriptFailure(['vim9script'] + vim9lines, scriptError)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
309 enddef