diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-08-17 12:37:52 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-08-17 13:14:32 +0800 |
commit | d9e7dad13945ce1f4110c37d5388b5c532dec0d3 (patch) | |
tree | 0cf385ae282fa00e739b1eb0926b86262b3b555a /test | |
parent | 8861f2af72481b1759a6935afa6dce2aae512359 (diff) | |
download | rneovim-d9e7dad13945ce1f4110c37d5388b5c532dec0d3.tar.gz rneovim-d9e7dad13945ce1f4110c37d5388b5c532dec0d3.tar.bz2 rneovim-d9e7dad13945ce1f4110c37d5388b5c532dec0d3.zip |
vim-patch:8.2.3818: cannot filter or map characters in a string
Problem: Cannot filter or map characters in a string.
Solution: Make filter() and map() work on a string. (Naruhiko Nishino,
closes vim/vim#9327)
https://github.com/vim/vim/commit/c479ce032f5d4d14bab9e479acbf42d758879893
Co-authored-by: rbtnn <naru123456789@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/old/testdir/test_filter_map.vim | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/test/old/testdir/test_filter_map.vim b/test/old/testdir/test_filter_map.vim index b11ab93143..c86e772d1f 100644 --- a/test/old/testdir/test_filter_map.vim +++ b/test/old/testdir/test_filter_map.vim @@ -84,8 +84,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 +136,68 @@ func Test_mapnew_blob() call assert_equal(0z129956, bout) endfunc +func Test_filter_map_string() + let s = "abc" + + " filter() + call filter(s, '"b" != v:val') + call assert_equal(s, 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')) + let t = "%),:;>?]}’”†‡…‰,‱‼⁇⁈⁉℃℉,、。〉》」,』】〕〗〙〛,!),.:,;?,]}" + let u = "%):;>?]}’”†‡…‰‱‼⁇⁈⁉℃℉、。〉》」』】〕〗〙〛!),.:;?]}" + call assert_equal(u, filter(t, '"," != v:val')) + call assert_equal('', filter('abc', '0')) + call assert_equal('ac', filter('abc', { i, x -> "b" != x })) + call assert_equal('あいうえお', filter('あxいxうxえxお', { i, x -> "x" != x })) + call assert_equal('', filter('abc', { i, x -> v:false })) + + " map() + call map(s, 'nr2char(char2nr(v:val) + 2)') + call assert_equal(s, 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', { i, x -> nr2char(char2nr(x) + 2) })) + call assert_equal('[あ][i][う][え][お]', map('あiうえお', { i, x -> '[' .. x .. ']' })) + call assert_equal('', map('abc', { i, x -> '' })) + + " mapnew() + call mapnew(s, 'nr2char(char2nr(v:val) + 2)') + call assert_equal(s, 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', { i, x -> nr2char(char2nr(x) + 2) })) + call assert_equal('[あ][i][う][え][お]', mapnew('あiうえお', { i, x -> '[' .. x .. ']' })) + call assert_equal('', mapnew('abc', { i, x -> '' })) + + " 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('ऊॠॡ,ऊॠॡ', {i,x -> x =~ '\Z' .. nr2char(0x0960) })) + call assert_equal('àà', filter('càt,càt', {i,x -> x =~ '\Za' })) + call assert_equal('ÅÅ', filter('Åström,Åström', {i,x -> x =~ '\Z' .. nr2char(0xc5) })) + call assert_equal('öö', filter('Åström,Åström', {i,x -> x =~ '\Z' .. nr2char(0xf6) })) + call assert_equal('ऊ@ॡ', map('ऊॠॡ', {i,x -> x =~ '\Z' .. nr2char(0x0960) ? '@' : x })) + call assert_equal('c@t', map('càt', {i,x -> x =~ '\Za' ? '@' : x })) + call assert_equal('@ström', map('Åström', {i,x -> x =~ '\Z' .. nr2char(0xc5) ? '@' : x })) + call assert_equal('Åstr@m', map('Åström', {i,x -> x =~ '\Z' .. nr2char(0xf6) ? '@' : x })) + + " patterns-composing(\%C) + call assert_equal('ॠॠ', filter('ऊॠॡ,ऊॠॡ', {i,x -> x =~ nr2char(0x0960) .. '\%C' })) + call assert_equal('àà', filter('càt,càt', {i,x -> x =~ 'a' .. '\%C' })) + call assert_equal('ÅÅ', filter('Åström,Åström', {i,x -> x =~ nr2char(0xc5) .. '\%C' })) + call assert_equal('öö', filter('Åström,Åström', {i,x -> x =~ nr2char(0xf6) .. '\%C' })) + call assert_equal('ऊ@ॡ', map('ऊॠॡ', {i,x -> x =~ nr2char(0x0960) .. '\%C' ? '@' : x })) + call assert_equal('c@t', map('càt', {i,x -> x =~ 'a' .. '\%C' ? '@' : x })) + call assert_equal('@ström', map('Åström', {i,x -> x =~ nr2char(0xc5) .. '\%C' ? '@' : x })) + call assert_equal('Åstr@m', map('Åström', {i,x -> x =~ nr2char(0xf6) .. '\%C' ? '@' : x })) +endfunc + " vim: shiftwidth=2 sts=2 expandtab |