changeset 21228:91b1047d4aa4 v8.2.1165

patch 8.2.1165: insufficient testing for the Tcl interface Commit: https://github.com/vim/vim/commit/e4358906fdbd0b2df1889dad49c79a9c8cee5ac4 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jul 9 18:49:23 2020 +0200 patch 8.2.1165: insufficient testing for the Tcl interface Problem: Insufficient testing for the Tcl interface. Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/6423)
author Bram Moolenaar <Bram@vim.org>
date Thu, 09 Jul 2020 19:00:04 +0200
parents 2dcfc1b4a478
children c383383768f4
files src/testdir/test_tcl.vim src/version.c
diffstat 2 files changed, 57 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_tcl.vim
+++ b/src/testdir/test_tcl.vim
@@ -23,6 +23,13 @@ func Test_tcldo()
   call setline(1, ['one', 'two', 'three'])
   tcldo ::vim::command new
   call assert_equal(wincount + 1, winnr('$'))
+
+  " Try to run a command in a 'nomodifiable' buffer
+  call setline(1, ['one', 'two', 'three'])
+  set nomodifiable
+  call assert_fails('tcldo set line "abc"', 'cannot save undo information')
+  set modifiable
+
   %bwipe!
 endfunc
 
@@ -91,6 +98,9 @@ func Test_vim_buffer()
         \           'expected integer but got "x"')
   call assert_fails('tcl ::vim::buffer list x',
         \           'wrong # args: should be "::vim::buffer list "')
+  " Invalid buffer command
+  call assert_fails('tcl $::vim::current(buffer) abcd',
+        \           'bad option "abcd":')
 
   tcl rename eachbuf ""
   %bwipe!
@@ -176,6 +186,8 @@ func Test_vim_window_list()
   call assert_fails('tcl ::vim::window x', 'unknown option')
   call assert_fails('tcl ::vim::window list x',
         \           'wrong # args: should be "::vim::window option"')
+  call assert_fails('tcl $::vim::current(window) abcd',
+        \           'bad option "abcd":')
 
   %bwipe
 endfunc
@@ -248,6 +260,19 @@ func Test_window_cursor()
   tcl $win cursor $here(row) $here(column)
   call assert_equal([0, 2, 3, 0], getpos('.'))
 
+  " Invalid values for the row and column
+  tcl array set pos {1 2}
+  call assert_fails('tcl $win cursor pos', "can't read \"pos(row)\":")
+  tcl array set pos {row '' abc 2}
+  call assert_fails('tcl $win cursor pos', "expected integer but got \"''\"")
+  tcl array set pos {row 1 abc 2}
+  call assert_fails('tcl $win cursor pos', "can't read \"pos(column)\":")
+  tcl array set pos {row 1 column ''}
+  call assert_fails('tcl $win cursor pos', "expected integer but got \"''\"")
+
+  call assert_fails("tcl $win cursor '' 2", "expected integer but got \"''\"")
+  call assert_fails("tcl $win cursor 1 ''", "expected integer but got \"''\"")
+
   call assert_fails('tcl $win cursor 1 1 1', 'wrong # args:')
 
   tcl unset win here
@@ -351,6 +376,7 @@ func Test_window_delcmd()
   call assert_equal('window deleted', TclEval('set msg'))
 
   call assert_fails('tcl $::vim::current(window) delcmd', 'wrong # args')
+  call assert_fails('tcl $::vim::current(window) delcmd x x', 'wrong # args')
 
   tcl unset msg
   bwipe
@@ -417,6 +443,14 @@ func Test_buffer_delete()
 
   call assert_fails('tcl $::vim::current(buffer) delete', 'wrong # args:')
   call assert_fails('tcl $::vim::current(buffer) delete 1 2 3', 'wrong # args:')
+  call assert_fails('tcl $::vim::current(buffer) delete 1 abc',
+        \ 'expected integer but got "abc"')
+
+  " Try to delete lines from an 'nomodifiable' buffer
+  set nomodifiable
+  call assert_fails('tcl $::vim::current(buffer) delete 2 1',
+        \ 'cannot save undo information')
+  set modifiable
 
   bwipe!
 endfunc
@@ -458,6 +492,12 @@ func Test_buffer_append()
   call assert_fails('tcl $buf append', 'wrong # args:')
   call assert_fails('tcl $buf append 1 x x', 'wrong # args:')
 
+  " Try to append lines to a 'nomodifiable' buffer
+  set nomodifiable
+  call assert_fails('tcl $buf append 1 "first"',
+        \ 'cannot save undo information')
+  set modifiable
+
   tcl unset buf
   bwipe!
 endfunc
@@ -485,6 +525,18 @@ func Test_buffer_set()
   call assert_fails('tcl $::vim::current(buffer) set 6 "x"', 'line number out of range')
 
   call assert_fails('tcl $::vim::current(buffer) set', 'wrong # args:')
+  call assert_fails('tcl $::vim::current(buffer) set 1 2 {[list "a" "b"]}',
+        \ 'list element in quotes followed by "]" instead of space')
+
+  " Try to modify a 'nomodifiable' buffer
+  set nomodifiable
+  call assert_fails('tcl $::vim::current(buffer) set 1 "x"',
+        \ 'cannot save undo information')
+  call assert_fails('tcl $::vim::current(buffer) set 1 {a b}',
+        \ 'cannot save undo information')
+  call assert_fails('tcl $::vim::current(buffer) set 1 2 {a b}',
+        \ 'cannot save undo information')
+  set modifiable
   bwipe!
 endfunc
 
@@ -514,6 +566,7 @@ func Test_buffer_get()
   call assert_fails('tcl $buf get  0 1', 'line number out of range')
 
   call assert_fails('tcl $::vim::current(buffer) get x', 'expected integer but got "x"')
+  call assert_fails('tcl $::vim::current(buffer) get 1 x', 'expected integer but got "x"')
   call assert_fails('tcl $::vim::current(buffer) get 1 1 1', 'wrong # args:')
 
   tcl unset buf
@@ -592,8 +645,8 @@ func Test_buffer_delcmd()
   q
   call assert_equal('buffer deleted', TclEval('set msg'))
 
-  call assert_fails('tcl $::vim::current(window) delcmd', 'wrong # args')
-  call assert_fails('tcl $::vim::current(window) delcmd x x', 'wrong # args')
+  call assert_fails('tcl $::vim::current(buffer) delcmd', 'wrong # args')
+  call assert_fails('tcl $::vim::current(buffer) delcmd x x', 'wrong # args')
 
   tcl unset msg
   %bwipe
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1165,
+/**/
     1164,
 /**/
     1163,