@@ -110,6 +110,17 @@ func Test_vim_option()
110110 call assert_equal (' +4' , &cc )
111111 call assert_equal (' +4' , TclEval (' ::vim::option cc' ))
112112
113+ " Test boolean option with 'toggle', 'on' and 'off' keywords.
114+ call assert_equal (' 0' , TclEval (' ::vim::option nu toggle' ))
115+ call assert_equal (1 , &nu )
116+ call assert_equal (' 1' , TclEval (' ::vim::option nu toggle' ))
117+ call assert_equal (0 , &nu )
118+ call assert_equal (' 0' , TclEval (' ::vim::option nu on' ))
119+ call assert_equal (1 , &nu )
120+ call assert_equal (' 1' , TclEval (' ::vim::option nu off' ))
121+ call assert_equal (0 , &nu )
122+
123+ call assert_fails (' tcl ::vim::option nu x' , ' expected integer but got "x"' )
113124 call assert_fails (' tcl ::vim::option xxx' , ' unknown vimOption' )
114125 call assert_fails (' tcl ::vim::option' ,
115126 \ ' wrong # args: should be "::vim::option vimOption ?value?"' )
@@ -124,13 +135,19 @@ func Test_vim_expr()
124135
125136 call assert_fails (' tcl ::vim::expr x y' ,
126137 \ ' wrong # args: should be "::vim::expr vimExpr"' )
138+ call assert_fails (' tcl ::vim::expr 1-' , ' E15: Invalid expression: 1-' )
127139endfunc
128140
129141" Test ::vim::command
130142func Test_vim_command ()
131143 call assert_equal (' hello world' ,
132144 \ TclEval (' ::vim::command {echo "hello world"}' ))
133145
146+ " Check that if ::vim::command created a new Tcl interpreter, it is removed.
147+ tcl set foo 123
148+ call assert_equal (' 321' , TclEval (' ::vim::command "tcl set foo 321"' ))
149+ call assert_equal (' 123' , TclEval (' set foo' ))
150+
134151 " With the -quiet option, the error should silently be ignored.
135152 call assert_equal (' ' , TclEval (' ::vim::command -quiet xyz' ))
136153
@@ -142,6 +159,8 @@ func Test_vim_command()
142159
143160 " With the -quiet option, the error should silently be ignored.
144161 call assert_equal (' ' , TclEval (' ::vim::command -quiet xyz' ))
162+
163+ tcl unset foo
145164endfunc
146165
147166" Test ::vim::window list
@@ -164,12 +183,15 @@ endfunc
164183
165184" Test output messages
166185func Test_output ()
167- call assert_fails (' tcl puts vimerr "an error"' , ' an error' )
168- tcl puts vimout " a message"
169- tcl puts " another message"
186+ call assert_fails (' tcl puts vimerr "error #1"' , ' error #1' )
187+ call assert_fails (' tcl puts stderr "error #2"' , ' error #2' )
188+ tcl puts vimout " message #1"
189+ tcl puts stdout " message #2"
190+ tcl puts " message #3"
170191 let messages = split (execute (' message' ), " \n " )
171- call assert_equal (' a message' , messages [-2 ])
172- call assert_equal (' another message' , messages [-1 ])
192+ call assert_equal (' message #3' , messages [-1 ])
193+ call assert_equal (' message #2' , messages [-2 ])
194+ call assert_equal (' message #1' , messages [-3 ])
173195
174196 call assert_fails (' tcl puts' ,
175197 \ ' wrong # args: should be "puts ?-nonewline? ?channelId? string"' )
@@ -447,13 +469,21 @@ func Test_buffer_set()
447469 call setline (1 , [' line1' , ' line2' , ' line3' , ' line4' , ' line5' ])
448470 tcl $ ::vim :: current (buffer ) set 2 a
449471 call assert_equal ([' line1' , ' a' , ' line3' , ' line4' , ' line5' ], getline (1 , ' $' ))
472+
473+ " Test with fewer replacing lines than replaced lines: lines get deleted.
450474 tcl $ ::vim :: current (buffer ) set 3 4 b
451475 call assert_equal ([' line1' , ' a' , ' b' , ' line5' ], getline (1 , ' $' ))
452476 tcl $ ::vim :: current (buffer ) set 4 3 c
453477 call assert_equal ([' line1' , ' a' , ' c' ], getline (1 , ' $' ))
454478
479+ " Test with more replacing lines than replaced lines: lines get added.
480+ tcl $ ::vim :: current (buffer ) set 2 3 {x y z}
481+ call assert_equal ([' line1' , ' x' , ' y' , ' z' ], getline (1 , ' $' ))
482+ tcl $ ::vim :: current (buffer ) set 3 2 {X Y Z}
483+ call assert_equal ([' line1' , ' X' , ' Y' , ' Z' , ' z' ], getline (1 , ' $' ))
484+
455485 call assert_fails (' tcl $::vim::current(buffer) set 0 "x"' , ' line number out of range' )
456- call assert_fails (' tcl $::vim::current(buffer) set 5 "x"' , ' line number out of range' )
486+ call assert_fails (' tcl $::vim::current(buffer) set 6 "x"' , ' line number out of range' )
457487
458488 call assert_fails (' tcl $::vim::current(buffer) set' , ' wrong # args:' )
459489 bwipe!
@@ -622,7 +652,7 @@ func Test_tclfile_error()
622652 call delete (' Xtcl_file' )
623653endfunc
624654
625- " Test exiting current Tcl interprepter and re-creating one.
655+ " Test exiting current Tcl interpreter and re-creating one.
626656func Test_tcl_exit ()
627657 tcl set foo " foo"
628658 call assert_fails (' tcl exit 3' , ' E572: exit code 3' )
0 commit comments