diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-02-28 20:18:52 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-02-28 20:46:06 +0800 |
commit | f6b9791212e86bac3e8128035dec2bfc5016927f (patch) | |
tree | 102e7ddbd2acfff973fd9a2d819a783139ce0167 /src/nvim/testdir | |
parent | 3f381f4d04aa70829a865c82292b7d23fec29c52 (diff) | |
download | rneovim-f6b9791212e86bac3e8128035dec2bfc5016927f.tar.gz rneovim-f6b9791212e86bac3e8128035dec2bfc5016927f.tar.bz2 rneovim-f6b9791212e86bac3e8128035dec2bfc5016927f.zip |
vim-patch:8.2.3438: cannot manipulate blobs
Problem: Cannot manipulate blobs.
Solution: Add blob2list() and list2blob(). (Yegappan Lakshmanan,
closes vim/vim#8868)
https://github.com/vim/vim/commit/5dfe467432638fac2e0156a2f9cd0d9eb569fb39
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/testdir')
-rw-r--r-- | src/nvim/testdir/test_blob.vim | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index b01d9309fa..28df120b78 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -666,6 +666,45 @@ func Test_blob_sort() call CheckLegacyAndVim9Failure(['call sort([11, 0z11], "N")'], 'E974:') endfunc +" Tests for the blob2list() function +func Test_blob2list() + call assert_fails('let v = blob2list(10)', 'E1238: Blob required for argument 1') + eval 0zFFFF->blob2list()->assert_equal([255, 255]) + let tests = [[0z0102, [1, 2]], + \ [0z00, [0]], + \ [0z, []], + \ [0z00000000, [0, 0, 0, 0]], + \ [0zAABB.CCDD, [170, 187, 204, 221]]] + for t in tests + call assert_equal(t[0]->blob2list(), t[1]) + endfor + exe 'let v = 0z' .. repeat('000102030405060708090A0B0C0D0E0F', 64) + call assert_equal(1024, blob2list(v)->len()) + call assert_equal([4, 8, 15], [v[100], v[1000], v[1023]]) + call assert_equal([], blob2list(v:_null_blob)) +endfunc + +" Tests for the list2blob() function +func Test_list2blob() + call assert_fails('let b = list2blob(0z10)', 'E1211: List required for argument 1') + let tests = [[[1, 2], 0z0102], + \ [[0], 0z00], + \ [[], 0z], + \ [[0, 0, 0, 0], 0z00000000], + \ [[170, 187, 204, 221], 0zAABB.CCDD], + \ ] + for t in tests + call assert_equal(t[0]->list2blob(), t[1]) + endfor + call assert_fails('let b = list2blob([1, []])', 'E745:') + call assert_fails('let b = list2blob([-1])', 'E1239:') + call assert_fails('let b = list2blob([256])', 'E1239:') + let b = range(16)->repeat(64)->list2blob() + call assert_equal(1024, b->len()) + call assert_equal([4, 8, 15], [b[100], b[1000], b[1023]]) + call assert_equal(0z, list2blob(v:_null_list)) +endfunc + " The following used to cause an out-of-bounds memory access func Test_blob2string() let v = '0z' .. repeat('01010101.', 444) |