diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-08-17 13:38:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-17 13:38:41 +0800 |
commit | 7f51829cf75e0d3ca546cab0e70a4c089eac40ec (patch) | |
tree | f907b7af2bbe5ec6bb19823d0a182f974062a406 /test | |
parent | 8861f2af72481b1759a6935afa6dce2aae512359 (diff) | |
parent | acac1e19d364c90ded6ded8c874f886d9ebbc393 (diff) | |
download | rneovim-7f51829cf75e0d3ca546cab0e70a4c089eac40ec.tar.gz rneovim-7f51829cf75e0d3ca546cab0e70a4c089eac40ec.tar.bz2 rneovim-7f51829cf75e0d3ca546cab0e70a4c089eac40ec.zip |
Merge pull request #24748 from zeertzjq/vim-8.2.3818
vim-patch:8.2.{3818,3822,3908,3982}: filter()/map() on a string
Diffstat (limited to 'test')
-rw-r--r-- | test/old/testdir/test_blob.vim | 14 | ||||
-rw-r--r-- | test/old/testdir/test_expr.vim | 1 | ||||
-rw-r--r-- | test/old/testdir/test_filter_map.vim | 90 | ||||
-rw-r--r-- | test/old/testdir/test_highlight.vim | 3 | ||||
-rw-r--r-- | test/old/testdir/test_listdict.vim | 1 | ||||
-rw-r--r-- | test/old/testdir/test_search.vim | 2 |
6 files changed, 109 insertions, 2 deletions
diff --git a/test/old/testdir/test_blob.vim b/test/old/testdir/test_blob.vim index 920ceb826d..2dae19bcfb 100644 --- a/test/old/testdir/test_blob.vim +++ b/test/old/testdir/test_blob.vim @@ -38,6 +38,7 @@ func Test_blob_create() call assert_fails('VAR b = 0z001122.') call assert_fails('call get("", 1)', 'E896:') call assert_equal(0, len(v:_null_blob)) + call assert_equal(0z, copy(v:_null_blob)) END call CheckLegacyAndVim9Success(lines) endfunc @@ -370,6 +371,14 @@ func Test_blob_add() add(v:_null_blob, 0x22) END call CheckDefExecAndScriptFailure(lines, 'E1131:') + + let lines =<< trim END + let b = 0zDEADBEEF + lockvar b + call add(b, 0) + unlockvar b + END + call CheckScriptFailure(lines, 'E741:') endfunc func Test_blob_empty() @@ -464,6 +473,9 @@ func Test_blob_func_remove() remove(b, 0) END call CheckScriptFailure(lines, 'E741:') + + call assert_fails('echo remove(0z1020, [])', 'E745:') + call assert_fails('echo remove(0z1020, 0, [])', 'E745:') endfunc func Test_blob_read_write() @@ -524,6 +536,7 @@ func Test_blob_filter() call assert_equal(0zADEF, filter(0zDEADBEEF, 'v:key % 2')) END call CheckLegacyAndVim9Success(lines) + call assert_fails('echo filter(0z10, "a10")', 'E121:') endfunc " map() item in blob @@ -539,6 +552,7 @@ func Test_blob_map() call map(0z00, '[9]') END call CheckLegacyAndVim9Failure(lines, 'E978:') + call assert_fails('echo map(0z10, "a10")', 'E121:') endfunc func Test_blob_index() diff --git a/test/old/testdir/test_expr.vim b/test/old/testdir/test_expr.vim index bf1ba240eb..d316e63818 100644 --- a/test/old/testdir/test_expr.vim +++ b/test/old/testdir/test_expr.vim @@ -421,6 +421,7 @@ func Test_printf_misc() call assert_equal('[00000あiう]', printf('[%010.7S]', 'あiう')) call assert_equal('1%', printf('%d%%', 1)) + call assert_notequal('', printf('%p', "abc")) END call CheckLegacyAndVim9Success(lines) diff --git a/test/old/testdir/test_filter_map.vim b/test/old/testdir/test_filter_map.vim index b11ab93143..3040b7b0d0 100644 --- a/test/old/testdir/test_filter_map.vim +++ b/test/old/testdir/test_filter_map.vim @@ -1,5 +1,7 @@ " Test filter() and map() +source vim9.vim + " list with expression string func Test_filter_map_list_expr_string() " filter() @@ -84,8 +86,6 @@ endfunc func Test_map_filter_fails() call assert_fails('call map([1], "42 +")', 'E15:') call assert_fails('call filter([1], "42 +")', 'E15:') - call assert_fails("let l = map('abc', '\"> \" . v:val')", 'E896:') - call assert_fails("let l = filter('abc', '\"> \" . v:val')", 'E896:') call assert_fails("let l = filter([1, 2, 3], '{}')", 'E728:') call assert_fails("let l = filter({'k' : 10}, '{}')", 'E728:') call assert_fails("let l = filter([1, 2], {})", 'E731:') @@ -138,4 +138,90 @@ func Test_mapnew_blob() call assert_equal(0z129956, bout) endfunc +" Test for using map(), filter() and mapnew() with a string +func Test_filter_map_string() + " filter() + let lines =<< trim END + VAR s = "abc" + call filter(s, '"b" != v:val') + call assert_equal('abc', s) + call assert_equal('ac', filter('abc', '"b" != v:val')) + call assert_equal('あいうえお', filter('あxいxうxえxお', '"x" != v:val')) + call assert_equal('あa😊💕💕b💕', filter('あxax😊x💕💕b💕x', '"x" != v:val')) + call assert_equal('xxxx', filter('あxax😊x💕💕b💕x', '"x" == v:val')) + VAR t = "%),:;>?]}’”†‡…‰,‱‼⁇⁈⁉℃℉,、。〉》」,』】〕〗〙〛,!),.:,;?,]}" + VAR u = "%):;>?]}’”†‡…‰‱‼⁇⁈⁉℃℉、。〉》」』】〕〗〙〛!),.:;?]}" + call assert_equal(u, filter(t, '"," != v:val')) + call assert_equal('', filter('abc', '0')) + call assert_equal('ac', filter('abc', LSTART i, x LMIDDLE "b" != x LEND)) + call assert_equal('あいうえお', filter('あxいxうxえxお', LSTART i, x LMIDDLE "x" != x LEND)) + call assert_equal('', filter('abc', LSTART i, x LMIDDLE v:false LEND)) + call assert_equal('', filter('', "v:val == 'a'")) + call assert_equal('', filter(v:_null_string, "v:val == 'a'")) + END + call CheckLegacyAndVim9Success(lines) + + " map() + let lines =<< trim END + VAR s = "abc" + call map(s, 'nr2char(char2nr(v:val) + 2)') + call assert_equal('abc', s) + call assert_equal('cde', map('abc', 'nr2char(char2nr(v:val) + 2)')) + call assert_equal('[あ][i][う][え][お]', map('あiうえお', '"[" .. v:val .. "]"')) + call assert_equal('[あ][a][😊][,][‱][‼][⁇][⁈][⁉][💕][b][💕][c][💕]', map('あa😊,‱‼⁇⁈⁉💕b💕c💕', '"[" .. v:val .. "]"')) + call assert_equal('', map('abc', '""')) + call assert_equal('cde', map('abc', LSTART i, x LMIDDLE nr2char(char2nr(x) + 2) LEND)) + call assert_equal('[あ][i][う][え][お]', map('あiうえお', LSTART i, x LMIDDLE '[' .. x .. ']' LEND)) + call assert_equal('', map('abc', LSTART i, x LMIDDLE '' LEND)) + call assert_equal('', map('', "v:val == 'a'")) + call assert_equal('', map(v:_null_string, "v:val == 'a'")) + call assert_fails('echo map("abc", "10")', 'E928:') + call assert_fails('echo map("abc", "a10")', 'E121:') + END + call CheckLegacyAndVim9Success(lines) + + " mapnew() + let lines =<< trim END + VAR s = "abc" + call mapnew(s, 'nr2char(char2nr(v:val) + 2)') + call assert_equal('abc', s) + call assert_equal('cde', mapnew('abc', 'nr2char(char2nr(v:val) + 2)')) + call assert_equal('[あ][i][う][え][お]', mapnew('あiうえお', '"[" .. v:val .. "]"')) + call assert_equal('[あ][a][😊][,][‱][‼][⁇][⁈][⁉][💕][b][💕][c][💕]', mapnew('あa😊,‱‼⁇⁈⁉💕b💕c💕', '"[" .. v:val .. "]"')) + call assert_equal('', mapnew('abc', '""')) + call assert_equal('cde', mapnew('abc', LSTART i, x LMIDDLE nr2char(char2nr(x) + 2) LEND)) + call assert_equal('[あ][i][う][え][お]', mapnew('あiうえお', LSTART i, x LMIDDLE '[' .. x .. ']' LEND)) + call assert_equal('', mapnew('abc', LSTART i, x LMIDDLE '' LEND)) + call assert_equal('', mapnew('', "v:val == 'a'")) + call assert_equal('', mapnew(v:_null_string, "v:val == 'a'")) + END + call CheckLegacyAndVim9Success(lines) + + let lines =<< trim END + #" map() and filter() + call assert_equal('[あ][⁈][a][😊][⁉][💕][💕][b][💕]', map(filter('あx⁈ax😊x⁉💕💕b💕x', '"x" != v:val'), '"[" .. v:val .. "]"')) + + #" patterns-composing(\Z) + call assert_equal('ॠॠ', filter('ऊॠॡ,ऊॠॡ', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0x0960) LEND)) + call assert_equal('àà', filter('càt,càt', LSTART i, x LMIDDLE x =~ '\Za' LEND)) + call assert_equal('ÅÅ', filter('Åström,Åström', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0xc5) LEND)) + call assert_equal('öö', filter('Åström,Åström', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0xf6) LEND)) + call assert_equal('ऊ@ॡ', map('ऊॠॡ', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0x0960) ? '@' : x LEND)) + call assert_equal('c@t', map('càt', LSTART i, x LMIDDLE x =~ '\Za' ? '@' : x LEND)) + call assert_equal('@ström', map('Åström', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0xc5) ? '@' : x LEND)) + call assert_equal('Åstr@m', map('Åström', LSTART i, x LMIDDLE x =~ '\Z' .. nr2char(0xf6) ? '@' : x LEND)) + + #" patterns-composing(\%C) + call assert_equal('ॠॠ', filter('ऊॠॡ,ऊॠॡ', LSTART i, x LMIDDLE x =~ nr2char(0x0960) .. '\%C' LEND)) + call assert_equal('àà', filter('càt,càt', LSTART i, x LMIDDLE x =~ 'a' .. '\%C' LEND)) + call assert_equal('ÅÅ', filter('Åström,Åström', LSTART i, x LMIDDLE x =~ nr2char(0xc5) .. '\%C' LEND)) + call assert_equal('öö', filter('Åström,Åström', LSTART i, x LMIDDLE x =~ nr2char(0xf6) .. '\%C' LEND)) + call assert_equal('ऊ@ॡ', map('ऊॠॡ', LSTART i, x LMIDDLE x =~ nr2char(0x0960) .. '\%C' ? '@' : x LEND)) + call assert_equal('c@t', map('càt', LSTART i, x LMIDDLE x =~ 'a' .. '\%C' ? '@' : x LEND)) + call assert_equal('@ström', map('Åström', LSTART i, x LMIDDLE x =~ nr2char(0xc5) .. '\%C' ? '@' : x LEND)) + call assert_equal('Åstr@m', map('Åström', LSTART i, x LMIDDLE x =~ nr2char(0xf6) .. '\%C' ? '@' : x LEND)) + END + call CheckLegacyAndVim9Success(lines) +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/old/testdir/test_highlight.vim b/test/old/testdir/test_highlight.vim index 8ed03732c2..dcfd1a350a 100644 --- a/test/old/testdir/test_highlight.vim +++ b/test/old/testdir/test_highlight.vim @@ -864,17 +864,20 @@ func Test_highlight_default_colorscheme_restores_links() let hlTestHiPre = HighlightArgs('TestHi') " Test colorscheme + call assert_equal("\ndefault", execute('colorscheme')) hi clear if exists('syntax_on') syntax reset endif let g:colors_name = 'test' + call assert_equal("\ntest", execute('colorscheme')) hi link TestLink ErrorMsg hi TestHi ctermbg=green " Restore default highlighting colorscheme default " 'default' should work no matter if highlight group was cleared + call assert_equal("\ndefault", execute('colorscheme')) hi def link TestLink Identifier hi def TestHi ctermbg=red let hlTestLinkPost = HighlightArgs('TestLink') diff --git a/test/old/testdir/test_listdict.vim b/test/old/testdir/test_listdict.vim index dc155ce0fc..d6309bad1e 100644 --- a/test/old/testdir/test_listdict.vim +++ b/test/old/testdir/test_listdict.vim @@ -1079,6 +1079,7 @@ func Test_listdict_extend() let d = {'a': 'A', 'b': 'B'} call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 'error')", 'E737:') + call assert_fails("call extend(d, {'b': 0}, [])", 'E730:') call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 'xxx')", 'E475:') if has('float') call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 1.2)", 'E475:') diff --git a/test/old/testdir/test_search.vim b/test/old/testdir/test_search.vim index 4a92ae34e4..c8152af4f3 100644 --- a/test/old/testdir/test_search.vim +++ b/test/old/testdir/test_search.vim @@ -1762,6 +1762,8 @@ func Test_invalid_regexp() call assert_fails("call search('\\(')", 'E54:') call assert_fails("call search('\\)')", 'E55:') call assert_fails("call search('\\z\\(\\)')", 'E66:') + call assert_fails("call search('\\z2')", 'E67:') + call assert_fails("call search('\\zx')", 'E867:') call assert_fails("call search('\\%[ab')", 'E69:') call assert_fails("call search('\\%[]')", 'E70:') call assert_fails("call search('\\%9999999999999999999999999999v')", 'E951:') |