Mercurial > vim
comparison src/testdir/vim9.vim @ 26650:a07323eb647f v8.2.3854
patch 8.2.3854: Vim9: inconsistent arguments for test functions
Commit: https://github.com/vim/vim/commit/86b3ab4fa0de3e8884ab6a6ced2a70592b937d0f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 19 18:33:23 2021 +0000
patch 8.2.3854: Vim9: inconsistent arguments for test functions
Problem: Vim9: inconsistent arguments for test functions.
Solution: When :def function and script have different arguments use a list
with two items instead of a separate function.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 19 Dec 2021 19:45:03 +0100 |
parents | f8bcd21e6e24 |
children | e01607ab0fab |
comparison
equal
deleted
inserted
replaced
26649:8a10ad703e92 | 26650:a07323eb647f |
---|---|
98 def CheckDefAndScriptSuccess(lines: list<string>) | 98 def CheckDefAndScriptSuccess(lines: list<string>) |
99 CheckDefSuccess(lines) | 99 CheckDefSuccess(lines) |
100 CheckScriptSuccess(['vim9script'] + lines) | 100 CheckScriptSuccess(['vim9script'] + lines) |
101 enddef | 101 enddef |
102 | 102 |
103 " Check that a command fails with the same error when used in a :def function | 103 " Check that a command fails when used in a :def function and when used in |
104 " and when used in Vim9 script. | 104 " Vim9 script. |
105 def CheckDefAndScriptFailure(lines: list<string>, error: string, lnum = -3) | 105 " When "error" is a string, both with the same error. |
106 CheckDefFailure(lines, error, lnum) | 106 " When "error" is a list, the :def function fails with "error[0]" , the script |
107 CheckScriptFailure(['vim9script'] + lines, error, lnum + 1) | 107 " fails with "error[1]". |
108 enddef | 108 def CheckDefAndScriptFailure(lines: list<string>, error: any, lnum = -3) |
109 | 109 var errorDef: string |
110 " As CheckDefAndScriptFailure() but with two different expected errors. | 110 var errorScript: string |
111 def CheckDefAndScriptFailure2( | 111 if type(error) == v:t_string |
112 lines: list<string>, | 112 errorDef = error |
113 errorDef: string, | 113 errorScript = error |
114 errorScript: string, | 114 elseif type(error) == v:t_list && len(error) == 2 |
115 lnum = -3) | 115 errorDef = error[0] |
116 errorScript = error[1] | |
117 else | |
118 echoerr 'error argument must be a string or a list with two items' | |
119 return | |
120 endif | |
116 CheckDefFailure(lines, errorDef, lnum) | 121 CheckDefFailure(lines, errorDef, lnum) |
117 CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1) | 122 CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1) |
118 enddef | 123 enddef |
119 | 124 |
120 " Check that a command fails with the same error when executed in a :def | 125 " Check that a command fails when executed in a :def function and when used in |
121 " function and when used in Vim9 script. | 126 " Vim9 script. |
122 def CheckDefExecAndScriptFailure(lines: list<string>, error: string, lnum = -3) | 127 " When "error" is a string, both with the same error. |
123 CheckDefExecFailure(lines, error, lnum) | 128 " When "error" is a list, the :def function fails with "error[0]" , the script |
124 CheckScriptFailure(['vim9script'] + lines, error, lnum + 1) | 129 " fails with "error[1]". |
125 enddef | 130 def CheckDefExecAndScriptFailure(lines: list<string>, error: any, lnum = -3) |
126 | 131 var errorDef: string |
127 " As CheckDefExecAndScriptFailure() but with two different expected errors. | 132 var errorScript: string |
128 def CheckDefExecAndScriptFailure2( | 133 if type(error) == v:t_string |
129 lines: list<string>, | 134 errorDef = error |
130 errorDef: string, | 135 errorScript = error |
131 errorScript: string, | 136 elseif type(error) == v:t_list && len(error) == 2 |
132 lnum = -3) | 137 errorDef = error[0] |
138 errorScript = error[1] | |
139 else | |
140 echoerr 'error argument must be a string or a list with two items' | |
141 return | |
142 endif | |
133 CheckDefExecFailure(lines, errorDef, lnum) | 143 CheckDefExecFailure(lines, errorDef, lnum) |
134 CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1) | 144 CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1) |
135 enddef | 145 enddef |
136 | 146 |
137 | 147 |