Merge pull request #22291 from zeertzjq/vim-8.2.0148

vim-patch:8.2.0148
This commit is contained in:
zeertzjq 2023-02-17 09:35:34 +08:00 committed by GitHub
commit 477bbb5f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 140 additions and 102 deletions

View File

@ -1167,7 +1167,7 @@ static char *translate_mapping(char_u *str, int cpo_flags)
garray_T ga; garray_T ga;
ga_init(&ga, 1, 40); ga_init(&ga, 1, 40);
bool cpo_bslash = !(cpo_flags&FLAG_CPO_BSLASH); bool cpo_bslash = cpo_flags & FLAG_CPO_BSLASH;
for (; *str; str++) { for (; *str; str++) {
int c = *str; int c = *str;

View File

@ -26,9 +26,11 @@ if exists('s:did_load')
set viewoptions& set viewoptions&
set viewoptions+=options set viewoptions+=options
set switchbuf= set switchbuf=
" Make "Q" switch to Ex mode. if g:testname !~ 'test_mapping.vim$'
" This does not work for all tests. " Make "Q" switch to Ex mode.
nnoremap Q gQ " This does not work for all tests.
nnoremap Q gQ
endif
endif endif
" Common preparations for running tests. " Common preparations for running tests.

View File

@ -217,33 +217,33 @@ endfunc
" Test for the 'g' flag in 'cpo' (jump to line 1 when re-editing a file) " Test for the 'g' flag in 'cpo' (jump to line 1 when re-editing a file)
func Test_cpo_g() func Test_cpo_g()
throw 'Skipped: Nvim does not support cpoptions flag "g"'
let save_cpo = &cpo let save_cpo = &cpo
new test_cpoptions.vim new test_cpoptions.vim
set cpo-=g set cpo-=g
normal 20G normal 20G
edit edit
call assert_equal(20, line('.')) call assert_equal(20, line('.'))
set cpo+=g " Nvim: no "g" flag in 'cpoptions'.
edit " set cpo+=g
call assert_equal(1, line('.')) " edit
" call assert_equal(1, line('.'))
close! close!
let &cpo = save_cpo let &cpo = save_cpo
endfunc endfunc
" Test for inserting text in a line with only spaces ('H' flag in 'cpoptions') " Test for inserting text in a line with only spaces ('H' flag in 'cpoptions')
func Test_cpo_H() func Test_cpo_H()
throw 'Skipped: Nvim does not support cpoptions flag "H"'
let save_cpo = &cpo let save_cpo = &cpo
new new
set cpo-=H set cpo-=H
call setline(1, ' ') call setline(1, ' ')
normal! Ia normal! Ia
call assert_equal(' a', getline(1)) call assert_equal(' a', getline(1))
set cpo+=H " Nvim: no "H" flag in 'cpoptions'.
call setline(1, ' ') " set cpo+=H
normal! Ia " call setline(1, ' ')
call assert_equal(' a ', getline(1)) " normal! Ia
" call assert_equal(' a ', getline(1))
close! close!
let &cpo = save_cpo let &cpo = save_cpo
endfunc endfunc
@ -560,15 +560,15 @@ endfunc
" Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one " Test for the 'w' flag in 'cpo' ('cw' on a blank character changes only one
" character) " character)
func Test_cpo_w() func Test_cpo_w()
throw 'Skipped: Nvim does not support cpoptions flag "w"'
let save_cpo = &cpo let save_cpo = &cpo
new new
set cpo+=w " Nvim: no "w" flag in 'cpoptions'.
call setline(1, 'here are some words') " set cpo+=w
norm! 1gg0elcwZZZ " call setline(1, 'here are some words')
call assert_equal('hereZZZ are some words', getline('.')) " norm! 1gg0elcwZZZ
norm! 1gg2elcWYYY " call assert_equal('hereZZZ are some words', getline('.'))
call assert_equal('hereZZZ areYYY some words', getline('.')) " norm! 1gg2elcWYYY
" call assert_equal('hereZZZ areYYY some words', getline('.'))
set cpo-=w set cpo-=w
call setline(1, 'here are some words') call setline(1, 'here are some words')
norm! 1gg0elcwZZZ norm! 1gg0elcwZZZ
@ -745,16 +745,16 @@ endfunc
" Test for the '*' flag in 'cpo' (':*' is same as ':@') " Test for the '*' flag in 'cpo' (':*' is same as ':@')
func Test_cpo_star() func Test_cpo_star()
throw 'Skipped: Nvim does not support cpoptions flag "*"'
let save_cpo = &cpo let save_cpo = &cpo
let x = 0 let x = 0
new new
set cpo-=* set cpo-=*
let @a = 'let x += 1' let @a = 'let x += 1'
call assert_fails('*a', 'E20:') call assert_fails('*a', 'E20:')
set cpo+=* " Nvim: no "*" flag in 'cpoptions'.
*a " set cpo+=*
call assert_equal(1, x) " *a
" call assert_equal(1, x)
close! close!
let &cpo = save_cpo let &cpo = save_cpo
endfunc endfunc
@ -815,7 +815,6 @@ endfunc
" Test for the '#' flag in 'cpo' (count before 'D', 'o' and 'O' operators) " Test for the '#' flag in 'cpo' (count before 'D', 'o' and 'O' operators)
func Test_cpo_hash() func Test_cpo_hash()
throw 'Skipped: Nvim does not support cpoptions flag "#"'
let save_cpo = &cpo let save_cpo = &cpo
new new
set cpo-=# set cpo-=#
@ -827,14 +826,15 @@ func Test_cpo_hash()
normal gg2Otwo normal gg2Otwo
call assert_equal(['two', 'two', 'three', 'four', 'four'], getline(1, '$')) call assert_equal(['two', 'two', 'three', 'four', 'four'], getline(1, '$'))
%d %d
set cpo+=# " Nvim: no "#" flag in 'cpoptions'.
call setline(1, ['one', 'two', 'three']) " set cpo+=#
normal gg2D " call setline(1, ['one', 'two', 'three'])
call assert_equal(['', 'two', 'three'], getline(1, '$')) " normal gg2D
normal gg2oone " call assert_equal(['', 'two', 'three'], getline(1, '$'))
call assert_equal(['', 'one', 'two', 'three'], getline(1, '$')) " normal gg2oone
normal gg2Ozero " call assert_equal(['', 'one', 'two', 'three'], getline(1, '$'))
call assert_equal(['zero', '', 'one', 'two', 'three'], getline(1, '$')) " normal gg2Ozero
" call assert_equal(['zero', '', 'one', 'two', 'three'], getline(1, '$'))
close! close!
let &cpo = save_cpo let &cpo = save_cpo
endfunc endfunc
@ -858,16 +858,16 @@ endfunc
" Test for the '\' flag in 'cpo' (backslash in a [] range in a search pattern) " Test for the '\' flag in 'cpo' (backslash in a [] range in a search pattern)
func Test_cpo_backslash() func Test_cpo_backslash()
throw 'Skipped: Nvim does not support cpoptions flag "\"'
let save_cpo = &cpo let save_cpo = &cpo
new new
call setline(1, ['', " \\-string"]) call setline(1, ['', " \\-string"])
set cpo-=\ set cpo-=\
exe 'normal gg/[ \-]' .. "\<CR>n" exe 'normal gg/[ \-]' .. "\<CR>n"
call assert_equal(3, col('.')) call assert_equal(3, col('.'))
set cpo+=\ " Nvim: no "\" flag in 'cpoptions'.
exe 'normal gg/[ \-]' .. "\<CR>n" " set cpo+=\
call assert_equal(2, col('.')) " exe 'normal gg/[ \-]' .. "\<CR>n"
" call assert_equal(2, col('.'))
close! close!
let &cpo = save_cpo let &cpo = save_cpo
endfunc endfunc
@ -877,7 +877,6 @@ endfunc
" Test for the '{' flag in 'cpo' (the "{" and "}" commands stop at a { " Test for the '{' flag in 'cpo' (the "{" and "}" commands stop at a {
" character at the start of a line) " character at the start of a line)
func Test_cpo_brace() func Test_cpo_brace()
throw 'Skipped: Nvim does not support cpoptions flag "{"'
let save_cpo = &cpo let save_cpo = &cpo
new new
call setline(1, ['', '{', ' int i;', '}', '']) call setline(1, ['', '{', ' int i;', '}', ''])
@ -886,11 +885,12 @@ func Test_cpo_brace()
call assert_equal(5, line('.')) call assert_equal(5, line('.'))
normal G{ normal G{
call assert_equal(1, line('.')) call assert_equal(1, line('.'))
set cpo+={ " Nvim: no "{" flag in 'cpoptions'.
normal gg} " set cpo+={
call assert_equal(2, line('.')) " normal gg}
normal G{ " call assert_equal(2, line('.'))
call assert_equal(2, line('.')) " normal G{
" call assert_equal(2, line('.'))
close! close!
let &cpo = save_cpo let &cpo = save_cpo
endfunc endfunc

View File

@ -934,6 +934,39 @@ func Test_abbr_remove()
call assert_equal({}, maparg('foo', 'i', 1, 1)) call assert_equal({}, maparg('foo', 'i', 1, 1))
endfunc endfunc
" Trigger an abbreviation using a special key
func Test_abbr_trigger_special()
new
iabbr teh the
call feedkeys("iteh\<F2>\<Esc>", 'xt')
call assert_equal('the<F2>', getline(1))
iunab teh
close!
endfunc
" Test for '<' in 'cpoptions'
func Test_map_cpo_special_keycode()
set cpo-=<
imap x<Bslash>k Test
let d = maparg('x<Bslash>k', 'i', 0, 1)
call assert_equal(['x\k', 'Test', 'i'], [d.lhs, d.rhs, d.mode])
call feedkeys(":imap x\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"imap x\k', @:)
iunmap x<Bslash>k
" Nvim: no "<" flag in 'cpoptions'.
" set cpo+=<
" imap x<Bslash>k Test
" let d = maparg('x<Bslash>k', 'i', 0, 1)
" call assert_equal(['x<Bslash>k', 'Test', 'i'], [d.lhs, d.rhs, d.mode])
" call feedkeys(":imap x\<C-A>\<C-B>\"\<CR>", 'tx')
" call assert_equal('"imap x<Bslash>k', @:)
" iunmap x<Bslash>k
set cpo-=<
" Modifying 'cpo' above adds some default mappings, remove them
mapclear
mapclear!
endfunc
func Test_map_cmdkey_redo() func Test_map_cmdkey_redo()
func SelectDash() func SelectDash()
call search('^---\n\zs', 'bcW') call search('^---\n\zs', 'bcW')

View File

@ -2254,61 +2254,63 @@ func Test_normal29_brace()
" set cpo+={ " set cpo+={
" 1 " 1
" norm! 0d2} " norm! 0d2}
" let expected =<< trim [DATA]
" { let expected =<< trim [DATA]
" This is no paragraph {
" unless the '{' is set This is no paragraph
" in 'cpoptions' unless the '{' is set
" } in 'cpoptions'
" .IP }
" The nroff macros IP separates a paragraph .IP
" That means, it must be a '.' The nroff macros IP separates a paragraph
" followed by IP That means, it must be a '.'
" .LPIt does not matter, if afterwards some followed by IP
" more characters follow. .LPIt does not matter, if afterwards some
" .SHAlso section boundaries from the nroff more characters follow.
" macros terminate a paragraph. That means .SHAlso section boundaries from the nroff
" a character like this: macros terminate a paragraph. That means
" .NH a character like this:
" End of text here .NH
" End of text here
" [DATA]
[DATA]
" call assert_equal(expected, getline(1, '$')) " call assert_equal(expected, getline(1, '$'))
"
" $ " $
" norm! d} " norm! d}
" let expected =<< trim [DATA]
" { let expected =<< trim [DATA]
" This is no paragraph {
" unless the '{' is set This is no paragraph
" in 'cpoptions' unless the '{' is set
" } in 'cpoptions'
" .IP }
" The nroff macros IP separates a paragraph .IP
" That means, it must be a '.' The nroff macros IP separates a paragraph
" followed by IP That means, it must be a '.'
" .LPIt does not matter, if afterwards some followed by IP
" more characters follow. .LPIt does not matter, if afterwards some
" .SHAlso section boundaries from the nroff more characters follow.
" macros terminate a paragraph. That means .SHAlso section boundaries from the nroff
" a character like this: macros terminate a paragraph. That means
" .NH a character like this:
" End of text here .NH
" End of text here
" [DATA]
[DATA]
" call assert_equal(expected, getline(1, '$')) " call assert_equal(expected, getline(1, '$'))
"
" norm! gg} " norm! gg}
" norm! d5} " norm! d5}
"
" let expected =<< trim [DATA]
" {
" This is no paragraph
" unless the '{' is set
" in 'cpoptions'
" }
" [DATA] let expected =<< trim [DATA]
{
This is no paragraph
unless the '{' is set
in 'cpoptions'
}
[DATA]
" call assert_equal(expected, getline(1, '$')) " call assert_equal(expected, getline(1, '$'))
" Jumping to a fold should open the fold " Jumping to a fold should open the fold

View File

@ -296,15 +296,15 @@ endfunc
" Test for *:s%* on :substitute. " Test for *:s%* on :substitute.
func Test_sub_cmd_6() func Test_sub_cmd_6()
throw 'Skipped: Nvim does not support cpoptions flag "/"'
set magic& set magic&
set cpo+=/ " Nvim: no "/" flag in 'cpoptions'.
" set cpo+=/
" List entry format: [input, cmd, output] " List entry format: [input, cmd, output]
let tests = [ ['A', 's/A/a/', ['a']], let tests = [ ['A', 's/A/a/', ['a']],
\ ['B', 's/B/%/', ['a']], \ ['B', 's/B/%/', ['a']],
\ ] \ ]
call Run_SubCmd_Tests(tests) " call Run_SubCmd_Tests(tests)
set cpo-=/ set cpo-=/
let tests = [ ['C', 's/C/c/', ['c']], let tests = [ ['C', 's/C/c/', ['c']],
@ -585,10 +585,11 @@ endfunc
func Test_sub_replace_6() func Test_sub_replace_6()
set magic& set magic&
" Nvim: no "/" flag in 'cpoptions'.
" set cpo+=/ " set cpo+=/
call assert_equal('a', substitute('A', 'A', 'a', '')) call assert_equal('a', substitute('A', 'A', 'a', ''))
call assert_equal('%', substitute('B', 'B', '%', '')) call assert_equal('%', substitute('B', 'B', '%', ''))
" set cpo-=/ set cpo-=/
call assert_equal('c', substitute('C', 'C', 'c', '')) call assert_equal('c', substitute('C', 'C', 'c', ''))
call assert_equal('%', substitute('D', 'D', '%', '')) call assert_equal('%', substitute('D', 'D', '%', ''))
endfunc endfunc
@ -853,13 +854,13 @@ func Test_sub_with_no_last_pat()
call assert_equal([], readfile('Xresult')) call assert_equal([], readfile('Xresult'))
endif endif
" Nvim does not support cpoptions flag "/"' let lines =<< trim [SCRIPT]
" let lines =<< trim [SCRIPT] set cpo+=/
" set cpo+=/ call assert_fails('s/abc/%/', 'E33:')
" call assert_fails('s/abc/%/', 'E33:') call writefile(v:errors, 'Xresult')
" call writefile(v:errors, 'Xresult') qall!
" qall! [SCRIPT]
" [SCRIPT] " Nvim: no "/" flag in 'cpoptions'.
" call writefile(lines, 'Xscript') " call writefile(lines, 'Xscript')
" if RunVim([], [], '--clean -S Xscript') " if RunVim([], [], '--clean -S Xscript')
" call assert_equal([], readfile('Xresult')) " call assert_equal([], readfile('Xresult'))