changeset 28570:35e24d9de858 v8.2.4809

patch 8.2.4809: various things no6 properly tested Commit: https://github.com/vim/vim/commit/885de449c0c0ef4a8541ed1f5377351844384516 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Apr 23 10:51:14 2022 +0100 patch 8.2.4809: various things no6 properly tested Problem: Various things no6 properly tested. Solution: Add various test cases. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/10259)
author Bram Moolenaar <Bram@vim.org>
date Sat, 23 Apr 2022 12:00:06 +0200
parents ec72a310d1b7
children 9b622722bad0
files src/testdir/test_blob.vim src/testdir/test_debugger.vim src/testdir/test_listdict.vim src/testdir/test_vim9_builtin.vim src/testdir/test_vim9_import.vim src/testdir/test_vim9_script.vim src/version.c
diffstat 7 files changed, 121 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_blob.vim
+++ b/src/testdir/test_blob.vim
@@ -118,6 +118,8 @@ func Test_blob_assign()
       LET b[1 : 1] ..= 0z55
   END
   call v9.CheckLegacyAndVim9Failure(lines, ['E734:', 'E1183:', 'E734:'])
+
+  call assert_fails('let b = readblob("a1b2c3")', 'E484:')
 endfunc
 
 func Test_blob_get_range()
@@ -210,6 +212,8 @@ func Test_blob_compare()
       call assert_true(b1 == b2)
       call assert_false(b1 is b2)
       call assert_true(b1 isnot b2)
+      call assert_true(0z != 0z10)
+      call assert_true(0z10 != 0z)
   END
   call v9.CheckLegacyAndVim9Success(lines)
 
@@ -266,7 +270,8 @@ func Test_blob_index_assign()
       VAR b = 0z00
       LET b[1] = 0x11
       LET b[2] = 0x22
-      call assert_equal(0z001122, b)
+      LET b[0] = 0x33
+      call assert_equal(0z331122, b)
   END
   call v9.CheckLegacyAndVim9Success(lines)
 
@@ -281,6 +286,18 @@ func Test_blob_index_assign()
       LET b[-2] = 0x33
   END
   call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
+
+  let lines =<< trim END
+      VAR b = 0z00010203
+      LET b[0 : -1] = 0z33
+  END
+  call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
+
+  let lines =<< trim END
+      VAR b = 0z00010203
+      LET b[3 : 4] = 0z3344
+  END
+  call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
 endfunc
 
 func Test_blob_for_loop()
@@ -428,6 +445,12 @@ func Test_blob_func_remove()
 
   let lines =<< trim END
       VAR b = 0zDEADBEEF
+      call remove(b, -10)
+  END
+  call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
+
+  let lines =<< trim END
+      VAR b = 0zDEADBEEF
       call remove(b, 3, 2)
   END
   call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
--- a/src/testdir/test_debugger.vim
+++ b/src/testdir/test_debugger.vim
@@ -362,7 +362,39 @@ func Test_Debugger_breakadd()
   call assert_fails('breakadd file Xtest.vim /\)/', 'E55:')
 endfunc
 
-def Test_Debugger_breakadd_expr()
+" Test for expression breakpoint set using ":breakadd expr <expr>"
+func Test_Debugger_breakadd_expr()
+  let lines =<< trim END
+    let g:Xtest_var += 1
+  END
+  call writefile(lines, 'Xtest.vim')
+
+  " Start Vim in a terminal
+  let buf = RunVimInTerminal('Xtest.vim', {})
+  call RunDbgCmd(buf, ':let g:Xtest_var = 10')
+  call RunDbgCmd(buf, ':breakadd expr g:Xtest_var')
+  call RunDbgCmd(buf, ':source %')
+  let expected =<< eval trim END
+    Oldval = "10"
+    Newval = "11"
+    `=fnamemodify('Xtest.vim', ':p')`
+    line 1: let g:Xtest_var += 1
+  END
+  call RunDbgCmd(buf, ':source %', expected)
+  call RunDbgCmd(buf, 'cont')
+  let expected =<< eval trim END
+    Oldval = "11"
+    Newval = "12"
+    `=fnamemodify('Xtest.vim', ':p')`
+    line 1: let g:Xtest_var += 1
+  END
+  call RunDbgCmd(buf, ':source %', expected)
+
+  call StopVimInTerminal(buf)
+  call delete('Xtest.vim')
+endfunc
+
+def Test_Debugger_breakadd_vim9_expr()
   var lines =<< trim END
       vim9script
       func g:EarlyFunc()
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -1017,6 +1017,7 @@ func Test_reduce()
 
   call assert_fails("call reduce([], { acc, val -> acc + val })", 'E998: Reduce of an empty List with no initial value')
   call assert_fails("call reduce(0z, { acc, val -> acc + val })", 'E998: Reduce of an empty Blob with no initial value')
+  call assert_fails("call reduce(test_null_blob(), { acc, val -> acc + val })", 'E998: Reduce of an empty Blob with no initial value')
   call assert_fails("call reduce('', { acc, val -> acc + val })", 'E998: Reduce of an empty String with no initial value')
   call assert_fails("call reduce(test_null_string(), { acc, val -> acc + val })", 'E998: Reduce of an empty String with no initial value')
 
@@ -1034,8 +1035,8 @@ func Test_reduce()
   call assert_fails("call reduce('', { acc, val -> acc + val }, 0.1)", 'E1253:')
   call assert_fails("call reduce('', { acc, val -> acc + val }, function('tr'))", 'E1253:')
   call assert_fails("call reduce('abc', { a, v -> a10}, '')", 'E121:')
-  call assert_fails("call reduce(0z01, { a, v -> a10}, 1)", 'E121:')
-  call assert_fails("call reduce([1], { a, v -> a10}, '')", 'E121:')
+  call assert_fails("call reduce(0z0102, { a, v -> a10}, 1)", 'E121:')
+  call assert_fails("call reduce([1, 2], { a, v -> a10}, '')", 'E121:')
 
   let g:lut = [1, 2, 3, 4]
   func EvilRemove()
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -1273,56 +1273,79 @@ def Test_float_funcs_args()
 
   # acos()
   v9.CheckDefAndScriptFailure(['acos("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('1.570796', string(acos(0.0)))
   # asin()
   v9.CheckDefAndScriptFailure(['asin("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('0.0', string(asin(0.0)))
   # atan()
   v9.CheckDefAndScriptFailure(['atan("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('0.0', string(atan(0.0)))
   # atan2()
   v9.CheckDefAndScriptFailure(['atan2("a", 1.1)'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('-2.356194', string(atan2(-1, -1)))
   v9.CheckDefAndScriptFailure(['atan2(1.2, "a")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 2'])
   v9.CheckDefAndScriptFailure(['atan2(1.2)'], ['E119:', 'E119:'])
   # ceil()
   v9.CheckDefAndScriptFailure(['ceil("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('2.0', string(ceil(2.0)))
   # cos()
   v9.CheckDefAndScriptFailure(['cos("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('1.0', string(cos(0.0)))
   # cosh()
   v9.CheckDefAndScriptFailure(['cosh("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('1.0', string(cosh(0.0)))
   # exp()
   v9.CheckDefAndScriptFailure(['exp("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('1.0', string(exp(0.0)))
   # float2nr()
   v9.CheckDefAndScriptFailure(['float2nr("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal(1, float2nr(1.234))
   # floor()
   v9.CheckDefAndScriptFailure(['floor("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('2.0', string(floor(2.0)))
   # fmod()
   v9.CheckDefAndScriptFailure(['fmod(1.1, "a")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 2'])
   v9.CheckDefAndScriptFailure(['fmod("a", 1.1)'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
   v9.CheckDefAndScriptFailure(['fmod(1.1)'], ['E119:', 'E119:'])
+  assert_equal('0.13', string(fmod(12.33, 1.22)))
   # isinf()
   v9.CheckDefAndScriptFailure(['isinf("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal(1, isinf(1.0 / 0.0))
   # isnan()
   v9.CheckDefAndScriptFailure(['isnan("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_true(isnan(0.0 / 0.0))
   # log()
   v9.CheckDefAndScriptFailure(['log("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('0.0', string(log(1.0)))
   # log10()
   v9.CheckDefAndScriptFailure(['log10("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('0.0', string(log10(1.0)))
   # pow()
   v9.CheckDefAndScriptFailure(['pow("a", 1.1)'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
   v9.CheckDefAndScriptFailure(['pow(1.1, "a")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 2'])
   v9.CheckDefAndScriptFailure(['pow(1.1)'], ['E119:', 'E119:'])
+  assert_equal('1.0', string(pow(0.0, 0.0)))
   # round()
   v9.CheckDefAndScriptFailure(['round("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('2.0', string(round(2.1)))
   # sin()
   v9.CheckDefAndScriptFailure(['sin("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('0.0', string(sin(0.0)))
   # sinh()
   v9.CheckDefAndScriptFailure(['sinh("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('0.0', string(sinh(0.0)))
   # sqrt()
   v9.CheckDefAndScriptFailure(['sqrt("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('0.0', string(sqrt(0.0)))
   # tan()
   v9.CheckDefAndScriptFailure(['tan("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('0.0', string(tan(0.0)))
   # tanh()
   v9.CheckDefAndScriptFailure(['tanh("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('0.0', string(tanh(0.0)))
   # trunc()
   v9.CheckDefAndScriptFailure(['trunc("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
+  assert_equal('2.0', string(trunc(2.1)))
 enddef
 
 def Test_fnameescape()
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -506,8 +506,6 @@ def Test_import_fails()
   END
   v9.CheckScriptFailure(lines, 'E1047:')
 
-  delete('Xfoo.vim')
-
   lines =<< trim END
       vim9script
       def TheFunc()
@@ -576,7 +574,26 @@ def Test_import_fails()
   END
   v9.CheckScriptSuccess(lines)
 
+  new
+  setline(1, ['vim9script', 'import "" as abc'])
+  assert_fails('source', 'E1071: Invalid string for :import: "" as abc')
+  setline(2, 'import [] as abc')
+  assert_fails('source', 'E1071: Invalid string for :import: [] as abc')
+  setline(2, 'import test_null_string() as abc')
+  assert_fails('source', 'E1071: Invalid string for :import: test_null_string() as abc')
+  bw!
+  call writefile(['vim9script', "import './Xfoo.vim' ask expo"], 'Xbar.vim')
+  assert_fails('source Xbar.vim', 'E488: Trailing characters: ask expo')
+  writefile([], 'Xtemp')
+  call writefile(['vim9script', "import './Xtemp'"], 'Xbar.vim')
+  assert_fails('source Xbar.vim', 'E1257: Imported script must use "as" or end in .vim: Xtemp')
+  delete('Xtemp')
+  call writefile(['vim9script', "import './Xfoo.vim' as abc | foobar"], 'Xbar.vim')
+  assert_fails('source Xbar.vim', 'E492: Not an editor command:  foobar')
+  call delete('Xbar.vim')
+
   delete('Ximport', 'rf')
+  delete('Xfoo.vim')
 enddef
 
 func g:Trigger()
@@ -1404,6 +1421,7 @@ def Test_export_fails()
   v9.CheckScriptFailure(['export var some = 123'], 'E1042:')
   v9.CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
   v9.CheckScriptFailure(['vim9script', 'export echo 134'], 'E1043:')
+  v9.CheckScriptFailure(['vim9script', 'export function /a1b2c3'], 'E1044:')
 
   assert_fails('export something', 'E1043:')
 enddef
@@ -2646,6 +2664,12 @@ def Test_vim9script_autoload_fails()
       var n = 0
   END
   v9.CheckScriptFailure(lines, 'E983: Duplicate argument: noclear')
+
+  lines =<< trim END
+      vim9script noclears
+      var n = 0
+  END
+  v9.CheckScriptFailure(lines, 'E475: Invalid argument: noclears')
 enddef
 
 def Test_import_autoload_fails()
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -3780,6 +3780,16 @@ def Test_unsupported_commands()
   v9.CheckDefAndScriptFailure(lines, ['E476:', 'E492:'])
 
   lines =<< trim END
+      :k a
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E1100:')
+
+  lines =<< trim END
+      :1k a
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E481:')
+
+  lines =<< trim END
     t
   END
   v9.CheckDefAndScriptFailure(lines, 'E1100:')
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4809,
+/**/
     4808,
 /**/
     4807,