Mercurial > vim
diff src/testdir/test_vim9_builtin.vim @ 23602:7b3317e959e3 v8.2.2343
patch 8.2.2343: Vim9: return type of readfile() is any
Commit: https://github.com/vim/vim/commit/c423ad77ed763c11ba67729bbf63c1cf0915231f
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jan 13 20:38:03 2021 +0100
patch 8.2.2343: Vim9: return type of readfile() is any
Problem: Vim9: return type of readfile() is any.
Solution: Add readblob() so that readfile() can be expected to always
return a list of strings. (closes #7671)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 13 Jan 2021 20:45:04 +0100 |
parents | 9fa72351c18f |
children | 1816ea68c022 |
line wrap: on
line diff
--- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -623,6 +623,32 @@ def Test_readdir() eval expand('sautest')->readdirex((e) => e.name[0] !=# '.') enddef +def Test_readblob() + var blob = 0z12341234 + writefile(blob, 'Xreadblob') + var read: blob = readblob('Xreadblob') + assert_equal(blob, read) + + var lines =<< trim END + var read: list<string> = readblob('Xreadblob') + END + CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1) + delete('Xreadblob') +enddef + +def Test_readfile() + var text = ['aaa', 'bbb', 'ccc'] + writefile(text, 'Xreadfile') + var read: list<string> = readfile('Xreadfile') + assert_equal(text, read) + + var lines =<< trim END + var read: dict<string> = readfile('Xreadfile') + END + CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1) + delete('Xreadfile') +enddef + def Test_remove_return_type() var l = remove({one: [1, 2], two: [3, 4]}, 'one') var res = 0