1" Test for the various 'cpoptions' (cpo) flags
2
3source check.vim
4source shared.vim
5source view_util.vim
6
7" Test for the 'a' flag in 'cpo'. Reading a file should set the alternate
8" file name.
9func Test_cpo_a()
10  let save_cpo = &cpo
11  call writefile(['one'], 'Xfile')
12  " Wipe out all the buffers, so that the alternate file is empty
13  edit Xfoo | %bw
14  set cpo-=a
15  new
16  read Xfile
17  call assert_equal('', @#)
18  %d
19  set cpo+=a
20  read Xfile
21  call assert_equal('Xfile', @#)
22  close!
23  call delete('Xfile')
24  let &cpo = save_cpo
25endfunc
26
27" Test for the 'A' flag in 'cpo'. Writing a file should set the alternate
28" file name.
29func Test_cpo_A()
30  let save_cpo = &cpo
31  " Wipe out all the buffers, so that the alternate file is empty
32  edit Xfoo | %bw
33  set cpo-=A
34  new Xfile1
35  write Xfile2
36  call assert_equal('', @#)
37  %bw
38  call delete('Xfile2')
39  new Xfile1
40  set cpo+=A
41  write Xfile2
42  call assert_equal('Xfile2', @#)
43  close!
44  call delete('Xfile2')
45  let &cpo = save_cpo
46endfunc
47
48" Test for the 'b' flag in 'cpo'. "\|" at the end of a map command is
49" recognized as the end of the map.
50func Test_cpo_b()
51  let save_cpo = &cpo
52  set cpo+=b
53  nnoremap <F5> :pwd\<CR>\|let i = 1
54  call assert_equal(':pwd\<CR>\', maparg('<F5>'))
55  nunmap <F5>
56  exe "nnoremap <F5> :pwd\<C-V>|let i = 1"
57  call assert_equal(':pwd|let i = 1', maparg('<F5>'))
58  nunmap <F5>
59  set cpo-=b
60  nnoremap <F5> :pwd\<CR>\|let i = 1
61  call assert_equal(':pwd\<CR>|let i = 1', maparg('<F5>'))
62  let &cpo = save_cpo
63  nunmap <F5>
64endfunc
65
66" Test for the 'B' flag in 'cpo'. A backslash in mappings, abbreviations, user
67" commands and menu commands has no special meaning.
68func Test_cpo_B()
69  let save_cpo = &cpo
70  new
71  set cpo-=B
72  iabbr <buffer> abc ab\<BS>d
73  exe "normal iabc "
74  call assert_equal('ab<BS>d ', getline(1))
75  %d
76  set cpo+=B
77  iabbr <buffer> abc ab\<BS>d
78  exe "normal iabc "
79  call assert_equal('abd ', getline(1))
80  close!
81  let &cpo = save_cpo
82endfunc
83
84" Test for the 'c' flag in 'cpo'.
85func Test_cpo_c()
86  let save_cpo = &cpo
87  set cpo+=c
88  new
89  call setline(1, ' abababababab')
90  exe "normal gg/abab\<CR>"
91  call assert_equal(3, searchcount().total)
92  set cpo-=c
93  exe "normal gg/abab\<CR>"
94  call assert_equal(5, searchcount().total)
95  close!
96  let &cpo = save_cpo
97endfunc
98
99" Test for the 'C' flag in 'cpo' (line continuation)
100func Test_cpo_C()
101  let save_cpo = &cpo
102  call writefile(['let l = [', '\ 1,', '\ 2]'], 'Xfile')
103  set cpo-=C
104  source Xfile
105  call assert_equal([1, 2], g:l)
106  set cpo+=C
107  call assert_fails('source Xfile', ['E697:', 'E10:'])
108  call delete('Xfile')
109  let &cpo = save_cpo
110endfunc
111
112" Test for the 'd' flag in 'cpo' (tags relative to the current file)
113func Test_cpo_d()
114  let save_cpo = &cpo
115  call mkdir('Xdir')
116  call writefile(["one\tXfile1\t/^one$/"], 'tags')
117  call writefile(["two\tXfile2\t/^two$/"], 'Xdir/tags')
118  set tags=./tags
119  set cpo-=d
120  edit Xdir/Xfile
121  call assert_equal('two', taglist('.*')[0].name)
122  set cpo+=d
123  call assert_equal('one', taglist('.*')[0].name)
124  %bw!
125  call delete('tags')
126  call delete('Xdir', 'rf')
127  set tags&
128  let &cpo = save_cpo
129endfunc
130
131" Test for the 'D' flag in 'cpo' (digraph after a r, f or t)
132func Test_cpo_D()
133  CheckFeature digraphs
134  let save_cpo = &cpo
135  new
136  set cpo-=D
137  call setline(1, 'abcdefgh|')
138  exe "norm! 1gg0f\<c-k>!!"
139  call assert_equal(9, col('.'))
140  set cpo+=D
141  exe "norm! 1gg0f\<c-k>!!"
142  call assert_equal(1, col('.'))
143  set cpo-=D
144  close!
145  let &cpo = save_cpo
146endfunc
147
148" Test for the 'e' flag in 'cpo'
149func Test_cpo_e()
150  let save_cpo = &cpo
151  let @a='let i = 45'
152  set cpo+=e
153  call feedkeys(":@a\<CR>", 'xt')
154  call assert_equal(45, i)
155  set cpo-=e
156  call feedkeys(":@a\<CR>6\<CR>", 'xt')
157  call assert_equal(456, i)
158  let &cpo = save_cpo
159endfunc
160
161" Test for the 'E' flag in 'cpo' with yank, change, delete, etc. operators
162func Test_cpo_E()
163  new
164  call setline(1, '')
165  set cpo+=E
166  " yank an empty line
167  call assert_beeps('normal "ayl')
168  " change an empty line
169  call assert_beeps('normal lcTa')
170  " delete an empty line
171  call assert_beeps('normal D')
172  call assert_beeps('normal dl')
173  call assert_equal('', getline(1))
174  " change case of an empty line
175  call assert_beeps('normal gul')
176  call assert_beeps('normal gUl')
177  " replace a character
178  call assert_beeps('normal vrx')
179  " increment and decrement
180  call assert_beeps('exe "normal v\<C-A>"')
181  call assert_beeps('exe "normal v\<C-X>"')
182  set cpo-=E
183  close!
184endfunc
185
186" Test for the 'f' flag in 'cpo' (read in an empty buffer sets the file name)
187func Test_cpo_f()
188  let save_cpo = &cpo
189  new
190  set cpo-=f
191  read test_cpoptions.vim
192  call assert_equal('', @%)
193  %d
194  set cpo+=f
195  read test_cpoptions.vim
196  call assert_equal('test_cpoptions.vim', @%)
197  close!
198  let &cpo = save_cpo
199endfunc
200
201" Test for the 'F' flag in 'cpo' (write in an empty buffer sets the file name)
202func Test_cpo_F()
203  let save_cpo = &cpo
204  new
205  set cpo-=F
206  write Xfile
207  call assert_equal('', @%)
208  call delete('Xfile')
209  set cpo+=F
210  write Xfile
211  call assert_equal('Xfile', @%)
212  close!
213  call delete('Xfile')
214  let &cpo = save_cpo
215endfunc
216
217" Test for the 'g' flag in 'cpo' (jump to line 1 when re-editing a file)
218func Test_cpo_g()
219  let save_cpo = &cpo
220  new test_cpoptions.vim
221  set cpo-=g
222  normal 20G
223  edit
224  call assert_equal(20, line('.'))
225  set cpo+=g
226  edit
227  call assert_equal(1, line('.'))
228  close!
229  let &cpo = save_cpo
230endfunc
231
232" Test for inserting text in a line with only spaces ('H' flag in 'cpoptions')
233func Test_cpo_H()
234  let save_cpo = &cpo
235  new
236  set cpo-=H
237  call setline(1, '    ')
238  normal! Ia
239  call assert_equal('    a', getline(1))
240  set cpo+=H
241  call setline(1, '    ')
242  normal! Ia
243  call assert_equal('   a ', getline(1))
244  close!
245  let &cpo = save_cpo
246endfunc
247
248" TODO: Add a test for the 'i' flag in 'cpo'
249" Interrupting the reading of a file will leave it modified.
250
251" Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys)
252func Test_cpo_I()
253  let save_cpo = &cpo
254  new
255  setlocal autoindent
256  set cpo+=I
257  exe "normal i    one\<CR>\<Up>"
258  call assert_equal('    ', getline(2))
259  set cpo-=I
260  %d
261  exe "normal i    one\<CR>\<Up>"
262  call assert_equal('', getline(2))
263  close!
264  let &cpo = save_cpo
265endfunc
266
267" Test for the 'j' flag in 'cpo' is in the test_join.vim file.
268
269" Test for the 'J' flag in 'cpo' (two spaces after a sentence)
270func Test_cpo_J()
271  let save_cpo = &cpo
272  new
273  set cpo-=J
274  call setline(1, 'one. two!  three? four."''  five.)]')
275  normal 0
276  for colnr in [6, 12, 19, 28, 34]
277    normal )
278    call assert_equal(colnr, col('.'))
279  endfor
280  for colnr in [28, 19, 12, 6, 1]
281    normal (
282    call assert_equal(colnr, col('.'))
283  endfor
284  set cpo+=J
285  normal 0
286  for colnr in [12, 28, 34]
287    normal )
288    call assert_equal(colnr, col('.'))
289  endfor
290  for colnr in [28, 12, 1]
291    normal (
292    call assert_equal(colnr, col('.'))
293  endfor
294  close!
295  let &cpo = save_cpo
296endfunc
297
298" TODO: Add a test for the 'k' flag in 'cpo'.
299" Disable the recognition of raw key codes in mappings, abbreviations, and the
300" "to" part of menu commands.
301
302" TODO: Add a test for the 'K' flag in 'cpo'.
303" Don't wait for a key code to complete when it is halfway a mapping.
304
305" Test for the 'l' flag in 'cpo' (backslash in a [] range)
306func Test_cpo_l()
307  let save_cpo = &cpo
308  new
309  call setline(1, ['', "a\tc" .. '\t'])
310  set cpo-=l
311  exe 'normal gg/[\t]' .. "\<CR>"
312  call assert_equal([2, 8], [col('.'), virtcol('.')])
313  set cpo+=l
314  exe 'normal gg/[\t]' .. "\<CR>"
315  call assert_equal([4, 10], [col('.'), virtcol('.')])
316  close!
317  let &cpo = save_cpo
318endfunc
319
320" Test for inserting tab in virtual replace mode ('L' flag in 'cpoptions')
321func Test_cpo_L()
322  let save_cpo = &cpo
323  new
324  set cpo-=L
325  call setline(1, 'abcdefghijklmnopqr')
326  exe "normal 0gR\<Tab>"
327  call assert_equal("\<Tab>ijklmnopqr", getline(1))
328  set cpo+=L
329  set list
330  call setline(1, 'abcdefghijklmnopqr')
331  exe "normal 0gR\<Tab>"
332  call assert_equal("\<Tab>cdefghijklmnopqr", getline(1))
333  set nolist
334  call setline(1, 'abcdefghijklmnopqr')
335  exe "normal 0gR\<Tab>"
336  call assert_equal("\<Tab>ijklmnopqr", getline(1))
337  close!
338  let &cpo = save_cpo
339endfunc
340
341" TODO: Add a test for the 'm' flag in 'cpo'.
342" When included, a showmatch will always wait half a second.  When not
343" included, a showmatch will wait half a second or until a character is typed.
344
345" Test for the 'M' flag in 'cpo' (% with escape parenthesis)
346func Test_cpo_M()
347  let save_cpo = &cpo
348  new
349  call setline(1, ['( \( )', '\( ( \)'])
350
351  set cpo-=M
352  call cursor(1, 1)
353  normal %
354  call assert_equal(6, col('.'))
355  call cursor(1, 4)
356  call assert_beeps('normal %')
357  call cursor(2, 2)
358  normal %
359  call assert_equal(7, col('.'))
360  call cursor(2, 4)
361  call assert_beeps('normal %')
362
363  set cpo+=M
364  call cursor(1, 4)
365  normal %
366  call assert_equal(6, col('.'))
367  call cursor(1, 1)
368  call assert_beeps('normal %')
369  call cursor(2, 4)
370  normal %
371  call assert_equal(7, col('.'))
372  call cursor(2, 1)
373  call assert_beeps('normal %')
374
375  close!
376  let &cpo = save_cpo
377endfunc
378
379" Test for the 'n' flag in 'cpo' (using number column for wrapped lines)
380func Test_cpo_n()
381  let save_cpo = &cpo
382  new
383  call setline(1, repeat('a', &columns))
384  setlocal number
385  set cpo-=n
386  redraw!
387  call assert_equal('    aaaa', Screenline(2))
388  set cpo+=n
389  redraw!
390  call assert_equal('aaaa', Screenline(2))
391  close!
392  let &cpo = save_cpo
393endfunc
394
395" Test for the 'o' flag in 'cpo' (line offset to search command)
396func Test_cpo_o()
397  let save_cpo = &cpo
398  new
399  call setline(1, ['', 'one', 'two', 'three', 'one', 'two', 'three'])
400  set cpo-=o
401  exe "normal /one/+2\<CR>"
402  normal n
403  call assert_equal(7, line('.'))
404  set cpo+=o
405  exe "normal /one/+2\<CR>"
406  normal n
407  call assert_equal(5, line('.'))
408  close!
409  let &cpo = save_cpo
410endfunc
411
412" Test for the 'O' flag in 'cpo' (overwriting an existing file)
413func Test_cpo_O()
414  let save_cpo = &cpo
415  new Xfile
416  call setline(1, 'one')
417  call writefile(['two'], 'Xfile')
418  set cpo-=O
419  call assert_fails('write', 'E13:')
420  set cpo+=O
421  write
422  call assert_equal(['one'], readfile('Xfile'))
423  close!
424  call delete('Xfile')
425  let &cpo = save_cpo
426endfunc
427
428" Test for the 'p' flag in 'cpo' is in the test_lispwords.vim file.
429
430" Test for the 'P' flag in 'cpo' (appending to a file sets the current file
431" name)
432func Test_cpo_P()
433  let save_cpo = &cpo
434  call writefile([], 'Xfile')
435  new
436  call setline(1, 'one')
437  set cpo+=F
438  set cpo-=P
439  write >> Xfile
440  call assert_equal('', @%)
441  set cpo+=P
442  write >> Xfile
443  call assert_equal('Xfile', @%)
444  close!
445  call delete('Xfile')
446  let &cpo = save_cpo
447endfunc
448
449" Test for the 'q' flag in 'cpo' (joining multiple lines)
450func Test_cpo_q()
451  let save_cpo = &cpo
452  new
453  call setline(1, ['one', 'two', 'three', 'four', 'five'])
454  set cpo-=q
455  normal gg4J
456  call assert_equal(14, col('.'))
457  %d
458  call setline(1, ['one', 'two', 'three', 'four', 'five'])
459  set cpo+=q
460  normal gg4J
461  call assert_equal(4, col('.'))
462  close!
463  let &cpo = save_cpo
464endfunc
465
466" Test for the 'r' flag in 'cpo' (redo command with a search motion)
467func Test_cpo_r()
468  let save_cpo = &cpo
469  new
470  call setline(1, repeat(['one two three four'], 2))
471  set cpo-=r
472  exe "normal ggc/two\<CR>abc "
473  let @/ = 'three'
474  normal 2G.
475  call assert_equal('abc two three four', getline(2))
476  %d
477  call setline(1, repeat(['one two three four'], 2))
478  set cpo+=r
479  exe "normal ggc/two\<CR>abc "
480  let @/ = 'three'
481  normal 2G.
482  call assert_equal('abc three four', getline(2))
483  close!
484  let &cpo = save_cpo
485endfunc
486
487" Test for the 'R' flag in 'cpo' (clear marks after a filter command)
488func Test_cpo_R()
489  CheckUnix
490  let save_cpo = &cpo
491  new
492  call setline(1, ['three', 'one', 'two'])
493  set cpo-=R
494  3mark r
495  %!sort
496  call assert_equal(3, line("'r"))
497  %d
498  call setline(1, ['three', 'one', 'two'])
499  set cpo+=R
500  3mark r
501  %!sort
502  call assert_equal(0, line("'r"))
503  close!
504  let &cpo = save_cpo
505endfunc
506
507" TODO: Add a test for the 's' flag in 'cpo'.
508" Set buffer options when entering the buffer for the first time.  If not
509" present the options are set when the buffer is created.
510
511" Test for the 'S' flag in 'cpo' (copying buffer options)
512func Test_cpo_S()
513  let save_cpo = &cpo
514  new Xfile1
515  set noautoindent
516  new Xfile2
517  set cpo-=S
518  set autoindent
519  wincmd p
520  call assert_equal(0, &autoindent)
521  wincmd p
522  call assert_equal(1, &autoindent)
523  set cpo+=S
524  wincmd p
525  call assert_equal(1, &autoindent)
526  set noautoindent
527  wincmd p
528  call assert_equal(0, &autoindent)
529  wincmd t
530  close!
531  close!
532  let &cpo = save_cpo
533endfunc
534
535" Test for the 't' flag in 'cpo' is in the test_tagjump.vim file.
536
537" Test for the 'u' flag in 'cpo' (Vi-compatible undo)
538func Test_cpo_u()
539  let save_cpo = &cpo
540  new
541  set cpo-=u
542  exe "normal iabc\<C-G>udef\<C-G>ughi"
543  normal uu
544  call assert_equal('abc', getline(1))
545  %d
546  set cpo+=u
547  exe "normal iabc\<C-G>udef\<C-G>ughi"
548  normal uu
549  call assert_equal('abcdefghi', getline(1))
550  close!
551  let &cpo = save_cpo
552endfunc
553
554" TODO: Add a test for the 'v' flag in 'cpo'.
555" Backspaced characters remain visible on the screen in Insert mode.
556
557" Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one
558" character)
559func Test_cpo_w()
560  let save_cpo = &cpo
561  new
562  set cpo+=w
563  call setline(1, 'here      are   some words')
564  norm! 1gg0elcwZZZ
565  call assert_equal('hereZZZ     are   some words', getline('.'))
566  norm! 1gg2elcWYYY
567  call assert_equal('hereZZZ     areYYY  some words', getline('.'))
568  set cpo-=w
569  call setline(1, 'here      are   some words')
570  norm! 1gg0elcwZZZ
571  call assert_equal('hereZZZare   some words', getline('.'))
572  norm! 1gg2elcWYYY
573  call assert_equal('hereZZZare   someYYYwords', getline('.'))
574  close!
575  let &cpo = save_cpo
576endfunc
577
578" Test for the 'W' flag in 'cpo' is in the test_writefile.vim file
579
580" Test for the 'x' flag in 'cpo' (Esc on command-line executes command)
581func Test_cpo_x()
582  let save_cpo = &cpo
583  set cpo-=x
584  let i = 1
585  call feedkeys(":let i=10\<Esc>", 'xt')
586  call assert_equal(1, i)
587  set cpo+=x
588  call feedkeys(":let i=10\<Esc>", 'xt')
589  call assert_equal(10, i)
590  let &cpo = save_cpo
591endfunc
592
593" Test for the 'X' flag in 'cpo' ('R' with a count)
594func Test_cpo_X()
595  let save_cpo = &cpo
596  new
597  call setline(1, 'aaaaaa')
598  set cpo-=X
599  normal gg4Rx
600  call assert_equal('xxxxaa', getline(1))
601  normal ggRy
602  normal 4.
603  call assert_equal('yyyyaa', getline(1))
604  call setline(1, 'aaaaaa')
605  set cpo+=X
606  normal gg4Rx
607  call assert_equal('xxxxaaaaa', getline(1))
608  normal ggRy
609  normal 4.
610  call assert_equal('yyyyxxxaaaaa', getline(1))
611  close!
612  let &cpo = save_cpo
613endfunc
614
615" Test for the 'y' flag in 'cpo' (repeating a yank command)
616func Test_cpo_y()
617  let save_cpo = &cpo
618  new
619  call setline(1, ['one', 'two'])
620  set cpo-=y
621  normal ggyy
622  normal 2G.
623  call assert_equal("one\n", @")
624  %d
625  call setline(1, ['one', 'two'])
626  set cpo+=y
627  normal ggyy
628  normal 2G.
629  call assert_equal("two\n", @")
630  close!
631  let &cpo = save_cpo
632endfunc
633
634" Test for the 'Z' flag in 'cpo' (write! resets 'readonly')
635func Test_cpo_Z()
636  let save_cpo = &cpo
637  call writefile([], 'Xfile')
638  new Xfile
639  setlocal readonly
640  set cpo-=Z
641  write!
642  call assert_equal(0, &readonly)
643  set cpo+=Z
644  setlocal readonly
645  write!
646  call assert_equal(1, &readonly)
647  close!
648  call delete('Xfile')
649  let &cpo = save_cpo
650endfunc
651
652" Test for the '!' flag in 'cpo' is in the test_normal.vim file
653
654" Test for displaying dollar when changing text ('$' flag in 'cpoptions')
655func Test_cpo_dollar()
656  new
657  let g:Line = ''
658  func SaveFirstLine()
659    let g:Line = Screenline(1)
660    return ''
661  endfunc
662  inoremap <expr> <buffer> <F2> SaveFirstLine()
663  call test_override('redraw_flag', 1)
664  set cpo+=$
665  call setline(1, 'one two three')
666  redraw!
667  exe "normal c2w\<F2>vim"
668  call assert_equal('one tw$ three', g:Line)
669  call assert_equal('vim three', getline(1))
670  set cpo-=$
671  call test_override('ALL', 0)
672  delfunc SaveFirstLine
673  %bw!
674endfunc
675
676" Test for the '%' flag in 'cpo' (parenthesis matching inside strings)
677func Test_cpo_percent()
678  let save_cpo = &cpo
679  new
680  call setline(1, '    if (strcmp("ab)cd(", s))')
681  set cpo-=%
682  normal 8|%
683  call assert_equal(28, col('.'))
684  normal 15|%
685  call assert_equal(27, col('.'))
686  normal 27|%
687  call assert_equal(15, col('.'))
688  call assert_beeps("normal 19|%")
689  call assert_beeps("normal 22|%")
690  set cpo+=%
691  normal 8|%
692  call assert_equal(28, col('.'))
693  normal 15|%
694  call assert_equal(19, col('.'))
695  normal 27|%
696  call assert_equal(22, col('.'))
697  normal 19|%
698  call assert_equal(15, col('.'))
699  normal 22|%
700  call assert_equal(27, col('.'))
701  close!
702  let &cpo = save_cpo
703endfunc
704
705" Test for cursor movement with '-' in 'cpoptions'
706func Test_cpo_minus()
707  new
708  call setline(1, ['foo', 'bar', 'baz'])
709  let save_cpo = &cpo
710  set cpo+=-
711  call assert_beeps('normal 10j')
712  call assert_equal(1, line('.'))
713  normal G
714  call assert_beeps('normal 10k')
715  call assert_equal(3, line('.'))
716  call assert_fails(10, 'E16:')
717  close!
718  let &cpo = save_cpo
719endfunc
720
721" Test for the '+' flag in 'cpo' ('write file' command resets the 'modified'
722" flag)
723func Test_cpo_plus()
724  let save_cpo = &cpo
725  call writefile([], 'Xfile')
726  new Xfile
727  call setline(1, 'foo')
728  write X1
729  call assert_equal(1, &modified)
730  set cpo+=+
731  write X2
732  call assert_equal(0, &modified)
733  close!
734  call delete('Xfile')
735  call delete('X1')
736  call delete('X2')
737  let &cpo = save_cpo
738endfunc
739
740" Test for the '*' flag in 'cpo' (':*' is same as ':@')
741func Test_cpo_star()
742  let save_cpo = &cpo
743  let x = 0
744  new
745  set cpo-=*
746  let @a = 'let x += 1'
747  call assert_fails('*a', 'E20:')
748  set cpo+=*
749  *a
750  call assert_equal(1, x)
751  close!
752  let &cpo = save_cpo
753endfunc
754
755" Test for the '<' flag in 'cpo' is in the test_mapping.vim file
756
757" Test for the '>' flag in 'cpo' (use a new line when appending to a register)
758func Test_cpo_gt()
759  let save_cpo = &cpo
760  new
761  call setline(1, 'one two')
762  set cpo-=>
763  let @r = ''
764  normal gg"Rye
765  normal "Rye
766  call assert_equal("oneone", @r)
767  set cpo+=>
768  let @r = ''
769  normal gg"Rye
770  normal "Rye
771  call assert_equal("\none\none", @r)
772  close!
773  let &cpo = save_cpo
774endfunc
775
776" Test for the ';' flag in 'cpo'
777" Test for t,f,F,T movement commands and 'cpo-;' setting
778func Test_cpo_semicolon()
779  let save_cpo = &cpo
780  new
781  call append(0, ["aaa two three four", "    zzz", "yyy   ",
782	      \ "bbb yee yoo four", "ccc two three four",
783	      \ "ddd yee yoo four"])
784  set cpo-=;
785  1
786  normal! 0tt;D
787  2
788  normal! 0fz;D
789  3
790  normal! $Fy;D
791  4
792  normal! $Ty;D
793  set cpo+=;
794  5
795  normal! 0tt;;D
796  6
797  normal! $Ty;;D
798
799  call assert_equal('aaa two', getline(1))
800  call assert_equal('    z', getline(2))
801  call assert_equal('y', getline(3))
802  call assert_equal('bbb y', getline(4))
803  call assert_equal('ccc', getline(5))
804  call assert_equal('ddd yee y', getline(6))
805  close!
806  let &cpo = save_cpo
807endfunc
808
809" Test for the '#' flag in 'cpo' (count before 'D', 'o' and 'O' operators)
810func Test_cpo_hash()
811  let save_cpo = &cpo
812  new
813  set cpo-=#
814  call setline(1, ['one', 'two', 'three'])
815  normal gg2D
816  call assert_equal(['three'], getline(1, '$'))
817  normal gg2ofour
818  call assert_equal(['three', 'four', 'four'], getline(1, '$'))
819  normal gg2Otwo
820  call assert_equal(['two', 'two', 'three', 'four', 'four'], getline(1, '$'))
821  %d
822  set cpo+=#
823  call setline(1, ['one', 'two', 'three'])
824  normal gg2D
825  call assert_equal(['', 'two', 'three'], getline(1, '$'))
826  normal gg2oone
827  call assert_equal(['', 'one', 'two', 'three'], getline(1, '$'))
828  normal gg2Ozero
829  call assert_equal(['zero', '', 'one', 'two', 'three'], getline(1, '$'))
830  close!
831  let &cpo = save_cpo
832endfunc
833
834" Test for the '&' flag in 'cpo'. The swap file is kept when a buffer is still
835" loaded and ':preserve' is used.
836func Test_cpo_ampersand()
837  call writefile(['one'], 'Xfile')
838  let after =<< trim [CODE]
839    set cpo+=&
840    preserve
841    qall
842  [CODE]
843  if RunVim([], after, 'Xfile')
844    call assert_equal(1, filereadable('.Xfile.swp'))
845    call delete('.Xfile.swp')
846  endif
847  call delete('Xfile')
848endfunc
849
850" Test for the '\' flag in 'cpo' (backslash in a [] range in a search pattern)
851func Test_cpo_backslash()
852  let save_cpo = &cpo
853  new
854  call setline(1, ['', " \\-string"])
855  set cpo-=\
856  exe 'normal gg/[ \-]' .. "\<CR>n"
857  call assert_equal(3, col('.'))
858  set cpo+=\
859  exe 'normal gg/[ \-]' .. "\<CR>n"
860  call assert_equal(2, col('.'))
861  close!
862  let &cpo = save_cpo
863endfunc
864
865" Test for the '/' flag in 'cpo' is in the test_substitute.vim file
866
867" Test for the '{' flag in 'cpo' (the "{" and "}" commands stop at a {
868" character at the start of a line)
869func Test_cpo_brace()
870  let save_cpo = &cpo
871  new
872  call setline(1, ['', '{', '    int i;', '}', ''])
873  set cpo-={
874  normal gg}
875  call assert_equal(5, line('.'))
876  normal G{
877  call assert_equal(1, line('.'))
878  set cpo+={
879  normal gg}
880  call assert_equal(2, line('.'))
881  normal G{
882  call assert_equal(2, line('.'))
883  close!
884  let &cpo = save_cpo
885endfunc
886
887" Test for the '.' flag in 'cpo' (:cd command fails if the current buffer is
888" modified)
889func Test_cpo_dot()
890  let save_cpo = &cpo
891  new Xfoo
892  call setline(1, 'foo')
893  let save_dir = getcwd()
894  set cpo+=.
895
896  " :cd should fail when buffer is modified and 'cpo' contains dot.
897  call assert_fails('cd ..', 'E747:')
898  call assert_equal(save_dir, getcwd())
899
900  " :cd with exclamation mark should succeed.
901  cd! ..
902  call assert_notequal(save_dir, getcwd())
903
904  " :cd should succeed when buffer has been written.
905  w!
906  exe 'cd ' .. fnameescape(save_dir)
907  call assert_equal(save_dir, getcwd())
908
909  call delete('Xfoo')
910  set cpo&
911  close!
912  let &cpo = save_cpo
913endfunc
914
915" vim: shiftwidth=2 sts=2 expandtab
916