Mercurial > vim
changeset 20848:d3fa0d29fa9a v8.2.0976
patch 8.2.0976: some 'cpoptions' not tested
Commit: https://github.com/vim/vim/commit/df7df59d85e7e56a796912dc865488a75d3f0e53
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 14 13:50:55 2020 +0200
patch 8.2.0976: some 'cpoptions' not tested
Problem: Some 'cpoptions' not tested.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/6253)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 14 Jun 2020 14:00:03 +0200 |
parents | 4e1017c5fbb5 |
children | a13abf01e8cd |
files | src/testdir/test_cd.vim src/testdir/test_charsearch.vim src/testdir/test_cpoptions.vim src/testdir/test_normal.vim src/version.c |
diffstat | 5 files changed, 301 insertions(+), 81 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/test_cd.vim +++ b/src/testdir/test_cd.vim @@ -58,30 +58,6 @@ func Test_cd_minus() call delete('Xresult') endfunc -func Test_cd_with_cpo_chdir() - e Xfoo - call setline(1, 'foo') - let path = getcwd() - set cpo+=. - - " :cd should fail when buffer is modified and 'cpo' contains dot. - call assert_fails('cd ..', 'E747:') - call assert_equal(path, getcwd()) - - " :cd with exclamation mark should succeed. - cd! .. - call assert_notequal(path, getcwd()) - - " :cd should succeed when buffer has been written. - w! - exe 'cd ' .. fnameescape(path) - call assert_equal(path, getcwd()) - - call delete('Xfoo') - set cpo& - bw! -endfunc - " Test for chdir() func Test_chdir_func() let topdir = getcwd()
--- a/src/testdir/test_charsearch.vim +++ b/src/testdir/test_charsearch.vim @@ -43,36 +43,6 @@ func Test_charsearch() enew! endfunc -" Test for t,f,F,T movement commands and 'cpo-;' setting -func Test_search_cmds() - enew! - call append(0, ["aaa two three four", " zzz", "yyy ", - \ "bbb yee yoo four", "ccc two three four", - \ "ddd yee yoo four"]) - set cpo-=; - 1 - normal! 0tt;D - 2 - normal! 0fz;D - 3 - normal! $Fy;D - 4 - normal! $Ty;D - set cpo+=; - 5 - normal! 0tt;;D - 6 - normal! $Ty;;D - - call assert_equal('aaa two', getline(1)) - call assert_equal(' z', getline(2)) - call assert_equal('y', getline(3)) - call assert_equal('bbb y', getline(4)) - call assert_equal('ccc', getline(5)) - call assert_equal('ddd yee y', getline(6)) - enew! -endfunc - " Test for character search in virtual edit mode with <Tab> func Test_csearch_virtualedit() new
--- a/src/testdir/test_cpoptions.vim +++ b/src/testdir/test_cpoptions.vim @@ -1,6 +1,7 @@ -" Test for various 'cpoptions' (cpo) flags +" Test for the various 'cpoptions' (cpo) flags source check.vim +source shared.vim source view_util.vim " Test for the 'a' flag in 'cpo'. Reading a file should set the alternate @@ -62,6 +63,24 @@ func Test_cpo_b() nunmap <F5> endfunc +" Test for the 'B' flag in 'cpo'. A backslash in mappings, abbreviations, user +" commands and menu commands has no special meaning. +func Test_cpo_B() + let save_cpo = &cpo + new + set cpo-=B + iabbr <buffer> abc ab\<BS>d + exe "normal iabc " + call assert_equal('ab<BS>d ', getline(1)) + %d + set cpo+=B + iabbr <buffer> abc ab\<BS>d + exe "normal iabc " + call assert_equal('abd ', getline(1)) + close! + let &cpo = save_cpo +endfunc + " Test for the 'c' flag in 'cpo'. func Test_cpo_c() let save_cpo = &cpo @@ -226,6 +245,8 @@ func Test_cpo_H() let &cpo = save_cpo endfunc +" TODO: Add a test for the 'i' flag in 'cpo' + " Test for the 'I' flag in 'cpo' (deleting autoindent when using arrow keys) func Test_cpo_I() let save_cpo = &cpo @@ -242,6 +263,8 @@ func Test_cpo_I() let &cpo = save_cpo endfunc +" Test for the 'j' flag in 'cpo' is in the test_join.vim file. + " Test for the 'J' flag in 'cpo' (two spaces after a sentence) func Test_cpo_J() let save_cpo = &cpo @@ -271,9 +294,9 @@ func Test_cpo_J() let &cpo = save_cpo endfunc -" TODO: Add a test for 'k' in 'cpo' +" TODO: Add a test for the 'k' flag in 'cpo' -" TODO: Add a test for 'K' in 'cpo' +" TODO: Add a test for the 'K' flag in 'cpo' " Test for the 'l' flag in 'cpo' (backslash in a [] range) func Test_cpo_l() @@ -311,7 +334,7 @@ func Test_cpo_L() let &cpo = save_cpo endfunc -" TODO: This test doesn't work. +" TODO: Add a test for the 'm' flag in 'cpo' " Test for the 'M' flag in 'cpo' (% with escape parenthesis) func Test_cpo_M() @@ -396,6 +419,8 @@ func Test_cpo_O() let &cpo = save_cpo endfunc +" Test for the 'p' flag in 'cpo' is in the test_lispwords.vim file. + " Test for the 'P' flag in 'cpo' (appending to a file sets the current file " name) func Test_cpo_P() @@ -473,6 +498,8 @@ func Test_cpo_R() let &cpo = save_cpo endfunc +" TODO: Add a test for the 's' flag in 'cpo' + " Test for the 'S' flag in 'cpo' (copying buffer options) func Test_cpo_S() let save_cpo = &cpo @@ -497,6 +524,8 @@ func Test_cpo_S() let &cpo = save_cpo endfunc +" Test for the 't' flag in 'cpo' is in the test_tagjump.vim file. + " Test for the 'u' flag in 'cpo' (Vi-compatible undo) func Test_cpo_u() let save_cpo = &cpo @@ -514,6 +543,32 @@ func Test_cpo_u() let &cpo = save_cpo endfunc +" TODO: Add a test for the 'v' flag in 'cpo' (backspace doesn't remove +" characters from the screen) + +" Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one +" character) +func Test_cpo_w() + let save_cpo = &cpo + new + set cpo+=w + call setline(1, 'here are some words') + norm! 1gg0elcwZZZ + call assert_equal('hereZZZ are some words', getline('.')) + norm! 1gg2elcWYYY + call assert_equal('hereZZZ areYYY some words', getline('.')) + set cpo-=w + call setline(1, 'here are some words') + norm! 1gg0elcwZZZ + call assert_equal('hereZZZare some words', getline('.')) + norm! 1gg2elcWYYY + call assert_equal('hereZZZare someYYYwords', getline('.')) + close! + let &cpo = save_cpo +endfunc + +" Test for the 'W' flag in 'cpo' is in the test_writefile.vim file + " Test for the 'x' flag in 'cpo' (Esc on command-line executes command) func Test_cpo_x() let save_cpo = &cpo @@ -586,21 +641,7 @@ func Test_cpo_Z() let &cpo = save_cpo endfunc -" Test for cursor movement with '-' in 'cpoptions' -func Test_cpo_minus() - new - call setline(1, ['foo', 'bar', 'baz']) - let save_cpo = &cpo - set cpo+=- - call assert_beeps('normal 10j') - call assert_equal(1, line('.')) - normal G - call assert_beeps('normal 10k') - call assert_equal(3, line('.')) - call assert_fails(10, 'E16:') - let &cpo = save_cpo - close! -endfunc +" Test for the '!' flag in 'cpo' is in the test_normal.vim file " Test for displaying dollar when changing text ('$' flag in 'cpoptions') func Test_cpo_dollar() @@ -624,4 +665,243 @@ func Test_cpo_dollar() %bw! endfunc +" Test for the '%' flag in 'cpo' (parenthesis matching inside strings) +func Test_cpo_percent() + let save_cpo = &cpo + new + call setline(1, ' if (strcmp("ab)cd(", s))') + set cpo-=% + normal 8|% + call assert_equal(28, col('.')) + normal 15|% + call assert_equal(27, col('.')) + normal 27|% + call assert_equal(15, col('.')) + call assert_beeps("normal 19|%") + call assert_beeps("normal 22|%") + set cpo+=% + normal 8|% + call assert_equal(28, col('.')) + normal 15|% + call assert_equal(19, col('.')) + normal 27|% + call assert_equal(22, col('.')) + normal 19|% + call assert_equal(15, col('.')) + normal 22|% + call assert_equal(27, col('.')) + close! + let &cpo = save_cpo +endfunc + +" Test for cursor movement with '-' in 'cpoptions' +func Test_cpo_minus() + new + call setline(1, ['foo', 'bar', 'baz']) + let save_cpo = &cpo + set cpo+=- + call assert_beeps('normal 10j') + call assert_equal(1, line('.')) + normal G + call assert_beeps('normal 10k') + call assert_equal(3, line('.')) + call assert_fails(10, 'E16:') + close! + let &cpo = save_cpo +endfunc + +" Test for the '+' flag in 'cpo' ('write file' command resets the 'modified' +" flag) +func Test_cpo_plus() + let save_cpo = &cpo + call writefile([], 'Xfile') + new Xfile + call setline(1, 'foo') + write X1 + call assert_equal(1, &modified) + set cpo+=+ + write X2 + call assert_equal(0, &modified) + close! + call delete('Xfile') + call delete('X1') + call delete('X2') + let &cpo = save_cpo +endfunc + +" Test for the '*' flag in 'cpo' (':*' is same as ':@') +func Test_cpo_star() + let save_cpo = &cpo + let x = 0 + new + set cpo-=* + let @a = 'let x += 1' + call assert_fails('*a', 'E20:') + set cpo+=* + *a + call assert_equal(1, x) + close! + let &cpo = save_cpo +endfunc + +" Test for the '<' flag in 'cpo' is in the test_mapping.vim file + +" Test for the '>' flag in 'cpo' (use a new line when appending to a register) +func Test_cpo_gt() + let save_cpo = &cpo + new + call setline(1, 'one two') + set cpo-=> + let @r = '' + normal gg"Rye + normal "Rye + call assert_equal("oneone", @r) + set cpo+=> + let @r = '' + normal gg"Rye + normal "Rye + call assert_equal("\none\none", @r) + close! + let &cpo = save_cpo +endfunc + +" Test for the ';' flag in 'cpo' +" Test for t,f,F,T movement commands and 'cpo-;' setting +func Test_cpo_semicolon() + let save_cpo = &cpo + new + call append(0, ["aaa two three four", " zzz", "yyy ", + \ "bbb yee yoo four", "ccc two three four", + \ "ddd yee yoo four"]) + set cpo-=; + 1 + normal! 0tt;D + 2 + normal! 0fz;D + 3 + normal! $Fy;D + 4 + normal! $Ty;D + set cpo+=; + 5 + normal! 0tt;;D + 6 + normal! $Ty;;D + + call assert_equal('aaa two', getline(1)) + call assert_equal(' z', getline(2)) + call assert_equal('y', getline(3)) + call assert_equal('bbb y', getline(4)) + call assert_equal('ccc', getline(5)) + call assert_equal('ddd yee y', getline(6)) + close! + let &cpo = save_cpo +endfunc + +" Test for the '#' flag in 'cpo' (count before 'D', 'o' and 'O' operators) +func Test_cpo_hash() + let save_cpo = &cpo + new + set cpo-=# + call setline(1, ['one', 'two', 'three']) + normal gg2D + call assert_equal(['three'], getline(1, '$')) + normal gg2ofour + call assert_equal(['three', 'four', 'four'], getline(1, '$')) + normal gg2Otwo + call assert_equal(['two', 'two', 'three', 'four', 'four'], getline(1, '$')) + %d + set cpo+=# + call setline(1, ['one', 'two', 'three']) + normal gg2D + call assert_equal(['', 'two', 'three'], getline(1, '$')) + normal gg2oone + call assert_equal(['', 'one', 'two', 'three'], getline(1, '$')) + normal gg2Ozero + call assert_equal(['zero', '', 'one', 'two', 'three'], getline(1, '$')) + close! + let &cpo = save_cpo +endfunc + +" Test for the '&' flag in 'cpo'. The swap file is kept when a buffer is still +" loaded and ':preserve' is used. +func Test_cpo_ampersand() + call writefile(['one'], 'Xfile') + let after =<< trim [CODE] + set cpo+=& + preserve + qall + [CODE] + if RunVim([], after, 'Xfile') + call assert_equal(1, filereadable('.Xfile.swp')) + call delete('.Xfile.swp') + endif + call delete('Xfile') +endfunc + +" Test for the '\' flag in 'cpo' (backslash in a [] range in a search pattern) +func Test_cpo_backslash() + let save_cpo = &cpo + new + call setline(1, ['', " \\-string"]) + set cpo-=\ + exe 'normal gg/[ \-]' .. "\<CR>n" + call assert_equal(3, col('.')) + set cpo+=\ + exe 'normal gg/[ \-]' .. "\<CR>n" + call assert_equal(2, col('.')) + close! + let &cpo = save_cpo +endfunc + +" Test for the '/' flag in 'cpo' is in the test_substitute.vim file + +" Test for the '{' flag in 'cpo' (the "{" and "}" commands stop at a { +" character at the start of a line) +func Test_cpo_brace() + let save_cpo = &cpo + new + call setline(1, ['', '{', ' int i;', '}', '']) + set cpo-={ + normal gg} + call assert_equal(5, line('.')) + normal G{ + call assert_equal(1, line('.')) + set cpo+={ + normal gg} + call assert_equal(2, line('.')) + normal G{ + call assert_equal(2, line('.')) + close! + let &cpo = save_cpo +endfunc + +" Test for the '.' flag in 'cpo' (:cd command fails if the current buffer is +" modified) +func Test_cpo_dot() + let save_cpo = &cpo + new Xfoo + call setline(1, 'foo') + let save_dir = getcwd() + set cpo+=. + + " :cd should fail when buffer is modified and 'cpo' contains dot. + call assert_fails('cd ..', 'E747:') + call assert_equal(save_dir, getcwd()) + + " :cd with exclamation mark should succeed. + cd! .. + call assert_notequal(save_dir, getcwd()) + + " :cd should succeed when buffer has been written. + w! + exe 'cd ' .. fnameescape(save_dir) + call assert_equal(save_dir, getcwd()) + + call delete('Xfoo') + set cpo& + close! + let &cpo = save_cpo +endfunc + " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_normal.vim +++ b/src/testdir/test_normal.vim @@ -2242,7 +2242,6 @@ endfunc " Test for cw cW ce func Test_normal39_cw() " Test for cw and cW on whitespace - " and cpo+=w setting new set tw=0 call append(0, 'here are some words') @@ -2250,13 +2249,6 @@ func Test_normal39_cw() call assert_equal('hereZZZare some words', getline('.')) norm! 1gg0elcWYYY call assert_equal('hereZZZareYYYsome words', getline('.')) - set cpo+=w - call setline(1, 'here are some words') - norm! 1gg0elcwZZZ - call assert_equal('hereZZZ are some words', getline('.')) - norm! 1gg2elcWYYY - call assert_equal('hereZZZ areYYY some words', getline('.')) - set cpo-=w norm! 2gg0cwfoo call assert_equal('foo', getline('.'))