comparison src/testdir/test_tcl.vim @ 14294:6c5c8de48152 v8.1.0163

patch 8.1.0163: insufficient testing for Tcl commit https://github.com/vim/vim/commit/2549acf794109731eab693bd396bb863d0e2cff4 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 7 22:42:01 2018 +0200 patch 8.1.0163: insufficient testing for Tcl Problem: Insufficient testing for Tcl. Solution: Add a few more tests. (Dominique Pelle, closes https://github.com/vim/vim/issues/3166)
author Christian Brabandt <cb@256bit.org>
date Sat, 07 Jul 2018 22:45:05 +0200
parents c80acf74e7df
children c15bef307de6
comparison
equal deleted inserted replaced
14293:f1e7e8edd216 14294:6c5c8de48152
108 " Test setting option 'cc' (it returns the old option value) 108 " Test setting option 'cc' (it returns the old option value)
109 call assert_equal('3,5', TclEval('::vim::option cc +4')) 109 call assert_equal('3,5', TclEval('::vim::option cc +4'))
110 call assert_equal('+4', &cc) 110 call assert_equal('+4', &cc)
111 call assert_equal('+4', TclEval('::vim::option cc')) 111 call assert_equal('+4', TclEval('::vim::option cc'))
112 112
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"')
113 call assert_fails('tcl ::vim::option xxx', 'unknown vimOption') 124 call assert_fails('tcl ::vim::option xxx', 'unknown vimOption')
114 call assert_fails('tcl ::vim::option', 125 call assert_fails('tcl ::vim::option',
115 \ 'wrong # args: should be "::vim::option vimOption ?value?"') 126 \ 'wrong # args: should be "::vim::option vimOption ?value?"')
116 127
117 set cc& 128 set cc&
122 call assert_equal(string(char2nr('X')), 133 call assert_equal(string(char2nr('X')),
123 \ TclEval('::vim::expr char2nr("X")')) 134 \ TclEval('::vim::expr char2nr("X")'))
124 135
125 call assert_fails('tcl ::vim::expr x y', 136 call assert_fails('tcl ::vim::expr x y',
126 \ 'wrong # args: should be "::vim::expr vimExpr"') 137 \ 'wrong # args: should be "::vim::expr vimExpr"')
138 call assert_fails('tcl ::vim::expr 1-', 'E15: Invalid expression: 1-')
127 endfunc 139 endfunc
128 140
129 " Test ::vim::command 141 " Test ::vim::command
130 func Test_vim_command() 142 func Test_vim_command()
131 call assert_equal('hello world', 143 call assert_equal('hello world',
132 \ TclEval('::vim::command {echo "hello world"}')) 144 \ TclEval('::vim::command {echo "hello world"}'))
145
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'))
133 150
134 " With the -quiet option, the error should silently be ignored. 151 " With the -quiet option, the error should silently be ignored.
135 call assert_equal('', TclEval('::vim::command -quiet xyz')) 152 call assert_equal('', TclEval('::vim::command -quiet xyz'))
136 153
137 call assert_fails('tcl ::vim::command', 154 call assert_fails('tcl ::vim::command',
140 call assert_fails('tcl ::vim::command xyz', 157 call assert_fails('tcl ::vim::command xyz',
141 \ 'E492: Not an editor command: xyz') 158 \ 'E492: Not an editor command: xyz')
142 159
143 " With the -quiet option, the error should silently be ignored. 160 " With the -quiet option, the error should silently be ignored.
144 call assert_equal('', TclEval('::vim::command -quiet xyz')) 161 call assert_equal('', TclEval('::vim::command -quiet xyz'))
162
163 tcl unset foo
145 endfunc 164 endfunc
146 165
147 " Test ::vim::window list 166 " Test ::vim::window list
148 func Test_vim_window_list() 167 func Test_vim_window_list()
149 e Xfoo1 168 e Xfoo1
162 %bwipe 181 %bwipe
163 endfunc 182 endfunc
164 183
165 " Test output messages 184 " Test output messages
166 func Test_output() 185 func Test_output()
167 call assert_fails('tcl puts vimerr "an error"', 'an error') 186 call assert_fails('tcl puts vimerr "error #1"', 'error #1')
168 tcl puts vimout "a message" 187 call assert_fails('tcl puts stderr "error #2"', 'error #2')
169 tcl puts "another message" 188 tcl puts vimout "message #1"
189 tcl puts stdout "message #2"
190 tcl puts "message #3"
170 let messages = split(execute('message'), "\n") 191 let messages = split(execute('message'), "\n")
171 call assert_equal('a message', messages[-2]) 192 call assert_equal('message #3', messages[-1])
172 call assert_equal('another message', messages[-1]) 193 call assert_equal('message #2', messages[-2])
194 call assert_equal('message #1', messages[-3])
173 195
174 call assert_fails('tcl puts', 196 call assert_fails('tcl puts',
175 \ 'wrong # args: should be "puts ?-nonewline? ?channelId? string"') 197 \ 'wrong # args: should be "puts ?-nonewline? ?channelId? string"')
176 endfunc 198 endfunc
177 199
445 func Test_buffer_set() 467 func Test_buffer_set()
446 new 468 new
447 call setline(1, ['line1', 'line2', 'line3', 'line4', 'line5']) 469 call setline(1, ['line1', 'line2', 'line3', 'line4', 'line5'])
448 tcl $::vim::current(buffer) set 2 a 470 tcl $::vim::current(buffer) set 2 a
449 call assert_equal(['line1', 'a', 'line3', 'line4', 'line5'], getline(1, '$')) 471 call assert_equal(['line1', 'a', 'line3', 'line4', 'line5'], getline(1, '$'))
472
473 " Test with fewer replacing lines than replaced lines: lines get deleted.
450 tcl $::vim::current(buffer) set 3 4 b 474 tcl $::vim::current(buffer) set 3 4 b
451 call assert_equal(['line1', 'a', 'b', 'line5'], getline(1, '$')) 475 call assert_equal(['line1', 'a', 'b', 'line5'], getline(1, '$'))
452 tcl $::vim::current(buffer) set 4 3 c 476 tcl $::vim::current(buffer) set 4 3 c
453 call assert_equal(['line1', 'a', 'c'], getline(1, '$')) 477 call assert_equal(['line1', 'a', 'c'], getline(1, '$'))
454 478
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
455 call assert_fails('tcl $::vim::current(buffer) set 0 "x"', 'line number out of range') 485 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')
457 487
458 call assert_fails('tcl $::vim::current(buffer) set', 'wrong # args:') 488 call assert_fails('tcl $::vim::current(buffer) set', 'wrong # args:')
459 bwipe! 489 bwipe!
460 endfunc 490 endfunc
461 491
620 call assert_fails('tclfile Xtcl_file', 'invalid command name "xyz"') 650 call assert_fails('tclfile Xtcl_file', 'invalid command name "xyz"')
621 651
622 call delete('Xtcl_file') 652 call delete('Xtcl_file')
623 endfunc 653 endfunc
624 654
625 " Test exiting current Tcl interprepter and re-creating one. 655 " Test exiting current Tcl interpreter and re-creating one.
626 func Test_tcl_exit() 656 func Test_tcl_exit()
627 tcl set foo "foo" 657 tcl set foo "foo"
628 call assert_fails('tcl exit 3', 'E572: exit code 3') 658 call assert_fails('tcl exit 3', 'E572: exit code 3')
629 659
630 " The Tcl interpreter should have been deleted and a new one 660 " The Tcl interpreter should have been deleted and a new one