view src/testdir/test_writefile.vim @ 11583:ef8b233f07ae v8.0.0674

patch 8.0.0674: cannot build with eval but without timers commit https://github.com/vim/vim/commit/5d7be4f0fa04a9210a14fca69b4f9e34613b378f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 25 13:40:17 2017 +0200 patch 8.0.0674: cannot build with eval but without timers Problem: Cannot build with eval but without timers. Solution: Add #ifdef (John Marriott)
author Christian Brabandt <cb@256bit.org>
date Sun, 25 Jun 2017 13:45:03 +0200
parents 4a1f7849fe86
children 16ccaedce025
line wrap: on
line source

" 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