blob: 2f92cf954e6fb9b540a74cfe11f5a29927827d40 [file] [log] [blame]
Bram Moolenaarcfe435d2020-04-25 20:02:55 +02001" Utility functions for testing vim9 script
2
Bram Moolenaar3e06a1e2020-08-10 21:57:54 +02003" Check that "lines" inside ":def" has no error.
4func CheckDefSuccess(lines)
5 call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef')
6 so Xdef
7 call Func()
8 call delete('Xdef')
9endfunc
10
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020011" Check that "lines" inside ":def" results in an "error" message.
Bram Moolenaar1d634542020-08-18 13:41:50 +020012" If "lnum" is given check that the error is reported for this line.
Bram Moolenaar3affe7a2020-08-18 20:34:13 +020013" Add a line before and after to make it less likely that the line number is
14" accidentally correct.
15func CheckDefFailure(lines, error, lnum = -3)
16 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], 'Xdef')
17 call assert_fails('so Xdef', a:error, a:lines, a:lnum + 1)
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020018 call delete('Xdef')
19endfunc
20
Bram Moolenaar015f4262020-05-05 21:25:22 +020021" Check that "lines" inside ":def" results in an "error" message when executed.
Bram Moolenaar1d634542020-08-18 13:41:50 +020022" If "lnum" is given check that the error is reported for this line.
Bram Moolenaar3affe7a2020-08-18 20:34:13 +020023" Add a line before and after to make it less likely that the line number is
24" accidentally correct.
25func CheckDefExecFailure(lines, error, lnum = -3)
26 call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], 'Xdef')
Bram Moolenaar015f4262020-05-05 21:25:22 +020027 so Xdef
Bram Moolenaar3affe7a2020-08-18 20:34:13 +020028 call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
Bram Moolenaar015f4262020-05-05 21:25:22 +020029 call delete('Xdef')
30endfunc
31
Bram Moolenaar3affe7a2020-08-18 20:34:13 +020032def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020033 writefile(lines, 'Xdef')
Bram Moolenaar3affe7a2020-08-18 20:34:13 +020034 assert_fails('so Xdef', error, lines, lnum)
Bram Moolenaarcfe435d2020-04-25 20:02:55 +020035 delete('Xdef')
36enddef
37
38def CheckScriptSuccess(lines: list<string>)
39 writefile(lines, 'Xdef')
40 so Xdef
41 delete('Xdef')
42enddef
Bram Moolenaar7cb6fc22020-08-21 22:36:47 +020043
44" Check that a command fails both when used in a :def function and when used
45" in Vim9 script.
46def CheckScriptAndDefFailure(lines: list<string>, error: string, lnum = -3)
47 CheckDefFailure(lines, error, lnum)
48 CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)
49enddef