diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-08-30 17:45:33 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-08-30 17:45:33 +0100 |
commit | 3e518a8ec74065aedd67d352c93d6ae6be550316 (patch) | |
tree | 239505fa04b1012bfccad56d6cc3f7f6517bfe78 /src/testdir | |
parent | f92cfb1acc3fef74eef0c83c1a35a2b6a9f93a9b (diff) |
patch 9.0.0331: cannot use items() on a stringv9.0.0331
Problem: Cannot use items() on a string.
Solution: Make items() work on a string. (closes #11016)
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/test_listdict.vim | 11 | ||||
-rw-r--r-- | src/testdir/test_vim9_builtin.vim | 8 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim index c87d701a36..89c4243bd7 100644 --- a/src/testdir/test_listdict.vim +++ b/src/testdir/test_listdict.vim @@ -206,7 +206,16 @@ func Test_list_items() endfor call assert_equal([[0, 'a'], [1, 'b'], [2, 'c']], r) - call assert_fails('call items(3)', 'E1227:') + call assert_fails('call items(3)', 'E1225:') +endfunc + +func Test_string_items() + let r = [] + let s = 'ábツ' + for [idx, val] in items(s) + call extend(r, [[idx, val]]) + endfor + call assert_equal([[0, 'á'], [1, 'b'], [2, 'ツ']], r) endfunc " Test removing items in list diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index 5eb64adefa..13f87cb8e5 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -799,7 +799,7 @@ enddef def Test_count() count('ABC ABC ABC', 'b', true)->assert_equal(3) count('ABC ABC ABC', 'b', false)->assert_equal(0) - v9.CheckDefAndScriptFailure(['count(10, 1)'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E1225: String, List or Dictionary required for argument 1']) + v9.CheckDefAndScriptFailure(['count(10, 1)'], 'E1225: String, List or Dictionary required for argument 1') v9.CheckDefAndScriptFailure(['count("a", [1], 2)'], ['E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3']) v9.CheckDefAndScriptFailure(['count("a", [1], 0, "b")'], ['E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4']) count([1, 2, 2, 3], 2)->assert_equal(2) @@ -2244,7 +2244,7 @@ def Test_islocked() enddef def Test_items() - v9.CheckDefFailure(['"x"->items()'], 'E1013: Argument 1: type mismatch, expected list<any> but got string') + v9.CheckDefFailure(['123->items()'], 'E1225:') assert_equal([['a', 10], ['b', 20]], {'a': 10, 'b': 20}->items()) assert_equal([], {}->items()) assert_equal(['x', 'x'], {'a': 10, 'b': 20}->items()->map((_, _) => 'x')) @@ -2252,6 +2252,10 @@ def Test_items() assert_equal([[0, 'a'], [1, 'b']], ['a', 'b']->items()) assert_equal([], []->items()) assert_equal([], test_null_list()->items()) + + assert_equal([[0, 'a'], [1, '웃'], [2, 'ć']], 'a웃ć'->items()) + assert_equal([], ''->items()) + assert_equal([], test_null_string()->items()) enddef def Test_job_getchannel() |