# HG changeset patch # User Christian Brabandt # Date 1530737106 -7200 # Node ID c80acf74e7df752fae22bc1590715567702d6fde # Parent 8607483b130f776ea658c8c69de74f1619950f01 patch 8.1.0150: insufficient test coverage for Tcl commit https://github.com/vim/vim/commit/fd34cebe9a3a179a5639355c43d2d4959182a279 Author: Bram Moolenaar Date: Wed Jul 4 22:36:46 2018 +0200 patch 8.1.0150: insufficient test coverage for Tcl Problem: Insufficient test coverage for Tcl. Solution: Add more tests. (Dominique Pelle, closes https://github.com/vim/vim/issues/3140) diff --git a/src/testdir/test_tcl.vim b/src/testdir/test_tcl.vim --- a/src/testdir/test_tcl.vim +++ b/src/testdir/test_tcl.vim @@ -4,20 +4,634 @@ if !has('tcl') finish end -function Test_tcldo() +" Helper function as there is no builtin tcleval() function similar +" to perleval, luaevel(), pyeval(), etc. +func TclEval(tcl_expr) + let s = split(execute('tcl ' . a:tcl_expr), "\n") + return (len(s) == 0) ? '' : s[-1] +endfunc + +func Test_tcldo() " Check deleting lines does not trigger ml_get error. new call setline(1, ['one', 'two', 'three']) tcldo ::vim::command %d_ bwipe! - " Check switching to another buffer does not trigger ml_get error. + " Check that switching to another buffer does not trigger ml_get error. new let wincount = winnr('$') call setline(1, ['one', 'two', 'three']) tcldo ::vim::command new call assert_equal(wincount + 1, winnr('$')) + %bwipe! +endfunc + +" Test :tcldo with a range +func Test_tcldo_range() + new + call setline(1, ['line1', 'line2', 'line3', 'line4']) + 2,3tcldo set line [string toupper $line] + call assert_equal(['line1', 'LINE2', 'LINE3', 'line4'], getline(1, '$')) bwipe! +endfunc + +" Test ::vim::beep +func Test_vim_beep() + call assert_beeps('tcl ::vim::beep') + call assert_fails('tcl ::vim::beep x', 'wrong # args: should be "::vim::beep"') +endfunc + +" Test ::vim::buffer +func Test_vim_buffer() + " Test ::vim::buffer {nr} + e Xfoo1 + call setline(1, ['foobar']) + let bn1 = bufnr('%') + let b1 = TclEval('::vim::buffer ' . bn1) + call assert_equal(b1, TclEval('set ::vim::current(buffer)')) + + new Xfoo2 + call setline(1, ['barfoo']) + let bn2 = bufnr('%') + let b2 = TclEval('::vim::buffer ' . bn2) + call assert_equal(b2, TclEval('set ::vim::current(buffer)')) + + call assert_match('Xfoo1$', TclEval(b1 . ' name')) + call assert_match('Xfoo2$', TclEval(b2 . ' name')) + + " Test ::vim::buffer exists {nr} + call assert_match('^[1-9]\d*$', TclEval('::vim::buffer exists ' . bn1)) + call assert_match('^[1-9]\d*$', TclEval('::vim::buffer exists ' . bn2)) + call assert_equal('0', TclEval('::vim::buffer exists 54321')) + + " Test ::vim::buffer list + call assert_equal('2', TclEval('llength [::vim::buffer list]')) + call assert_equal(b1.' '.b2, TclEval('::vim::buffer list')) + tcl <