blob: 13c1a888d921089eb53115394cb17f2232c96778 [file] [log] [blame]
" Tests for the writefile() function.
func Test_writefile()
let f = tempname()
call writefile(["over","written"], f, "b")
call writefile(["hello","world"], f, "b")
call writefile(["!", "good"], f, "a")
call writefile(["morning"], f, "ab")
call writefile(["", "vimmers"], f, "ab")
let l = readfile(f)
call assert_equal("hello", l[0])
call assert_equal("world!", l[1])
call assert_equal("good", l[2])
call assert_equal("morning", l[3])
call assert_equal("vimmers", l[4])
call delete(f)
endfunc
func Test_writefile_fails_gently()
call assert_fails('call writefile(["test"], "Xfile", [])', 'E730:')
call assert_false(filereadable("Xfile"))
call delete("Xfile")
call assert_fails('call writefile(["test", [], [], [], "tset"], "Xfile")', 'E730:')
call assert_false(filereadable("Xfile"))
call delete("Xfile")
call assert_fails('call writefile([], "Xfile", [])', 'E730:')
call assert_false(filereadable("Xfile"))
call delete("Xfile")
call assert_fails('call writefile([], [])', 'E730:')
endfunc