Merge #11795 from janlazo/vim-8.2.0014

vim-patch:8.2.{14,16}
This commit is contained in:
Justin M. Keyes
2020-01-30 22:42:34 -08:00
committed by GitHub
2 changed files with 564 additions and 0 deletions

View File

@@ -192,3 +192,144 @@ func Test_optmatch_toolong()
set re=0
endfunc
" Test for regexp patterns with multi-byte support, using utf-8.
func Test_multibyte_chars()
" tl is a List of Lists with:
" 2: test auto/old/new 0: test auto/old 1: test auto/new
" regexp pattern
" text to test the pattern on
" expected match (optional)
" expected submatch 1 (optional)
" expected submatch 2 (optional)
" etc.
" When there is no match use only the first two items.
let tl = []
" Multi-byte character tests. These will fail unless vim is compiled
" with Multibyte (FEAT_MBYTE) or BIG/HUGE features.
call add(tl, [2, '[[:alpha:][=a=]]\+', '879 aiaãâaiuvna ', 'aiaãâaiuvna'])
call add(tl, [2, '[[=a=]]\+', 'ddaãâbcd', 'aãâ']) " equivalence classes
call add(tl, [2, '[^ม ]\+', 'มม oijasoifjos ifjoisj f osij j มมมมม abcd', 'oijasoifjos'])
call add(tl, [2, ' [^ ]\+', 'start มabcdม ', ' มabcdม'])
call add(tl, [2, '[ม[:alpha:][=a=]]\+', '879 aiaãมâมaiuvna ', 'aiaãมâมaiuvna'])
" this is not a normal "i" but 0xec
call add(tl, [2, '\p\+', 'ìa', 'ìa'])
call add(tl, [2, '\p*', 'aあ', 'aあ'])
" Test recognition of some character classes
call add(tl, [2, '\i\+', '&*¨xx ', 'xx'])
call add(tl, [2, '\f\+', '&*Ÿfname ', 'fname'])
" Test composing character matching
call add(tl, [2, '.ม', 'xม่x yมy', 'yม'])
call add(tl, [2, '.ม่', 'xม่x yมy', 'xม่'])
call add(tl, [2, "\u05b9", " x\u05b9 ", "x\u05b9"])
call add(tl, [2, ".\u05b9", " x\u05b9 ", "x\u05b9"])
call add(tl, [2, "\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
call add(tl, [2, ".\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
call add(tl, [2, "\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
call add(tl, [2, ".\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"])
call add(tl, [2, "\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
call add(tl, [2, ".\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"])
call add(tl, [2, "\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"])
call add(tl, [2, ".\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"])
call add(tl, [1, "\u05b9\u05bb", " y\u05b9 x\u05b9\u05bb ", "x\u05b9\u05bb"])
call add(tl, [2, ".\u05b9\u05bb", " y\u05bb x\u05b9\u05bb ", "x\u05b9\u05bb"])
call add(tl, [2, "a", "ca\u0300t"])
call add(tl, [2, "ca", "ca\u0300t"])
call add(tl, [2, "a\u0300", "ca\u0300t", "a\u0300"])
call add(tl, [2, 'a\%C', "ca\u0300t", "a\u0300"])
call add(tl, [2, 'ca\%C', "ca\u0300t", "ca\u0300"])
call add(tl, [2, 'ca\%Ct', "ca\u0300t", "ca\u0300t"])
" Test \Z
call add(tl, [2, 'ú\Z', 'x'])
call add(tl, [2, 'יהוה\Z', 'יהוה', 'יהוה'])
call add(tl, [2, 'יְהוָה\Z', 'יהוה', 'יהוה'])
call add(tl, [2, 'יהוה\Z', 'יְהוָה', 'יְהוָה'])
call add(tl, [2, 'יְהוָה\Z', 'יְהוָה', 'יְהוָה'])
call add(tl, [2, 'יְ\Z', 'וְיַ', 'יַ'])
call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200dxy", "ק\u200dx"])
call add(tl, [2, "ק\u200dx\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"])
call add(tl, [2, "ק\u200dx\\Z", "xק\u200dxy", "ק\u200dx"])
call add(tl, [2, "\u05b9\\Z", "xyz"])
call add(tl, [2, "\\Z\u05b9", "xyz"])
call add(tl, [2, "\u05b9\\Z", "xy\u05b9z", "y\u05b9"])
call add(tl, [2, "\\Z\u05b9", "xy\u05b9z", "y\u05b9"])
call add(tl, [1, "\u05b9\\+\\Z", "xy\u05b9z\u05b9 ", "y\u05b9z\u05b9"])
call add(tl, [1, "\\Z\u05b9\\+", "xy\u05b9z\u05b9 ", "y\u05b9z\u05b9"])
" Combining different tests and features
call add(tl, [2, '[^[=a=]]\+', 'ddaãâbcd', 'dd'])
" Run the tests
for t in tl
let re = t[0]
let pat = t[1]
let text = t[2]
let matchidx = 3
for engine in [0, 1, 2]
if engine == 2 && re == 0 || engine == 1 && re == 1
continue
endif
let &regexpengine = engine
try
let l = matchlist(text, pat)
catch
call assert_report('Error ' . engine . ': pat: \"' . pat .
\ '\", text: \"' . text .
\ '\", caused an exception: \"' . v:exception . '\"')
endtry
" check the match itself
if len(l) == 0 && len(t) > matchidx
call assert_report('Error ' . engine . ': pat: \"' . pat .
\ '\", text: \"' . text .
\ '\", did not match, expected: \"' . t[matchidx] . '\"')
elseif len(l) > 0 && len(t) == matchidx
call assert_report('Error ' . engine . ': pat: \"' . pat .
\ '\", text: \"' . text . '\", match: \"' . l[0] .
\ '\", expected no match')
elseif len(t) > matchidx && l[0] != t[matchidx]
call assert_report('Error ' . engine . ': pat: \"' . pat .
\ '\", text: \"' . text . '\", match: \"' . l[0] .
\ '\", expected: \"' . t[matchidx] . '\"')
else
" Test passed
endif
if len(l) > 0
" check all the nine submatches
for i in range(1, 9)
if len(t) <= matchidx + i
let e = ''
else
let e = t[matchidx + i]
endif
if l[i] != e
call assert_report('Error ' . engine . ': pat: \"' . pat .
\ '\", text: \"' . text . '\", submatch ' . i .
\ ': \"' . l[i] . '\", expected: \"' . e . '\"')
endif
endfor
unlet i
endif
endfor
endfor
set regexpengine&
endfunc
" check that 'ambiwidth' does not change the meaning of \p
func Test_ambiwidth()
set regexpengine=1 ambiwidth=single
call assert_equal(0, match("\u00EC", '\p'))
set regexpengine=1 ambiwidth=double
call assert_equal(0, match("\u00EC", '\p'))
set regexpengine=2 ambiwidth=single
call assert_equal(0, match("\u00EC", '\p'))
set regexpengine=2 ambiwidth=double
call assert_equal(0, match("\u00EC", '\p'))
set regexpengine& ambiwidth&
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -489,3 +489,426 @@ func Test_format_list_auto()
bwipe!
set fo& ai& bs&
endfunc
" Test for formatting multi-byte text with 'fo=t'
func Test_tw_2_fo_t()
new
let t =<< trim END
{
abc
}
END
call setline(1, t)
call cursor(2, 1)
set tw=2 fo=t
let t =<< trim END
abc
END
exe "normal gqgqjgqgq"
exe "normal o\n" . join(t, "\n")
let expected =<< trim END
{
abc
abc
}
END
call assert_equal(expected, getline(1, '$'))
set tw& fo&
bwipe!
endfunc
" Test for formatting multi-byte text with 'fo=tm' and 'tw=1'
func Test_tw_1_fo_tm()
new
let t =<< trim END
{
a
a
}
END
call setline(1, t)
call cursor(2, 1)
set tw=1 fo=tm
let t =<< trim END
a
a
END
exe "normal gqgqjgqgqjgqgqjgqgqjgqgq"
exe "normal o\n" . join(t, "\n")
let expected =<< trim END
{
a
a
a
a
}
END
call assert_equal(expected, getline(1, '$'))
set tw& fo&
bwipe!
endfunc
" Test for formatting multi-byte text with 'fo=tm' and 'tw=2'
func Test_tw_2_fo_tm()
new
let t =<< trim END
{
a
a
a
ab
abc
ab c
ab
}
END
call setline(1, t)
call cursor(2, 1)
set tw=2 fo=tm
let t =<< trim END
a
a
a
ab
abc
ab c
ab
END
exe "normal gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgq"
exe "normal o\n" . join(t, "\n")
let expected =<< trim END
{
a
a
a
ab
abc
ab
c
ab
a
a
a
ab
abc
ab
c
ab
}
END
call assert_equal(expected, getline(1, '$'))
set tw& fo&
bwipe!
endfunc
" Test for formatting multi-byte text with 'fo=tm', 'tw=2' and 'autoindent'.
func Test_tw_2_fo_tm_ai()
new
let t =<< trim END
{
a
}
END
call setline(1, t)
call cursor(2, 1)
set ai tw=2 fo=tm
let t =<< trim END
a
END
exe "normal gqgqjgqgq"
exe "normal o\n" . join(t, "\n")
let expected =<< trim END
{
a
a
}
END
call assert_equal(expected, getline(1, '$'))
set tw& fo& ai&
bwipe!
endfunc
" Test for formatting multi-byte text with 'fo=tm', 'tw=2' and 'noai'.
func Test_tw_2_fo_tm_noai()
new
let t =<< trim END
{
a
}
END
call setline(1, t)
call cursor(2, 1)
set noai tw=2 fo=tm
exe "normal gqgqjgqgqo\n \n a"
let expected =<< trim END
{
a
a
}
END
call assert_equal(expected, getline(1, '$'))
set tw& fo& ai&
bwipe!
endfunc
func Test_tw_2_fo_cqm_com()
new
let t =<< trim END
{
a
a
a
}
END
call setline(1, t)
call cursor(2, 1)
set tw=2 fo=cqm comments=n:
exe "normal gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgq"
let t =<< trim END
a
a
a
END
exe "normal o\n" . join(t, "\n")
let expected =<< trim END
{
a
a
a
a
a
a
}
END
call assert_equal(expected, getline(1, '$'))
set tw& fo& comments&
bwipe!
endfunc
func Test_tw_2_fo_tm_replace()
new
let t =<< trim END
{
}
END
call setline(1, t)
call cursor(2, 1)
set tw=2 fo=tm
exe "normal Ra"
let expected =<< trim END
{
a
}
END
call assert_equal(expected, getline(1, '$'))
set tw& fo&
bwipe!
endfunc
" Test for 'matchpairs' with multibyte chars
func Test_mps()
new
let t =<< trim END
{
two three four
}
END
call setline(1, t)
call cursor(2, 1)
exe "set mps+=\u2018:\u2019"
normal d%
let expected =<< trim END
{
four
}
END
call assert_equal(expected, getline(1, '$'))
set mps&
bwipe!
endfunc
" Test for ra on multi-byte characters
func Test_ra_multibyte()
new
let t =<< trim END
ra test
bb
b
END
call setline(1, t)
call cursor(1, 1)
normal jVjra
let expected =<< trim END
ra test
aaaa
aaa
END
call assert_equal(expected, getline(1, '$'))
bwipe!
endfunc
" Test for 'whichwrap' with multi-byte character
func Test_whichwrap_multi_byte()
new
let t =<< trim END
á
x
END
call setline(1, t)
call cursor(2, 1)
set whichwrap+=h
normal dh
set whichwrap&
let expected =<< trim END
áx
END
call assert_equal(expected, getline(1, '$'))
bwipe!
endfunc
func Test_substitute()
call assert_equal('aaaa', substitute('', '\zs', 'a', 'g'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab