mirror of
https://github.com/vim/vim.git
synced 2025-10-26 09:14:23 -04:00
patch 9.1.1668: items() does not work for Blobs
Problem: items() does not work for Blobs
Solution: Extend items() to support Blob
(Yegappan Lakshmanan).
closes: #18080
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
6b56711804
commit
da34f84847
@@ -865,4 +865,15 @@ func Test_indexof()
|
||||
call assert_fails('let i = indexof(b, " ")', 'E15:')
|
||||
endfunc
|
||||
|
||||
" Test for using the items() function with a blob
|
||||
func Test_blob_items()
|
||||
let lines =<< trim END
|
||||
call assert_equal([[0, 0xAA], [1, 0xBB], [2, 0xCC]], 0zAABBCC->items())
|
||||
call assert_equal([[0, 0]], 0z00->items())
|
||||
call assert_equal([], 0z->items())
|
||||
call assert_equal([], test_null_blob()->items())
|
||||
END
|
||||
call v9.CheckSourceLegacyAndVim9Success(lines)
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
||||
@@ -230,7 +230,7 @@ func Test_list_items()
|
||||
endfor
|
||||
call assert_equal([[0, 'a'], [1, 'b'], [2, 'c']], r)
|
||||
|
||||
call assert_fails('call items(3)', 'E1225:')
|
||||
call assert_fails('call items(3)', 'E1251:')
|
||||
endfunc
|
||||
|
||||
func Test_string_items()
|
||||
|
||||
@@ -76,7 +76,7 @@ func Test_string_method()
|
||||
eval "a\rb\ec"->strtrans()->assert_equal('a^Mb^[c')
|
||||
eval "aあb"->strwidth()->assert_equal(4)
|
||||
eval 'abc'->substitute('b', 'x', '')->assert_equal('axc')
|
||||
call assert_fails('eval 123->items()', 'E1225:')
|
||||
call assert_fails('eval 123->items()', 'E1251: List, Tuple, Dictionary, Blob or String required for argument 1')
|
||||
|
||||
eval 'abc'->printf('the %s arg')->assert_equal('the abc arg')
|
||||
endfunc
|
||||
|
||||
@@ -1655,7 +1655,7 @@ enddef
|
||||
|
||||
def Test_foreach()
|
||||
CheckFeature job
|
||||
v9.CheckSourceDefAndScriptFailure(['foreach(test_null_job(), "")'], ['E1013: Argument 1: type mismatch, expected list<any> but got job', 'E1251: List, Tuple, Dictionary, Blob or String required for argument 1'])
|
||||
v9.CheckSourceDefAndScriptFailure(['foreach(test_null_job(), "")'], 'E1251: List, Tuple, Dictionary, Blob or String required for argument 1')
|
||||
enddef
|
||||
|
||||
def Test_fullcommand()
|
||||
@@ -2492,15 +2492,19 @@ def Test_islocked()
|
||||
enddef
|
||||
|
||||
def Test_items()
|
||||
v9.CheckSourceDefFailure(['123->items()'], 'E1225:')
|
||||
v9.CheckSourceDefFailure(['123->items()'], 'E1251: List, Tuple, Dictionary, Blob or String required for argument 1')
|
||||
|
||||
# Dict
|
||||
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'))
|
||||
|
||||
# List
|
||||
assert_equal([[0, 'a'], [1, 'b']], ['a', 'b']->items())
|
||||
assert_equal([], []->items())
|
||||
assert_equal([], test_null_list()->items())
|
||||
|
||||
# String
|
||||
assert_equal([[0, 'a'], [1, '웃'], [2, 'ć']], 'a웃ć'->items())
|
||||
assert_equal([], ''->items())
|
||||
assert_equal([], test_null_string()->items())
|
||||
|
||||
Reference in New Issue
Block a user