annotate src/testdir/vim9.vim @ 34864:3f9d9ee5cb7c v9.1.0299

patch 9.1.0299: Vim9: return type not set for a lambda assigned to script var Commit: https://github.com/vim/vim/commit/7f5202143b2c84ec12e709272d90dd79621d14ca Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Wed Apr 10 17:18:19 2024 +0200 patch 9.1.0299: Vim9: return type not set for a lambda assigned to script var Problem: Vim9: return type not set for a lambda assigned to script var (Ernie Rael) Solution: Correctly determine the return type (Yegappan Lakshmanan) fixes: #14445 closes: #14473 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Wed, 10 Apr 2024 17:30:04 +0200
parents aba1fa2b7d1e
children 96131d0faead
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)
34864
3f9d9ee5cb7c patch 9.1.0299: Vim9: return type not set for a lambda assigned to script var
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
115 var cwd = getcwd()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
116 new
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
117 setline(1, lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
118 try
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
119 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
120 finally
34864
3f9d9ee5cb7c patch 9.1.0299: Vim9: return type not set for a lambda assigned to script var
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
121 chdir(cwd)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
122 bw!
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
123 endtry
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
124 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
125
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
126 # :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
127 # "errors"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
128 export def CheckSourceFailureList(lines: list<string>, errors: list<string>, lnum = -3)
34864
3f9d9ee5cb7c patch 9.1.0299: Vim9: return type not set for a lambda assigned to script var
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
129 var cwd = getcwd()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
130 new
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
131 setline(1, lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
132 try
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
133 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
134 finally
34864
3f9d9ee5cb7c patch 9.1.0299: Vim9: return type not set for a lambda assigned to script var
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
135 chdir(cwd)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
136 bw!
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
137 endtry
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
138 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
139
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
140 # :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
141 export def CheckSourceSuccess(lines: list<string>)
34864
3f9d9ee5cb7c patch 9.1.0299: Vim9: return type not set for a lambda assigned to script var
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
142 var cwd = getcwd()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
143 new
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
144 setline(1, lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
145 try
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
146 :source
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
147 finally
34864
3f9d9ee5cb7c patch 9.1.0299: Vim9: return type not set for a lambda assigned to script var
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
148 chdir(cwd)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
149 bw!
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
150 endtry
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
151 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 31849
diff changeset
152
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
153 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
154 CheckDefSuccess(lines)
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
155 CheckScriptSuccess(['vim9script'] + lines)
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
156 enddef
b931df03adcc patch 8.2.1518: Vim9: cannot assign to local option
Bram Moolenaar <Bram@vim.org>
parents: 21909
diff changeset
157
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
158 # 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
159 # Vim9 script.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
160 # 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
161 # 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
162 # 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
163 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
164 var errorDef: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
165 var errorScript: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
166 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
167 errorDef = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
168 errorScript = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
169 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
170 errorDef = error[0]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
171 errorScript = error[1]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
172 else
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
173 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
174 return
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
175 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
176 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
177 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
178 enddef
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 23679
diff changeset
179
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
180 # 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
181 # Vim9 script.
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
182 # 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
183 # 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
184 # 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
185 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
186 var errorDef: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
187 var errorScript: string
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
188 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
189 errorDef = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
190 errorScript = error
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
191 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
192 errorDef = error[0]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
193 errorScript = error[1]
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
194 else
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
195 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
196 return
a07323eb647f patch 8.2.3854: Vim9: inconsistent arguments for test functions
Bram Moolenaar <Bram@vim.org>
parents: 25609
diff changeset
197 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
198 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
199 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
200 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
201
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
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
203 # 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
204 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
205 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
206 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
207 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
208 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
209 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
210 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
211 call Func()
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
212 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
213 delfunc! Func
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
214 call chdir(cwd)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
215 call delete(fname)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
216 endtry
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
217 endfunc
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
218
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
219 # 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
220 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
221 let cwd = getcwd()
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
222 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
223 let s:sequence += 1
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
224 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
225 try
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
226 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
227 finally
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
228 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
229 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
230 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
231 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
232 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
233
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
234 # 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
235 # CheckLegacyAndVim9Success()
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
236 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
237 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
238 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
239 ->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
240 ->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
241 ->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
242 ->substitute('\<LEND\>', '}', 'g')
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
243 ->substitute('\<TRUE\>', '1', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
244 ->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
245 ->substitute('#"', ' "', 'g'))
25593
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
246 CheckLegacySuccess(legacylines)
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
247 enddef
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
248
27457
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 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
250 return lines->mapnew((_, v) =>
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
251 v->substitute('\<VAR\>', 'var', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
252 ->substitute('\<LET ', '', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
253 ->substitute('\<LSTART\>', '(', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
254 ->substitute('\<LMIDDLE\>', ') =>', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
255 ->substitute(' *\<LEND\> *', '', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
256 ->substitute('\<TRUE\>', 'true', 'g')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
257 ->substitute('\<FALSE\>', 'false', 'g'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
258 enddef
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
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 :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
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 CheckTransDefSuccess(lines: list<string>)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26650
diff changeset
263 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
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 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
267 # CheckLegacyAndVim9Success()
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
268 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
269 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
270 enddef
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
271
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
272 # 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
273 # 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
274 # 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
275 # 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
276 # 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
277 # 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
278 # 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
279 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
280 CheckTransLegacySuccess(lines)
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
281 CheckTransDefSuccess(lines)
c6277019b8c1 patch 8.2.3333: Vim9: not enough tests run with Vim9
Bram Moolenaar <Bram@vim.org>
parents: 25016
diff changeset
282 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
283 enddef
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
284
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26686
diff changeset
285 # 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
286 # 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
287 # 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
288 # 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
289 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
290 var legacyError: string
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
291 var defError: string
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
292 var scriptError: string
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
293
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
294 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
295 legacyError = error
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
296 defError = error
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
297 scriptError = error
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
298 else
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
299 legacyError = error[0]
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
300 defError = error[1]
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
301 scriptError = error[2]
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
302 endif
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 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
305 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
306 ->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
307 ->substitute('#"', ' "', 'g'))
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
308 CheckLegacyFailure(legacylines, legacyError)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
309
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
310 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
311 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
312 ->substitute('\<LET ', '', 'g'))
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
313 CheckDefExecFailure(vim9lines, defError)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
314 CheckScriptFailure(['vim9script'] + vim9lines, scriptError)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
315 enddef