diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2022-08-13 13:09:20 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-08-13 13:09:20 +0100 |
commit | b218655d5a485f5b193fb18d7240837d42b89812 (patch) | |
tree | 63cd2df4a3e2f3bbd0cac7bbe6ab637c56c6b6c5 /src/testdir/test_blob.vim | |
parent | 9032b9ceb6073288d75386dbcbd9d1982fa24080 (diff) |
patch 9.0.0196: finding value in list may require a for loopv9.0.0196
Problem: Finding value in list may require a for loop.
Solution: Add indexof(). (Yegappan Lakshmanan, closes #10903)
Diffstat (limited to 'src/testdir/test_blob.vim')
-rw-r--r-- | src/testdir/test_blob.vim | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/testdir/test_blob.vim b/src/testdir/test_blob.vim index ff4186a730..46f2d61ad3 100644 --- a/src/testdir/test_blob.vim +++ b/src/testdir/test_blob.vim @@ -764,4 +764,30 @@ func Test_blob_alloc_failure() call assert_equal(0, x) endfunc +" Test for the indexof() function +func Test_indexof() + let b = 0zdeadbeef + call assert_equal(0, indexof(b, {i, v -> v == 0xde})) + call assert_equal(3, indexof(b, {i, v -> v == 0xef})) + call assert_equal(-1, indexof(b, {i, v -> v == 0x1})) + call assert_equal(1, indexof(b, "v:val == 0xad")) + call assert_equal(-1, indexof(b, "v:val == 0xff")) + + call assert_equal(-1, indexof(0z, "v:val == 0x0")) + call assert_equal(-1, indexof(test_null_blob(), "v:val == 0xde")) + call assert_equal(-1, indexof(b, test_null_string())) + call assert_equal(-1, indexof(b, test_null_function())) + + let b = 0z01020102 + call assert_equal(1, indexof(b, "v:val == 0x02", #{startidx: 0})) + call assert_equal(2, indexof(b, "v:val == 0x01", #{startidx: -2})) + call assert_equal(-1, indexof(b, "v:val == 0x01", #{startidx: 5})) + call assert_equal(0, indexof(b, "v:val == 0x01", #{startidx: -5})) + call assert_equal(0, indexof(b, "v:val == 0x01", test_null_dict())) + + " failure cases + call assert_fails('let i = indexof(b, "val == 0xde")', 'E121:') + call assert_fails('let i = indexof(b, {})', 'E1256:') +endfunc + " vim: shiftwidth=2 sts=2 expandtab |