comparison 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
comparison
equal deleted inserted replaced
23601:3b600f015796 23602:7b3317e959e3
621 def Test_readdir() 621 def Test_readdir()
622 eval expand('sautest')->readdir((e) => e[0] !=# '.') 622 eval expand('sautest')->readdir((e) => e[0] !=# '.')
623 eval expand('sautest')->readdirex((e) => e.name[0] !=# '.') 623 eval expand('sautest')->readdirex((e) => e.name[0] !=# '.')
624 enddef 624 enddef
625 625
626 def Test_readblob()
627 var blob = 0z12341234
628 writefile(blob, 'Xreadblob')
629 var read: blob = readblob('Xreadblob')
630 assert_equal(blob, read)
631
632 var lines =<< trim END
633 var read: list<string> = readblob('Xreadblob')
634 END
635 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected list<string> but got blob', 1)
636 delete('Xreadblob')
637 enddef
638
639 def Test_readfile()
640 var text = ['aaa', 'bbb', 'ccc']
641 writefile(text, 'Xreadfile')
642 var read: list<string> = readfile('Xreadfile')
643 assert_equal(text, read)
644
645 var lines =<< trim END
646 var read: dict<string> = readfile('Xreadfile')
647 END
648 CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<string> but got list<string>', 1)
649 delete('Xreadfile')
650 enddef
651
626 def Test_remove_return_type() 652 def Test_remove_return_type()
627 var l = remove({one: [1, 2], two: [3, 4]}, 'one') 653 var l = remove({one: [1, 2], two: [3, 4]}, 'one')
628 var res = 0 654 var res = 0
629 for n in l 655 for n in l
630 res += n 656 res += n