comparison src/testdir/test_blob.vim @ 29712:bdb31515f78b v9.0.0196

patch 9.0.0196: finding value in list may require a for loop Commit: https://github.com/vim/vim/commit/b218655d5a485f5b193fb18d7240837d42b89812 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Aug 13 13:09:20 2022 +0100 patch 9.0.0196: finding value in list may require a for loop Problem: Finding value in list may require a for loop. Solution: Add indexof(). (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/10903)
author Bram Moolenaar <Bram@vim.org>
date Sat, 13 Aug 2022 14:15:05 +0200
parents 35e24d9de858
children cadc9851377d
comparison
equal deleted inserted replaced
29711:4069513e8995 29712:bdb31515f78b
762 call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0) 762 call test_alloc_fail(GetAllocId('blob_alloc'), 0, 0)
763 call assert_fails('let x = readblob("test_blob.vim")', 'E342:') 763 call assert_fails('let x = readblob("test_blob.vim")', 'E342:')
764 call assert_equal(0, x) 764 call assert_equal(0, x)
765 endfunc 765 endfunc
766 766
767 " Test for the indexof() function
768 func Test_indexof()
769 let b = 0zdeadbeef
770 call assert_equal(0, indexof(b, {i, v -> v == 0xde}))
771 call assert_equal(3, indexof(b, {i, v -> v == 0xef}))
772 call assert_equal(-1, indexof(b, {i, v -> v == 0x1}))
773 call assert_equal(1, indexof(b, "v:val == 0xad"))
774 call assert_equal(-1, indexof(b, "v:val == 0xff"))
775
776 call assert_equal(-1, indexof(0z, "v:val == 0x0"))
777 call assert_equal(-1, indexof(test_null_blob(), "v:val == 0xde"))
778 call assert_equal(-1, indexof(b, test_null_string()))
779 call assert_equal(-1, indexof(b, test_null_function()))
780
781 let b = 0z01020102
782 call assert_equal(1, indexof(b, "v:val == 0x02", #{startidx: 0}))
783 call assert_equal(2, indexof(b, "v:val == 0x01", #{startidx: -2}))
784 call assert_equal(-1, indexof(b, "v:val == 0x01", #{startidx: 5}))
785 call assert_equal(0, indexof(b, "v:val == 0x01", #{startidx: -5}))
786 call assert_equal(0, indexof(b, "v:val == 0x01", test_null_dict()))
787
788 " failure cases
789 call assert_fails('let i = indexof(b, "val == 0xde")', 'E121:')
790 call assert_fails('let i = indexof(b, {})', 'E1256:')
791 endfunc
792
767 " vim: shiftwidth=2 sts=2 expandtab 793 " vim: shiftwidth=2 sts=2 expandtab