annotate src/testdir/test_writefile.vim @ 21580:93dae47699fb v8.2.1340

patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD Commit: https://github.com/vim/vim/commit/b86abadf87bd0f85f800077171ec4b98aefff776 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 1 16:08:19 2020 +0200 patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD Problem: Some tests fail on Cirrus CI and/or with FreeBSD. Solution: Make 'backupskip' empty. Do not run tests as root. Check for directory when using viminfo. (Ozaki Kiichi, closes #6596)
author Bram Moolenaar <Bram@vim.org>
date Sat, 01 Aug 2020 16:15:04 +0200
parents dc1c26547a42
children 08940efa6b4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18386
105c6cf8b266 patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents: 16869
diff changeset
1 " Tests for the writefile() function and some :write commands.
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
19277
1b02482e6a61 patch 8.2.0197: some Ex commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19231
diff changeset
3 source check.vim
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
4 source term_util.vim
19277
1b02482e6a61 patch 8.2.0197: some Ex commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19231
diff changeset
5
11519
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
6 func Test_writefile()
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 let f = tempname()
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 call writefile(["over","written"], f, "b")
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 call writefile(["hello","world"], f, "b")
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 call writefile(["!", "good"], f, "a")
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 call writefile(["morning"], f, "ab")
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call writefile(["", "vimmers"], f, "ab")
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 let l = readfile(f)
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 call assert_equal("hello", l[0])
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_equal("world!", l[1])
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 call assert_equal("good", l[2])
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call assert_equal("morning", l[3])
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 call assert_equal("vimmers", l[4])
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 call delete(f)
19695
1697a25328fd patch 8.2.0404: writefile() error does not give a hint
Bram Moolenaar <Bram@vim.org>
parents: 19425
diff changeset
20
1697a25328fd patch 8.2.0404: writefile() error does not give a hint
Bram Moolenaar <Bram@vim.org>
parents: 19425
diff changeset
21 call assert_fails('call writefile("text", "Xfile")', 'E475: Invalid argument: writefile() first argument must be a List or a Blob')
11519
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
22 endfunc
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
23
18386
105c6cf8b266 patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents: 16869
diff changeset
24 func Test_writefile_ignore_regexp_error()
105c6cf8b266 patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents: 16869
diff changeset
25 write Xt[z-a]est.txt
105c6cf8b266 patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents: 16869
diff changeset
26 call delete('Xt[z-a]est.txt')
105c6cf8b266 patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents: 16869
diff changeset
27 endfunc
105c6cf8b266 patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents: 16869
diff changeset
28
11519
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
29 func Test_writefile_fails_gently()
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
30 call assert_fails('call writefile(["test"], "Xfile", [])', 'E730:')
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
31 call assert_false(filereadable("Xfile"))
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
32 call delete("Xfile")
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
33
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
34 call assert_fails('call writefile(["test", [], [], [], "tset"], "Xfile")', 'E730:')
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
35 call assert_false(filereadable("Xfile"))
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
36 call delete("Xfile")
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
37
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
38 call assert_fails('call writefile([], "Xfile", [])', 'E730:')
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
39 call assert_false(filereadable("Xfile"))
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
40 call delete("Xfile")
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
41
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
42 call assert_fails('call writefile([], [])', 'E730:')
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
43 endfunc
11605
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
44
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
45 func Test_writefile_fails_conversion()
15677
772e72b046a3 patch 8.1.0846: not easy to recognize the system Vim runs on
Bram Moolenaar <Bram@vim.org>
parents: 15607
diff changeset
46 if !has('iconv') || has('sun')
11605
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
47 return
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
48 endif
16694
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
49 " Without a backup file the write won't happen if there is a conversion
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
50 " error.
16869
e264d45f268a patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents: 16694
diff changeset
51 set nobackup nowritebackup backupdir=. backupskip=
11605
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
52 new
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
53 let contents = ["line one", "line two"]
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
54 call writefile(contents, 'Xfile')
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
55 edit Xfile
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
56 call setline(1, ["first line", "cannot convert \u010b", "third line"])
16694
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
57 call assert_fails('write ++enc=cp932', 'E513:')
11605
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
58 call assert_equal(contents, readfile('Xfile'))
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
59
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
60 call delete('Xfile')
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
61 bwipe!
16869
e264d45f268a patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents: 16694
diff changeset
62 set backup& writebackup& backupdir&vim backupskip&vim
11605
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
63 endfunc
12624
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
64
16694
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
65 func Test_writefile_fails_conversion2()
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
66 if !has('iconv') || has('sun')
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
67 return
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
68 endif
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
69 " With a backup file the write happens even if there is a conversion error,
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
70 " but then the backup file must remain
16869
e264d45f268a patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents: 16694
diff changeset
71 set nobackup writebackup backupdir=. backupskip=
16694
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
72 let contents = ["line one", "line two"]
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
73 call writefile(contents, 'Xfile_conversion_err')
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
74 edit Xfile_conversion_err
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
75 call setline(1, ["first line", "cannot convert \u010b", "third line"])
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
76 set fileencoding=latin1
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
77 let output = execute('write')
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
78 call assert_match('CONVERSION ERROR', output)
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
79 call assert_equal(contents, readfile('Xfile_conversion_err~'))
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
80
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
81 call delete('Xfile_conversion_err')
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
82 call delete('Xfile_conversion_err~')
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
83 bwipe!
16869
e264d45f268a patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents: 16694
diff changeset
84 set backup& writebackup& backupdir&vim backupskip&vim
16694
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
85 endfunc
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
86
12624
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
87 func SetFlag(timer)
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
88 let g:flag = 1
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
89 endfunc
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
90
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
91 func Test_write_quit_split()
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
92 " Prevent exiting by splitting window on file write.
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
93 augroup testgroup
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
94 autocmd BufWritePre * split
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
95 augroup END
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
96 e! Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
97 call setline(1, 'nothing')
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
98 wq
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
99
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
100 if has('timers')
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
101 " timer will not run if "exiting" is still set
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
102 let g:flag = 0
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
103 call timer_start(1, 'SetFlag')
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
104 sleep 50m
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
105 call assert_equal(1, g:flag)
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
106 unlet g:flag
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
107 endif
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
108 au! testgroup
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
109 bwipe Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
110 call delete('Xfile')
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
111 endfunc
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
112
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
113 func Test_nowrite_quit_split()
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
114 " Prevent exiting by opening a help window.
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
115 e! Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
116 help
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
117 wincmd w
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
118 exe winnr() . 'q'
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
119
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
120 if has('timers')
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
121 " timer will not run if "exiting" is still set
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
122 let g:flag = 0
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
123 call timer_start(1, 'SetFlag')
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
124 sleep 50m
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
125 call assert_equal(1, g:flag)
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
126 unlet g:flag
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
127 endif
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
128 bwipe Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
129 endfunc
12857
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
130
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
131 func Test_writefile_sync_arg()
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
132 " This doesn't check if fsync() works, only that the argument is accepted.
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
133 call writefile(['one'], 'Xtest', 's')
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
134 call writefile(['two'], 'Xtest', 'S')
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
135 call delete('Xtest')
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
136 endfunc
12926
98503d690368 patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents: 12857
diff changeset
137
98503d690368 patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents: 12857
diff changeset
138 func Test_writefile_sync_dev_stdout()
21580
93dae47699fb patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 21532
diff changeset
139 CheckUnix
13744
d6553cde1292 patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents: 12926
diff changeset
140 if filewritable('/dev/stdout')
d6553cde1292 patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents: 12926
diff changeset
141 " Just check that this doesn't cause an error.
d6553cde1292 patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents: 12926
diff changeset
142 call writefile(['one'], '/dev/stdout')
d6553cde1292 patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents: 12926
diff changeset
143 else
d6553cde1292 patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents: 12926
diff changeset
144 throw 'Skipped: /dev/stdout is not writable'
d6553cde1292 patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents: 12926
diff changeset
145 endif
12926
98503d690368 patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents: 12857
diff changeset
146 endfunc
14642
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
147
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
148 func Test_writefile_autowrite()
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
149 set autowrite
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
150 new
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
151 next Xa Xb Xc
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
152 call setline(1, 'aaa')
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
153 next
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
154 call assert_equal(['aaa'], readfile('Xa'))
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
155 call setline(1, 'bbb')
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
156 call assert_fails('edit XX')
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
157 call assert_false(filereadable('Xb'))
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
158
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
159 set autowriteall
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
160 edit XX
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
161 call assert_equal(['bbb'], readfile('Xb'))
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
162
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
163 bwipe!
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
164 call delete('Xa')
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
165 call delete('Xb')
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
166 set noautowrite
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
167 endfunc
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
168
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
169 func Test_writefile_autowrite_nowrite()
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
170 set autowrite
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
171 new
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
172 next Xa Xb Xc
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
173 set buftype=nowrite
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
174 call setline(1, 'aaa')
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
175 let buf = bufnr('%')
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
176 " buffer contents silently lost
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
177 edit XX
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
178 call assert_false(filereadable('Xa'))
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
179 rewind
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
180 call assert_equal('', getline(1))
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
181
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
182 bwipe!
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
183 set noautowrite
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
184 endfunc
19231
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
185
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
186 " Test for ':w !<cmd>' to pipe lines from the current buffer to an external
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
187 " command.
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
188 func Test_write_pipe_to_cmd()
19277
1b02482e6a61 patch 8.2.0197: some Ex commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19231
diff changeset
189 CheckUnix
19231
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
190 new
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
191 call setline(1, ['L1', 'L2', 'L3', 'L4'])
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
192 2,3w !cat > Xfile
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
193 call assert_equal(['L2', 'L3'], readfile('Xfile'))
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
194 close!
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
195 call delete('Xfile')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
196 endfunc
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
197
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
198 " Test for :saveas
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
199 func Test_saveas()
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
200 call assert_fails('saveas', 'E471:')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
201 call writefile(['L1'], 'Xfile')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
202 new Xfile
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
203 new
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
204 call setline(1, ['L1'])
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
205 call assert_fails('saveas Xfile', 'E139:')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
206 close!
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
207 enew | only
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
208 call delete('Xfile')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
209 endfunc
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
210
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
211 func Test_write_errors()
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
212 " Test for writing partial buffer
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
213 call writefile(['L1', 'L2', 'L3'], 'Xfile')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
214 new Xfile
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
215 call assert_fails('1,2write', 'E140:')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
216 close!
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
217
19384
6c944fee0d7e patch 8.2.0250: test_clear_search_pat() is unused
Bram Moolenaar <Bram@vim.org>
parents: 19277
diff changeset
218 call assert_fails('w > Xtest', 'E494:')
19425
67fbe280a502 patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19384
diff changeset
219
19231
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
220 " Try to overwrite a directory
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
221 if has('unix')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
222 call mkdir('Xdir1')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
223 call assert_fails('write Xdir1', 'E17:')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
224 call delete('Xdir1', 'd')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
225 endif
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
226
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
227 " Test for :wall for a buffer with no name
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
228 enew | only
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
229 call setline(1, ['L1'])
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
230 call assert_fails('wall', 'E141:')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
231 enew!
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
232
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
233 " Test for writing a 'readonly' file
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
234 new Xfile
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
235 set readonly
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
236 call assert_fails('write', 'E45:')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
237 close
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
238
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
239 " Test for writing to a read-only file
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
240 new Xfile
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
241 call setfperm('Xfile', 'r--r--r--')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
242 call assert_fails('write', 'E505:')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
243 call setfperm('Xfile', 'rw-rw-rw-')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
244 close
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
245
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
246 call delete('Xfile')
20178
2fb397573541 patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents: 19695
diff changeset
247
2fb397573541 patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents: 19695
diff changeset
248 call writefile(test_null_list(), 'Xfile')
2fb397573541 patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents: 19695
diff changeset
249 call assert_false(filereadable('Xfile'))
2fb397573541 patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents: 19695
diff changeset
250 call writefile(test_null_blob(), 'Xfile')
2fb397573541 patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents: 19695
diff changeset
251 call assert_false(filereadable('Xfile'))
2fb397573541 patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents: 19695
diff changeset
252 call assert_fails('call writefile([], "")', 'E482:')
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
253
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
254 " very long file name
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
255 let long_fname = repeat('n', 5000)
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
256 call assert_fails('exe "w " .. long_fname', 'E75:')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
257 call assert_fails('call writefile([], long_fname)', 'E482:')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
258 endfunc
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
259
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
260 " Test for writing to a file which is modified after Vim read it
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
261 func Test_write_file_mtime()
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
262 CheckEnglish
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
263 CheckRunVimInTerminal
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
264
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
265 " First read the file into a buffer
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
266 call writefile(["Line1", "Line2"], 'Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
267 let old_ftime = getftime('Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
268 let buf = RunVimInTerminal('Xfile', #{rows : 10})
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
269 call term_wait(buf)
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
270 call term_sendkeys(buf, ":set noswapfile\<CR>")
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
271 call term_wait(buf)
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
272
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
273 " Modify the file directly. Make sure the file modification time is
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
274 " different. Note that on Linux/Unix, the file is considered modified
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
275 " outside, only if the difference is 2 seconds or more
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
276 sleep 1
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
277 call writefile(["Line3", "Line4"], 'Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
278 let new_ftime = getftime('Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
279 while new_ftime - old_ftime < 2
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
280 sleep 100m
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
281 call writefile(["Line3", "Line4"], 'Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
282 let new_ftime = getftime('Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
283 endwhile
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
284
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
285 " Try to overwrite the file and check for the prompt
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
286 call term_sendkeys(buf, ":w\<CR>")
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
287 call term_wait(buf)
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
288 call WaitForAssert({-> assert_equal("WARNING: The file has been changed since reading it!!!", term_getline(buf, 9))})
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
289 call assert_equal("Do you really want to write to it (y/n)?",
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
290 \ term_getline(buf, 10))
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
291 call term_sendkeys(buf, "n\<CR>")
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
292 call term_wait(buf)
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
293 call assert_equal(new_ftime, getftime('Xfile'))
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
294 call term_sendkeys(buf, ":w\<CR>")
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
295 call term_wait(buf)
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
296 call term_sendkeys(buf, "y\<CR>")
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
297 call term_wait(buf)
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
298 call WaitForAssert({-> assert_equal('Line2', readfile('Xfile')[1])})
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
299
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
300 " clean up
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
301 call StopVimInTerminal(buf)
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
302 call delete('Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
303 endfunc
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
304
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
305 " Test for an autocmd unloading a buffer during a write command
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
306 func Test_write_autocmd_unloadbuf_lockmark()
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
307 augroup WriteTest
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
308 autocmd BufWritePre Xfile enew | write
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
309 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
310 e Xfile
21265
6a4806e326dd patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents: 20861
diff changeset
311 call assert_fails('lockmarks write', ['E32', 'E203:'])
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
312 augroup WriteTest
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
313 au!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
314 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
315 augroup! WriteTest
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
316 endfunc
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
317
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
318 " Test for writing a buffer with 'acwrite' but without autocmds
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
319 func Test_write_acwrite_error()
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
320 new Xfile
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
321 call setline(1, ['line1', 'line2', 'line3'])
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
322 set buftype=acwrite
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
323 call assert_fails('write', 'E676:')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
324 call assert_fails('1,2write!', 'E676:')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
325 call assert_fails('w >>', 'E676:')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
326 close!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
327 endfunc
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
328
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
329 " Test for adding and removing lines from an autocmd when writing a buffer
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
330 func Test_write_autocmd_add_remove_lines()
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
331 new Xfile
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
332 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd'])
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
333
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
334 " Autocmd deleting lines from the file when writing a partial file
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
335 augroup WriteTest2
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
336 au!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
337 autocmd FileWritePre Xfile 1,2d
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
338 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
339 call assert_fails('2,3w!', 'E204:')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
340
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
341 " Autocmd adding lines to a file when writing a partial file
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
342 augroup WriteTest2
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
343 au!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
344 autocmd FileWritePre Xfile call append(0, ['xxx', 'yyy'])
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
345 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
346 %d
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
347 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd'])
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
348 1,2w!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
349 call assert_equal(['xxx', 'yyy', 'aaa', 'bbb'], readfile('Xfile'))
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
350
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
351 " Autocmd deleting lines from the file when writing the whole file
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
352 augroup WriteTest2
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
353 au!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
354 autocmd BufWritePre Xfile 1,2d
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
355 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
356 %d
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
357 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd'])
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
358 w
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
359 call assert_equal(['ccc', 'ddd'], readfile('Xfile'))
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
360
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
361 augroup WriteTest2
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
362 au!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
363 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
364 augroup! WriteTest2
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
365
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
366 close!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
367 call delete('Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
368 endfunc
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
369
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
370 " Test for writing to a readonly file
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
371 func Test_write_readonly()
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
372 call writefile([], 'Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
373 call setfperm('Xfile', "r--------")
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
374 edit Xfile
21580
93dae47699fb patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 21532
diff changeset
375 set noreadonly backupskip=
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
376 call assert_fails('write', 'E505:')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
377 let save_cpo = &cpo
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
378 set cpo+=W
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
379 call assert_fails('write!', 'E504:')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
380 let &cpo = save_cpo
20812
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
381 call setline(1, ['line1'])
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
382 write!
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
383 call assert_equal(['line1'], readfile('Xfile'))
21580
93dae47699fb patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 21532
diff changeset
384 set backupskip&
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
385 call delete('Xfile')
19231
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
386 endfunc
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
387
20812
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
388 " Test for 'patchmode'
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
389 func Test_patchmode()
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
390 call writefile(['one'], 'Xfile')
21580
93dae47699fb patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 21532
diff changeset
391 set patchmode=.orig nobackup backupskip= writebackup
20812
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
392 new Xfile
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
393 call setline(1, 'two')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
394 " first write should create the .orig file
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
395 write
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
396 call assert_equal(['one'], readfile('Xfile.orig'))
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
397 call setline(1, 'three')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
398 " subsequent writes should not create/modify the .orig file
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
399 write
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
400 call assert_equal(['one'], readfile('Xfile.orig'))
21580
93dae47699fb patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 21532
diff changeset
401 set patchmode& backup& backupskip& writebackup&
20812
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
402 call delete('Xfile')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
403 call delete('Xfile.orig')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
404 endfunc
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
405
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
406 " Test for writing to a file in a readonly directory
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
407 func Test_write_readonly_dir()
21580
93dae47699fb patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 21532
diff changeset
408 " On MS-Windows, modifying files in a read-only directory is allowed.
93dae47699fb patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 21532
diff changeset
409 CheckUnix
20812
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
410 call mkdir('Xdir')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
411 call writefile(['one'], 'Xdir/Xfile1')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
412 call setfperm('Xdir', 'r-xr--r--')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
413 " try to create a new file in the directory
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
414 new Xdir/Xfile2
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
415 call setline(1, 'two')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
416 call assert_fails('write', 'E212:')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
417 " try to create a backup file in the directory
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
418 edit! Xdir/Xfile1
21580
93dae47699fb patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 21532
diff changeset
419 set backupdir=./Xdir backupskip=
20812
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
420 set patchmode=.orig
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
421 call assert_fails('write', 'E509:')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
422 call setfperm('Xdir', 'rwxr--r--')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
423 call delete('Xdir', 'rf')
21580
93dae47699fb patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 21532
diff changeset
424 set backupdir& backupskip& patchmode&
20812
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
425 endfunc
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
426
20861
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
427 " Test for writing a file using invalid file encoding
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
428 func Test_write_invalid_encoding()
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
429 new
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
430 call setline(1, 'abc')
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
431 call assert_fails('write ++enc=axbyc Xfile', 'E213:')
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
432 close!
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
433 endfunc
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
434
21510
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
435 " Tests for reading and writing files with conversion for Win32.
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
436 func Test_write_file_encoding()
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
437 CheckMSWindows
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
438 let save_encoding = &encoding
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
439 let save_fileencodings = &fileencodings
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
440 set encoding& fileencodings&
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
441 let text =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
442 1 utf-8 text: Ð”Ð»Ñ Vim version 6.2. ПоÑледнее изменение: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
443 2 cp1251 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
444 3 cp866 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
445 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
446 call writefile(text, 'Xfile')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
447 edit Xfile
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
448
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
449 " write tests:
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
450 " combine three values for 'encoding' with three values for 'fileencoding'
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
451 " also write files for read tests
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
452 call cursor(1, 1)
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
453 set encoding=utf-8
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
454 .w! ++enc=utf-8 Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
455 .w ++enc=cp1251 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
456 .w ++enc=cp866 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
457 .w! ++enc=utf-8 Xutf8
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
458 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
459 1 utf-8 text: Ð”Ð»Ñ Vim version 6.2. ПоÑледнее изменение: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
460 1 utf-8 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
461 1 utf-8 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
462 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
463 call assert_equal(expected, readfile('Xtest'))
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
464
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
465 call cursor(2, 1)
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
466 set encoding=cp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
467 .w! ++enc=utf-8 Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
468 .w ++enc=cp1251 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
469 .w ++enc=cp866 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
470 .w! ++enc=cp1251 Xcp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
471 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
472 2 cp1251 text: Ð”Ð»Ñ Vim version 6.2. ПоÑледнее изменение: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
473 2 cp1251 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
474 2 cp1251 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
475 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
476 call assert_equal(expected, readfile('Xtest'))
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
477
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
478 call cursor(3, 1)
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
479 set encoding=cp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
480 .w! ++enc=utf-8 Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
481 .w ++enc=cp1251 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
482 .w ++enc=cp866 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
483 .w! ++enc=cp866 Xcp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
484 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
485 3 cp866 text: Ð”Ð»Ñ Vim version 6.2. ПоÑледнее изменение: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
486 3 cp866 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
487 3 cp866 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
488 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
489 call assert_equal(expected, readfile('Xtest'))
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
490
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
491 " read three 'fileencoding's with utf-8 'encoding'
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
492 set encoding=utf-8 fencs=utf-8,cp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
493 e Xutf8
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
494 .w! ++enc=utf-8 Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
495 e Xcp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
496 .w ++enc=utf-8 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
497 set fencs=utf-8,cp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
498 e Xcp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
499 .w ++enc=utf-8 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
500 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
501 1 utf-8 text: Ð”Ð»Ñ Vim version 6.2. ПоÑледнее изменение: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
502 2 cp1251 text: Ð”Ð»Ñ Vim version 6.2. ПоÑледнее изменение: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
503 3 cp866 text: Ð”Ð»Ñ Vim version 6.2. ПоÑледнее изменение: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
504 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
505 call assert_equal(expected, readfile('Xtest'))
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
506
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
507 " read three 'fileencoding's with cp1251 'encoding'
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
508 set encoding=utf-8 fencs=utf-8,cp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
509 e Xutf8
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
510 .w! ++enc=cp1251 Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
511 e Xcp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
512 .w ++enc=cp1251 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
513 set fencs=utf-8,cp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
514 e Xcp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
515 .w ++enc=cp1251 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
516 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
517 1 utf-8 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
518 2 cp1251 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
519 3 cp866 text: Äëÿ Vim version 6.2. Ïîñëåäíåå èçìåíåíèå: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
520 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
521 call assert_equal(expected, readfile('Xtest'))
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
522
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
523 " read three 'fileencoding's with cp866 'encoding'
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
524 set encoding=cp866 fencs=utf-8,cp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
525 e Xutf8
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
526 .w! ++enc=cp866 Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
527 e Xcp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
528 .w ++enc=cp866 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
529 set fencs=utf-8,cp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
530 e Xcp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
531 .w ++enc=cp866 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
532 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
533 1 utf-8 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
534 2 cp1251 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
535 3 cp866 text: „«ï Vim version 6.2. ®á«¥¤­¥¥ ¨§¬¥­¥­¨¥: 1970 Jan 01
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
536 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
537 call assert_equal(expected, readfile('Xtest'))
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
538
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
539 call delete('Xfile')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
540 call delete('Xtest')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
541 call delete('Xutf8')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
542 call delete('Xcp1251')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
543 call delete('Xcp866')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
544 let &encoding = save_encoding
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
545 let &fileencodings = save_fileencodings
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
546 %bw!
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
547 endfunc
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
548
21532
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
549 " Test for writing and reading a file starting with a BOM.
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
550 " Byte Order Mark (BOM) character for various encodings is below:
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
551 " UTF-8 : EF BB BF
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
552 " UTF-16 (BE): FE FF
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
553 " UTF-16 (LE): FF FE
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
554 " UTF-32 (BE): 00 00 FE FF
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
555 " UTF-32 (LE): FF FE 00 00
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
556 func Test_readwrite_file_with_bom()
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
557 let utf8_bom = "\xEF\xBB\xBF"
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
558 let utf16be_bom = "\xFE\xFF"
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
559 let utf16le_bom = "\xFF\xFE"
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
560 let utf32be_bom = "\n\n\xFE\xFF"
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
561 let utf32le_bom = "\xFF\xFE\n\n"
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
562 let save_fileencoding = &fileencoding
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
563 set cpoptions+=S
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
564
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
565 " Check that editing a latin1 file doesn't see a BOM
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
566 call writefile(["\xFE\xFElatin-1"], 'Xtest1')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
567 edit Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
568 call assert_equal('latin1', &fileencoding)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
569 call assert_equal(0, &bomb)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
570 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
571 write Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
572 call assert_equal(["\xFE\xFElatin-1", ''], readfile('Xfile2', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
573 set bomb fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
574 write Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
575 call assert_equal(["\xFE\xFElatin-1", ''], readfile('Xtest3', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
576 set bomb&
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
577
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
578 " Check utf-8 BOM
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
579 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
580 call writefile([utf8_bom .. "utf-8"], 'Xtest1')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
581 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
582 call assert_equal('utf-8', &fileencoding)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
583 call assert_equal(1, &bomb)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
584 call assert_equal('utf-8', getline(1))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
585 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
586 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
587 call assert_equal(['utf-8', ''], readfile('Xfile2', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
588 set fenc=utf-8
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
589 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
590 call assert_equal([utf8_bom .. "utf-8", ''], readfile('Xtest3', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
591
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
592 " Check utf-8 with an error (will fall back to latin-1)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
593 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
594 call writefile([utf8_bom .. "utf-8\x80err"], 'Xtest1')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
595 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
596 call assert_equal('latin1', &fileencoding)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
597 call assert_equal(0, &bomb)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
598 call assert_equal("\xC3\xAF\xC2\xBB\xC2\xBFutf-8\xC2\x80err", getline(1))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
599 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
600 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
601 call assert_equal([utf8_bom .. "utf-8\x80err", ''], readfile('Xfile2', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
602 set fenc=utf-8
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
603 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
604 call assert_equal(["\xC3\xAF\xC2\xBB\xC2\xBFutf-8\xC2\x80err", ''],
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
605 \ readfile('Xtest3', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
606
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
607 " Check ucs-2 BOM
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
608 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
609 call writefile([utf16be_bom .. "\nu\nc\ns\n-\n2\n"], 'Xtest1')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
610 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
611 call assert_equal('utf-16', &fileencoding)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
612 call assert_equal(1, &bomb)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
613 call assert_equal('ucs-2', getline(1))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
614 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
615 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
616 call assert_equal(["ucs-2", ''], readfile('Xfile2', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
617 set fenc=ucs-2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
618 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
619 call assert_equal([utf16be_bom .. "\nu\nc\ns\n-\n2\n", ''],
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
620 \ readfile('Xtest3', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
621
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
622 " Check ucs-2le BOM
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
623 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
624 call writefile([utf16le_bom .. "u\nc\ns\n-\n2\nl\ne\n"], 'Xtest1')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
625 " Need to add a NUL byte after the NL byte
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
626 call writefile(0z00, 'Xtest1', 'a')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
627 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
628 call assert_equal('utf-16le', &fileencoding)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
629 call assert_equal(1, &bomb)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
630 call assert_equal('ucs-2le', getline(1))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
631 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
632 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
633 call assert_equal(["ucs-2le", ''], readfile('Xfile2', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
634 set fenc=ucs-2le
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
635 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
636 call assert_equal([utf16le_bom .. "u\nc\ns\n-\n2\nl\ne\n", "\n"],
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
637 \ readfile('Xtest3', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
638
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
639 " Check ucs-4 BOM
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
640 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
641 call writefile([utf32be_bom .. "\n\n\nu\n\n\nc\n\n\ns\n\n\n-\n\n\n4\n\n\n"], 'Xtest1')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
642 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
643 call assert_equal('ucs-4', &fileencoding)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
644 call assert_equal(1, &bomb)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
645 call assert_equal('ucs-4', getline(1))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
646 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
647 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
648 call assert_equal(["ucs-4", ''], readfile('Xfile2', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
649 set fenc=ucs-4
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
650 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
651 call assert_equal([utf32be_bom .. "\n\n\nu\n\n\nc\n\n\ns\n\n\n-\n\n\n4\n\n\n", ''], readfile('Xtest3', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
652
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
653 " Check ucs-4le BOM
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
654 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
655 call writefile([utf32le_bom .. "u\n\n\nc\n\n\ns\n\n\n-\n\n\n4\n\n\nl\n\n\ne\n\n\n"], 'Xtest1')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
656 " Need to add three NUL bytes after the NL byte
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
657 call writefile(0z000000, 'Xtest1', 'a')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
658 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
659 call assert_equal('ucs-4le', &fileencoding)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
660 call assert_equal(1, &bomb)
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
661 call assert_equal('ucs-4le', getline(1))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
662 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
663 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
664 call assert_equal(["ucs-4le", ''], readfile('Xfile2', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
665 set fenc=ucs-4le
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
666 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
667 call assert_equal([utf32le_bom .. "u\n\n\nc\n\n\ns\n\n\n-\n\n\n4\n\n\nl\n\n\ne\n\n\n", "\n\n\n"], readfile('Xtest3', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
668
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
669 set cpoptions-=S
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
670 let &fileencoding = save_fileencoding
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
671 call delete('Xtest1')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
672 call delete('Xtest2')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
673 call delete('Xtest3')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
674 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
675 endfunc
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
676
19231
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
677 " vim: shiftwidth=2 sts=2 expandtab