diff 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
line wrap: on
line diff
--- a/src/testdir/vim9.vim
+++ b/src/testdir/vim9.vim
@@ -100,36 +100,46 @@ def CheckDefAndScriptSuccess(lines: list
   CheckScriptSuccess(['vim9script'] + lines)
 enddef
 
-" Check that a command fails with the same error when used in a :def function
-" and when used in Vim9 script.
-def CheckDefAndScriptFailure(lines: list<string>, error: string, lnum = -3)
-  CheckDefFailure(lines, error, lnum)
-  CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)
-enddef
-
-" As CheckDefAndScriptFailure() but with two different expected errors.
-def CheckDefAndScriptFailure2(
-  	lines: list<string>,
-	errorDef: string,
-	errorScript: string,
-	lnum = -3)
+" Check that a command fails when used in a :def function and when used in
+" Vim9 script.
+" When "error" is a string, both with the same error.
+" When "error" is a list, the :def function fails with "error[0]" , the script
+" fails with "error[1]".
+def CheckDefAndScriptFailure(lines: list<string>, error: any, lnum = -3)
+  var errorDef: string
+  var errorScript: string
+  if type(error) == v:t_string
+    errorDef = error
+    errorScript = error
+  elseif type(error) == v:t_list && len(error) == 2
+    errorDef = error[0]
+    errorScript = error[1]
+  else
+    echoerr 'error argument must be a string or a list with two items'
+    return
+  endif
   CheckDefFailure(lines, errorDef, lnum)
   CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1)
 enddef
 
-" Check that a command fails with the same error  when executed in a :def
-" function and when used in Vim9 script.
-def CheckDefExecAndScriptFailure(lines: list<string>, error: string, lnum = -3)
-  CheckDefExecFailure(lines, error, lnum)
-  CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)
-enddef
-
-" As CheckDefExecAndScriptFailure() but with two different expected errors.
-def CheckDefExecAndScriptFailure2(
-  	lines: list<string>,
-	errorDef: string,
-	errorScript: string,
-	lnum = -3)
+" Check that a command fails when executed in a :def function and when used in
+" Vim9 script.
+" When "error" is a string, both with the same error.
+" When "error" is a list, the :def function fails with "error[0]" , the script
+" fails with "error[1]".
+def CheckDefExecAndScriptFailure(lines: list<string>, error: any, lnum = -3)
+  var errorDef: string
+  var errorScript: string
+  if type(error) == v:t_string
+    errorDef = error
+    errorScript = error
+  elseif type(error) == v:t_list && len(error) == 2
+    errorDef = error[0]
+    errorScript = error[1]
+  else
+    echoerr 'error argument must be a string or a list with two items'
+    return
+  endif
   CheckDefExecFailure(lines, errorDef, lnum)
   CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1)
 enddef