diff options
author | rbtnn <naru123456789@gmail.com> | 2021-12-18 18:33:46 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-12-18 18:33:46 +0000 |
commit | 0ccb5842f5fb103763d106c7aa364d758343c35a (patch) | |
tree | 76ea36f2abf5035e3695132e0cc5b59e2e9a325c /src/testdir/test_listdict.vim | |
parent | 605ec91e5a7330d61be313637e495fa02a6dc264 (diff) | |
download | vim-git-0ccb5842f5fb103763d106c7aa364d758343c35a.tar.gz |
patch 8.2.3848: cannot use reduce() for a stringv8.2.3848
Problem: Cannot use reduce() for a string.
Solution: Make reduce() work with a string. (Naruhiko Nishino, closes #9366)
Diffstat (limited to 'src/testdir/test_listdict.vim')
-rw-r--r-- | src/testdir/test_listdict.vim | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim index 30f47adc6..c76731325 100644 --- a/src/testdir/test_listdict.vim +++ b/src/testdir/test_listdict.vim @@ -1,4 +1,5 @@ " Tests for the List and Dict types +scriptencoding utf-8 source vim9.vim @@ -936,7 +937,7 @@ func Test_reverse_sort_uniq() call assert_fails("call sort([1, 2], function('min'))", "E118:") endfunc -" reduce a list or a blob +" reduce a list, blob or string func Test_reduce() let lines =<< trim END call assert_equal(1, reduce([], LSTART acc, val LMIDDLE acc + val LEND, 1)) @@ -959,6 +960,16 @@ func Test_reduce() call assert_equal(0xff, reduce(0zff, LSTART acc, val LMIDDLE acc + val LEND)) call assert_equal(2 * (2 * 0xaf + 0xbf) + 0xcf, reduce(0zAFBFCF, LSTART acc, val LMIDDLE 2 * acc + val LEND)) + + call assert_equal('x,y,z', 'xyz'->reduce(LSTART acc, val LMIDDLE acc .. ',' .. val LEND)) + call assert_equal('', ''->reduce(LSTART acc, val LMIDDLE acc .. ',' .. val LEND, '')) + call assert_equal('あ,い,う,え,お,😊,💕', 'あいうえお😊💕'->reduce(LSTART acc, val LMIDDLE acc .. ',' .. val LEND)) + call assert_equal('😊,あ,い,う,え,お,💕', 'あいうえお💕'->reduce(LSTART acc, val LMIDDLE acc .. ',' .. val LEND, '😊')) + call assert_equal('ऊ,ॠ,ॡ', reduce('ऊॠॡ', LSTART acc, val LMIDDLE acc .. ',' .. val LEND)) + call assert_equal('c,à,t', reduce('càt', LSTART acc, val LMIDDLE acc .. ',' .. val LEND)) + call assert_equal('Å,s,t,r,ö,m', reduce('Åström', LSTART acc, val LMIDDLE acc .. ',' .. val LEND)) + call assert_equal('Å,s,t,r,ö,m', reduce('Åström', LSTART acc, val LMIDDLE acc .. ',' .. val LEND)) + call assert_equal(',a,b,c', reduce('abc', LSTART acc, val LMIDDLE acc .. ',' .. val LEND, test_null_string())) END call CheckLegacyAndVim9Success(lines) @@ -967,13 +978,23 @@ func Test_reduce() call assert_fails("call reduce([], { acc, val -> acc + val })", 'E998: Reduce of an empty List with no initial value') call assert_fails("call reduce(0z, { acc, val -> acc + val })", 'E998: Reduce of an empty Blob with no initial value') + call assert_fails("call reduce('', { acc, val -> acc + val })", 'E998: Reduce of an empty String with no initial value') + call assert_fails("call reduce(test_null_string(), { acc, val -> acc + val })", 'E998: Reduce of an empty String with no initial value') - call assert_fails("call reduce({}, { acc, val -> acc + val }, 1)", 'E897:') - call assert_fails("call reduce(0, { acc, val -> acc + val }, 1)", 'E897:') - call assert_fails("call reduce('', { acc, val -> acc + val }, 1)", 'E897:') + call assert_fails("call reduce({}, { acc, val -> acc + val }, 1)", 'E1098:') + call assert_fails("call reduce(0, { acc, val -> acc + val }, 1)", 'E1098:') call assert_fails("call reduce([1, 2], 'Xdoes_not_exist')", 'E117:') call assert_fails("echo reduce(0z01, { acc, val -> 2 * acc + val }, '')", 'E39:') + call assert_fails("vim9 reduce(0, (acc, val) => (acc .. val), '')", 'E1252:') + call assert_fails("vim9 reduce({}, (acc, val) => (acc .. val), '')", 'E1252:') + call assert_fails("vim9 reduce(0.1, (acc, val) => (acc .. val), '')", 'E1252:') + call assert_fails("vim9 reduce(function('tr'), (acc, val) => (acc .. val), '')", 'E1252:') + call assert_fails("call reduce('', { acc, val -> acc + val }, 1)", 'E1253:') + call assert_fails("call reduce('', { acc, val -> acc + val }, {})", 'E1253:') + call assert_fails("call reduce('', { acc, val -> acc + val }, 0.1)", 'E1253:') + call assert_fails("call reduce('', { acc, val -> acc + val }, function('tr'))", 'E1253:') + let g:lut = [1, 2, 3, 4] func EvilRemove() call remove(g:lut, 1) |