annotate src/testdir/test_writefile.vim @ 24866:f1121eb17e14 v8.2.2971

patch 8.2.2971: cannot yank a block without trailing spaces Commit: https://github.com/vim/vim/commit/544a38e44db0f25ec4fa7a2a4666cf28a2336f33 Author: Christian Brabandt <cb@256bit.org> Date: Thu Jun 10 19:39:11 2021 +0200 patch 8.2.2971: cannot yank a block without trailing spaces Problem: Cannot yank a block without trailing spaces. Solution: Add the "zy" command. (Christian Brabandt, closes https://github.com/vim/vim/issues/8292)
author Bram Moolenaar <Bram@vim.org>
date Thu, 10 Jun 2021 19:45:02 +0200
parents 7da496081b91
children 8e9886ce88b3
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()
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21580
diff changeset
46 CheckFeature iconv
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21580
diff changeset
47 if has('sun')
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21580
diff changeset
48 throw 'Skipped: does not work on SunOS'
11605
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
49 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
50 " 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
51 " error.
16869
e264d45f268a patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents: 16694
diff changeset
52 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
53 new
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
54 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
55 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
56 edit Xfile
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
57 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
58 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
59 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
60
24620
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
61 " With 'backupcopy' set, if there is a conversion error, the backup file is
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
62 " still created.
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
63 set backupcopy=yes writebackup& backup&
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
64 call delete('Xfile' .. &backupext)
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
65 call assert_fails('write ++enc=cp932', 'E513:')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
66 call assert_equal(contents, readfile('Xfile'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
67 call assert_equal(contents, readfile('Xfile' .. &backupext))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
68 set backupcopy&
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
69 %bw!
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
70
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
71 " Conversion error during write
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
72 new
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
73 call setline(1, ["\U10000000"])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
74 let output = execute('write! ++enc=utf-16 Xfile')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
75 call assert_match('CONVERSION ERROR', output)
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
76 let output = execute('write! ++enc=ucs-2 Xfile')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
77 call assert_match('CONVERSION ERROR', output)
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
78 call delete('Xfilz~')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
79 call delete('Xfily~')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
80 %bw!
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
81
11605
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
82 call delete('Xfile')
24620
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
83 call delete('Xfile' .. &backupext)
11605
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
84 bwipe!
16869
e264d45f268a patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents: 16694
diff changeset
85 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
86 endfunc
12624
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
87
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
88 func Test_writefile_fails_conversion2()
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21580
diff changeset
89 CheckFeature iconv
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21580
diff changeset
90 if has('sun')
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 21580
diff changeset
91 throw 'Skipped: does not work on SunOS'
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
92 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
93 " 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
94 " 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
95 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
96 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
97 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
98 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
99 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
100 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
101 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
102 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
103 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
104
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
105 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
106 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
107 bwipe!
16869
e264d45f268a patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents: 16694
diff changeset
108 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
109 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
110
12624
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
111 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
112 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
113 endfunc
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
114
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
115 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
116 " 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
117 augroup testgroup
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
118 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
119 augroup END
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
120 e! Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
121 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
122 wq
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
123
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
124 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
125 " 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
126 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
127 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
128 sleep 50m
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
129 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
130 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
131 endif
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
132 au! testgroup
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
133 bwipe Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
134 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
135 endfunc
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
136
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
137 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
138 " 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
139 e! Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
140 help
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
141 wincmd w
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
142 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
143
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
144 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
145 " 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
146 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
147 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
148 sleep 50m
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
149 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
150 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
151 endif
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
152 bwipe Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
153 endfunc
12857
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
154
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
155 func Test_writefile_sync_arg()
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
156 " 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
157 call writefile(['one'], 'Xtest', 's')
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
158 call writefile(['two'], 'Xtest', 'S')
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
159 call delete('Xtest')
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
160 endfunc
12926
98503d690368 patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents: 12857
diff changeset
161
98503d690368 patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents: 12857
diff changeset
162 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
163 CheckUnix
13744
d6553cde1292 patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents: 12926
diff changeset
164 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
165 " 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
166 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
167 else
d6553cde1292 patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents: 12926
diff changeset
168 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
169 endif
12926
98503d690368 patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents: 12857
diff changeset
170 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
171
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 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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182
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 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
184 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
185 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
186
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
187 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
188 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
189 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
190 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
191 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
192
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 " 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
201 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
202 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
203 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
204 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
205
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
206 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
207 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
208 endfunc
19231
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
209
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
210 " 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
211 " command.
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
212 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
213 CheckUnix
19231
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
214 new
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
215 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
216 2,3w !cat > Xfile
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
217 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
218 close!
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
219 call delete('Xfile')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
220 endfunc
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
221
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
222 " Test for :saveas
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
223 func Test_saveas()
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
224 call assert_fails('saveas', 'E471:')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
225 call writefile(['L1'], 'Xfile')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
226 new Xfile
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
227 new
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
228 call setline(1, ['L1'])
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
229 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
230 close!
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
231 enew | only
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
232 call delete('Xfile')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
233 endfunc
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
234
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
235 func Test_write_errors()
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
236 " Test for writing partial buffer
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
237 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
238 new Xfile
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
239 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
240 close!
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
241
19384
6c944fee0d7e patch 8.2.0250: test_clear_search_pat() is unused
Bram Moolenaar <Bram@vim.org>
parents: 19277
diff changeset
242 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
243
19231
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
244 " Try to overwrite a directory
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
245 if has('unix')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
246 call mkdir('Xdir1')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
247 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
248 call delete('Xdir1', 'd')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
249 endif
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
250
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
251 " 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
252 enew | only
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
253 call setline(1, ['L1'])
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
254 call assert_fails('wall', 'E141:')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
255 enew!
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
256
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
257 " 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
258 new Xfile
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
259 set readonly
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
260 call assert_fails('write', 'E45:')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
261 close
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
262
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
263 " 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
264 new Xfile
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
265 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
266 call assert_fails('write', 'E505:')
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
267 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
268 close
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
269
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
270 call delete('Xfile')
20178
2fb397573541 patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents: 19695
diff changeset
271
2fb397573541 patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents: 19695
diff changeset
272 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
273 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
274 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
275 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
276 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
277
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
278 " very long file name
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
279 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
280 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
281 call assert_fails('call writefile([], long_fname)', 'E482:')
24620
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
282
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
283 " Test for writing to a block device on Unix-like systems
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
284 if has('unix') && getfperm('/dev/loop0') != ''
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
285 \ && getftype('/dev/loop0') == 'bdev' && !IsRoot()
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
286 new
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
287 edit /dev/loop0
24634
d3c4ecf67604 patch 8.2.2856: get readonly error for device that can't be written to
Bram Moolenaar <Bram@vim.org>
parents: 24620
diff changeset
288 call assert_fails('write', 'E503: ')
24620
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
289 call assert_fails('write!', 'E503: ')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
290 close!
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
291 endif
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
292 endfunc
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
293
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
294 " 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
295 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
296 CheckEnglish
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
297 CheckRunVimInTerminal
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
298
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
299 " 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
300 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
301 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
302 let buf = RunVimInTerminal('Xfile', #{rows : 10})
21897
e0af4660dfc7 patch 8.2.1498: on slow systems tests can be flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
303 call TermWait(buf)
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
304 call term_sendkeys(buf, ":set noswapfile\<CR>")
21897
e0af4660dfc7 patch 8.2.1498: on slow systems tests can be flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
305 call TermWait(buf)
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
306
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
307 " 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
308 " 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
309 " 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
310 sleep 1
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
311 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
312 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
313 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
314 sleep 100m
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
315 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
316 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
317 endwhile
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
318
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
319 " 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
320 call term_sendkeys(buf, ":w\<CR>")
21897
e0af4660dfc7 patch 8.2.1498: on slow systems tests can be flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
321 call TermWait(buf)
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
322 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
323 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
324 \ term_getline(buf, 10))
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
325 call term_sendkeys(buf, "n\<CR>")
21897
e0af4660dfc7 patch 8.2.1498: on slow systems tests can be flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
326 call TermWait(buf)
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
327 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
328 call term_sendkeys(buf, ":w\<CR>")
21897
e0af4660dfc7 patch 8.2.1498: on slow systems tests can be flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
329 call TermWait(buf)
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
330 call term_sendkeys(buf, "y\<CR>")
21897
e0af4660dfc7 patch 8.2.1498: on slow systems tests can be flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
331 call TermWait(buf)
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
332 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
333
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
334 " clean up
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
335 call StopVimInTerminal(buf)
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
336 call delete('Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
337 endfunc
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
338
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
339 " 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
340 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
341 augroup WriteTest
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
342 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
343 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
344 e Xfile
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21897
diff changeset
345 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
346 augroup WriteTest
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
347 au!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
348 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
349 augroup! WriteTest
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
350 endfunc
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
351
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
352 " 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
353 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
354 new Xfile
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
355 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
356 set buftype=acwrite
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
357 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
358 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
359 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
360 close!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
361 endfunc
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
362
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
363 " 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
364 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
365 new Xfile
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
366 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
367
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
368 " 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
369 augroup WriteTest2
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
370 au!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
371 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
372 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
373 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
374
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
375 " 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
376 augroup WriteTest2
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
377 au!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
378 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
379 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
380 %d
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
381 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
382 1,2w!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
383 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
384
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
385 " 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
386 augroup WriteTest2
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
387 au!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
388 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
389 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
390 %d
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
391 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
392 w
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
393 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
394
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
395 augroup WriteTest2
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
396 au!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
397 augroup END
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
398 augroup! WriteTest2
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
399
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
400 close!
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
401 call delete('Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
402 endfunc
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
403
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
404 " 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
405 func Test_write_readonly()
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
406 call writefile([], 'Xfile')
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
407 call setfperm('Xfile', "r--------")
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
408 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
409 set noreadonly backupskip=
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
410 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
411 let save_cpo = &cpo
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
412 set cpo+=W
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
413 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
414 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
415 call setline(1, ['line1'])
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
416 write!
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
417 call assert_equal(['line1'], readfile('Xfile'))
24620
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
418
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
419 " Auto-saving a readonly file should fail with 'autowriteall'
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
420 %bw!
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
421 e Xfile
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
422 set noreadonly autowriteall
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
423 call setline(1, ['aaaa'])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
424 call assert_fails('n', 'E505:')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
425 set cpo+=W
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
426 call assert_fails('n', 'E504:')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
427 set cpo-=W
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
428 set autowriteall&
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
429
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
430 set backupskip&
20625
116c7bd5e980 patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
431 call delete('Xfile')
24620
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
432 %bw!
19231
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
433 endfunc
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
434
20812
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
435 " Test for 'patchmode'
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
436 func Test_patchmode()
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
437 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
438 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
439 new Xfile
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
440 call setline(1, 'two')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
441 " 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
442 write
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
443 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
444 call setline(1, 'three')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
445 " 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
446 write
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
447 call assert_equal(['one'], readfile('Xfile.orig'))
24620
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
448
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
449 " use 'patchmode' with 'nobackup' and 'nowritebackup' to create an empty
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
450 " original file
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
451 call delete('Xfile')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
452 call delete('Xfile.orig')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
453 %bw!
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
454 set patchmode=.orig nobackup nowritebackup
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
455 edit Xfile
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
456 call setline(1, ['xxx'])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
457 write
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
458 call assert_equal(['xxx'], readfile('Xfile'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
459 call assert_equal([], readfile('Xfile.orig'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
460
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
461 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
462 call delete('Xfile')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
463 call delete('Xfile.orig')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
464 endfunc
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
465
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
466 " Test for writing to a file in a readonly directory
24057
eeb5518a37aa patch 8.2.2570: tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 23314
diff changeset
467 " NOTE: if you run tests as root this will fail. Don't run tests as root!
20812
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
468 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
469 " 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
470 CheckUnix
24164
2259c73cc1d9 patch 8.2.2623: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 24057
diff changeset
471 " Root can do it too.
2259c73cc1d9 patch 8.2.2623: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 24057
diff changeset
472 CheckNotRoot
2259c73cc1d9 patch 8.2.2623: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents: 24057
diff changeset
473
24669
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
474 call mkdir('Xdir/')
20812
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
475 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
476 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
477 " 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
478 new Xdir/Xfile2
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
479 call setline(1, 'two')
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
480 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
481 " 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
482 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
483 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
484 set patchmode=.orig
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
485 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
486 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
487 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
488 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
489 endfunc
d8628d75c47a patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents: 20625
diff changeset
490
20861
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
491 " 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
492 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
493 new
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
494 call setline(1, 'abc')
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
495 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
496 close!
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
497 endfunc
1725bb56178a patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents: 20812
diff changeset
498
21510
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
499 " 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
500 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
501 CheckMSWindows
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
502 let save_encoding = &encoding
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
503 let save_fileencodings = &fileencodings
24747
7da496081b91 patch 8.2.2912: MS-Windows: most users expect using Unicode
Bram Moolenaar <Bram@vim.org>
parents: 24723
diff changeset
504 set encoding=latin1 fileencodings&
21510
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
505 let text =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
506 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
507 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
508 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
509 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
510 call writefile(text, 'Xfile')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
511 edit Xfile
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
512
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
513 " write tests:
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
514 " 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
515 " 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
516 call cursor(1, 1)
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
517 set encoding=utf-8
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
518 .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
519 .w ++enc=cp1251 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
520 .w ++enc=cp866 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
521 .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
522 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
523 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
524 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
525 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
526 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
527 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
528
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
529 call cursor(2, 1)
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
530 set encoding=cp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
531 .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
532 .w ++enc=cp1251 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
533 .w ++enc=cp866 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
534 .w! ++enc=cp1251 Xcp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
535 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
536 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
537 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
538 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
539 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
540 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
541
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
542 call cursor(3, 1)
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
543 set encoding=cp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
544 .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
545 .w ++enc=cp1251 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
546 .w ++enc=cp866 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
547 .w! ++enc=cp866 Xcp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
548 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
549 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
550 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
551 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
552 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
553 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
554
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
555 " 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
556 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
557 e Xutf8
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
558 .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
559 e Xcp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
560 .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
561 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
562 e Xcp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
563 .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
564 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
565 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
566 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
567 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
568 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
569 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
570
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
571 " 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
572 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
573 e Xutf8
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
574 .w! ++enc=cp1251 Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
575 e Xcp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
576 .w ++enc=cp1251 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
577 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
578 e Xcp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
579 .w ++enc=cp1251 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
580 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
581 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
582 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
583 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
584 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
585 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
586
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
587 " 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
588 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
589 e Xutf8
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
590 .w! ++enc=cp866 Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
591 e Xcp1251
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
592 .w ++enc=cp866 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
593 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
594 e Xcp866
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
595 .w ++enc=cp866 >> Xtest
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
596 let expected =<< trim END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
597 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
598 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
599 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
600 END
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
601 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
602
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
603 call delete('Xfile')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
604 call delete('Xtest')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
605 call delete('Xutf8')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
606 call delete('Xcp1251')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
607 call delete('Xcp866')
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
608 let &encoding = save_encoding
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
609 let &fileencodings = save_fileencodings
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
610 %bw!
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
611 endfunc
31cb78014fe4 patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
612
21532
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
613 " 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
614 " 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
615 " 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
616 " 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
617 " 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
618 " 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
619 " 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
620 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
621 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
622 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
623 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
624 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
625 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
626 let save_fileencoding = &fileencoding
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
627 set cpoptions+=S
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
628
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
629 " 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
630 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
631 edit Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
632 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
633 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
634 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
635 write Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
636 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
637 set bomb fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
638 write Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
639 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
640 set bomb&
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
641
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
642 " Check utf-8 BOM
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
643 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
644 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
645 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
646 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
647 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
648 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
649 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
650 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
651 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
652 set fenc=utf-8
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
653 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
654 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
655
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
656 " 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
657 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
658 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
659 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
660 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
661 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
662 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
663 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
664 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
665 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
666 set fenc=utf-8
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
667 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
668 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
669 \ readfile('Xtest3', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
670
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
671 " Check ucs-2 BOM
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
672 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
673 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
674 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
675 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
676 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
677 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
678 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
679 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
680 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
681 set fenc=ucs-2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
682 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
683 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
684 \ readfile('Xtest3', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
685
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
686 " Check ucs-2le BOM
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
687 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
688 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
689 " 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
690 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
691 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
692 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
693 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
694 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
695 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
696 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
697 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
698 set fenc=ucs-2le
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
699 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
700 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
701 \ readfile('Xtest3', 'b'))
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
702
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
703 " Check ucs-4 BOM
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
704 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
705 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
706 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
707 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
708 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
709 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
710 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
711 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
712 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
713 set fenc=ucs-4
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
714 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
715 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
716
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
717 " Check ucs-4le BOM
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
718 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
719 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
720 " 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
721 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
722 edit! Xtest1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
723 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
724 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
725 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
726 set fenc=latin1
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
727 write! Xfile2
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
728 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
729 set fenc=ucs-4le
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
730 w! Xtest3
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
731 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
732
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
733 set cpoptions-=S
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
734 let &fileencoding = save_fileencoding
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
735 call delete('Xtest1')
21897
e0af4660dfc7 patch 8.2.1498: on slow systems tests can be flaky
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
736 call delete('Xfile2')
21532
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
737 call delete('Xtest3')
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
738 %bw!
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
739 endfunc
dc1c26547a42 patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents: 21510
diff changeset
740
23308
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
741 func Test_read_write_bin()
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
742 " write file missing EOL
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
743 call writefile(['noeol'], "XNoEolSetEol", 'bS')
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
744 call assert_equal(0z6E6F656F6C, readfile('XNoEolSetEol', 'B'))
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
745
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
746 " when file is read 'eol' is off
23314
7d09c9cdaab8 patch 8.2.2202: write file test still fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 23312
diff changeset
747 set nofixeol
7d09c9cdaab8 patch 8.2.2202: write file test still fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 23312
diff changeset
748 e! ++ff=unix XNoEolSetEol
23308
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
749 call assert_equal(0, &eol)
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
750
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
751 " writing with 'eol' set adds the newline
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
752 setlocal eol
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
753 w
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
754 call assert_equal(0z6E6F656F6C0A, readfile('XNoEolSetEol', 'B'))
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
755
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
756 call delete('XNoEolSetEol')
24669
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
757 set ff& fixeol&
23312
4841385b981a patch 8.2.2201: write file test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 23308
diff changeset
758 bwipe! XNoEolSetEol
23308
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
759 endfunc
4d6c1b17f66a patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
760
24620
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
761 " Test for the 'backupcopy' option when writing files
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
762 func Test_backupcopy()
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
763 CheckUnix
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
764 set backupskip=
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
765 " With the default 'backupcopy' setting, saving a symbolic link file
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
766 " should not break the link.
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
767 set backupcopy&
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
768 call writefile(['1111'], 'Xfile1')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
769 silent !ln -s Xfile1 Xfile2
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
770 new Xfile2
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
771 call setline(1, ['2222'])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
772 write
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
773 close
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
774 call assert_equal(['2222'], readfile('Xfile1'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
775 call assert_equal('Xfile1', resolve('Xfile2'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
776 call assert_equal('link', getftype('Xfile2'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
777 call delete('Xfile1')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
778 call delete('Xfile2')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
779
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
780 " With the 'backupcopy' set to 'breaksymlink', saving a symbolic link file
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
781 " should break the link.
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
782 set backupcopy=yes,breaksymlink
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
783 call writefile(['1111'], 'Xfile1')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
784 silent !ln -s Xfile1 Xfile2
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
785 new Xfile2
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
786 call setline(1, ['2222'])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
787 write
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
788 close
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
789 call assert_equal(['1111'], readfile('Xfile1'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
790 call assert_equal(['2222'], readfile('Xfile2'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
791 call assert_equal('Xfile2', resolve('Xfile2'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
792 call assert_equal('file', getftype('Xfile2'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
793 call delete('Xfile1')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
794 call delete('Xfile2')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
795 set backupcopy&
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
796
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
797 " With the default 'backupcopy' setting, saving a hard link file
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
798 " should not break the link.
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
799 set backupcopy&
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
800 call writefile(['1111'], 'Xfile1')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
801 silent !ln Xfile1 Xfile2
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
802 new Xfile2
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
803 call setline(1, ['2222'])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
804 write
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
805 close
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
806 call assert_equal(['2222'], readfile('Xfile1'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
807 call delete('Xfile1')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
808 call delete('Xfile2')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
809
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
810 " With the 'backupcopy' set to 'breaksymlink', saving a hard link file
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
811 " should break the link.
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
812 set backupcopy=yes,breakhardlink
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
813 call writefile(['1111'], 'Xfile1')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
814 silent !ln Xfile1 Xfile2
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
815 new Xfile2
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
816 call setline(1, ['2222'])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
817 write
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
818 call assert_equal(['1111'], readfile('Xfile1'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
819 call assert_equal(['2222'], readfile('Xfile2'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
820 call delete('Xfile1')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
821 call delete('Xfile2')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
822
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
823 " If a backup file is already present, then a slightly modified filename
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
824 " should be used as the backup file. Try with 'backupcopy' set to 'yes' and
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
825 " 'no'.
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
826 %bw
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
827 call writefile(['aaaa'], 'Xfile')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
828 call writefile(['bbbb'], 'Xfile.bak')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
829 set backupcopy=yes backupext=.bak
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
830 new Xfile
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
831 call setline(1, ['cccc'])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
832 write
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
833 close
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
834 call assert_equal(['cccc'], readfile('Xfile'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
835 call assert_equal(['bbbb'], readfile('Xfile.bak'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
836 set backupcopy=no backupext=.bak
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
837 new Xfile
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
838 call setline(1, ['dddd'])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
839 write
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
840 close
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
841 call assert_equal(['dddd'], readfile('Xfile'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
842 call assert_equal(['bbbb'], readfile('Xfile.bak'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
843 call delete('Xfile')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
844 call delete('Xfile.bak')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
845
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
846 " Write to a device file (in Unix-like systems) which cannot be backed up.
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
847 if has('unix')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
848 set writebackup backupcopy=yes nobackup
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
849 new
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
850 call setline(1, ['aaaa'])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
851 let output = execute('write! /dev/null')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
852 call assert_match('"/dev/null" \[Device]', output)
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
853 close
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
854 set writebackup backupcopy=no nobackup
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
855 new
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
856 call setline(1, ['aaaa'])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
857 let output = execute('write! /dev/null')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
858 call assert_match('"/dev/null" \[Device]', output)
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
859 close
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
860 set backup writebackup& backupcopy&
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
861 new
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
862 call setline(1, ['aaaa'])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
863 let output = execute('write! /dev/null')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
864 call assert_match('"/dev/null" \[Device]', output)
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
865 close
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
866 endif
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
867
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
868 set backupcopy& backupskip& backupext& backup&
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
869 endfunc
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
870
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
871 " Test for writing a file with 'encoding' set to 'utf-16'
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
872 func Test_write_utf16()
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
873 new
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
874 call setline(1, ["\U00010001"])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
875 write ++enc=utf-16 Xfile
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
876 bw!
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
877 call assert_equal(0zD800DC01, readfile('Xfile', 'B')[0:3])
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
878 call delete('Xfile')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
879 endfunc
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
880
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
881 " Test for trying to save a backup file when the backup file is a symbolic
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
882 " link to the original file. The backup file should not be modified.
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
883 func Test_write_backup_symlink()
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
884 CheckUnix
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
885 call writefile(['1111'], 'Xfile')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
886 silent !ln -s Xfile Xfile.bak
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
887
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
888 new Xfile
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
889 set backup backupcopy=yes backupext=.bak
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
890 write
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
891 call assert_equal('link', getftype('Xfile.bak'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
892 call assert_equal('Xfile', resolve('Xfile.bak'))
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
893 set backup& backupcopy& backupext&
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
894 close
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
895
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
896 call delete('Xfile')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
897 call delete('Xfile.bak')
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
898 endfunc
9f48b262539b patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 24164
diff changeset
899
24669
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
900 " Test for ':write ++bin' and ':write ++nobin'
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
901 func Test_write_binary_file()
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
902 " create a file without an eol/eof character
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
903 call writefile(0z616161, 'Xfile1', 'b')
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
904 new Xfile1
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
905 write ++bin Xfile2
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
906 write ++nobin Xfile3
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
907 call assert_equal(0z616161, readblob('Xfile2'))
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
908 if has('win32')
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
909 call assert_equal(0z6161610D.0A, readblob('Xfile3'))
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
910 else
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
911 call assert_equal(0z6161610A, readblob('Xfile3'))
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
912 endif
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
913 call delete('Xfile1')
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
914 call delete('Xfile2')
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
915 call delete('Xfile3')
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
916 endfunc
d7644bffe128 patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents: 24634
diff changeset
917
24723
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
918 " Check that buffer is written before triggering QuitPre
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
919 func Test_wq_quitpre_autocommand()
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
920 edit Xsomefile
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
921 call setline(1, 'hello')
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
922 split
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
923 let g:seq = []
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
924 augroup Testing
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
925 au QuitPre * call add(g:seq, 'QuitPre - ' .. (&modified ? 'modified' : 'not modified'))
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
926 au BufWritePost * call add(g:seq, 'written')
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
927 augroup END
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
928 wq
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
929 call assert_equal(['written', 'QuitPre - not modified'], g:seq)
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
930
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
931 augroup Testing
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
932 au!
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
933 augroup END
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
934 bwipe!
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
935 unlet g:seq
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
936 call delete('Xsomefile')
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
937 endfunc
5194fba32954 patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents: 24669
diff changeset
938
19231
b8fd7364befd patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents: 18386
diff changeset
939 " vim: shiftwidth=2 sts=2 expandtab