Mercurial > vim
annotate src/testdir/test_writefile.vim @ 27740:2bd27d5ffbef v8.2.4396
patch 8.2.4396: Python3 test fails
Commit: https://github.com/vim/vim/commit/f5288c589500de0677444af4a428cfbccfccb8ce
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 15 21:33:29 2022 +0000
patch 8.2.4396: Python3 test fails
Problem: Python3 test fails.
Solution: Remove "let".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 15 Feb 2022 22:45:03 +0100 |
parents | 8e9886ce88b3 |
children | b737bfa876c5 |
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') |
25569
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
233 |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
234 " :saveas should detect and set the file type. |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
235 syntax on |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
236 saveas! Xsaveas.pl |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
237 call assert_equal('perl', &filetype) |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
238 syntax off |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
239 %bw! |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
240 call delete('Xsaveas.pl') |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
241 endfunc |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
242 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
243 func Test_write_errors() |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
244 " Test for writing partial buffer |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
245 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
|
246 new Xfile |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
247 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
|
248 close! |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
249 |
19384
6c944fee0d7e
patch 8.2.0250: test_clear_search_pat() is unused
Bram Moolenaar <Bram@vim.org>
parents:
19277
diff
changeset
|
250 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
|
251 |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
252 " Try to overwrite a directory |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
253 if has('unix') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
254 call mkdir('Xdir1') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
255 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
|
256 call delete('Xdir1', 'd') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
257 endif |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
258 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
259 " 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
|
260 enew | only |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
261 call setline(1, ['L1']) |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
262 call assert_fails('wall', 'E141:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
263 enew! |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
264 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
265 " 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
|
266 new Xfile |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
267 set readonly |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
268 call assert_fails('write', 'E45:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
269 close |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
270 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
271 " 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
|
272 new Xfile |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
273 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
|
274 call assert_fails('write', 'E505:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
275 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
|
276 close |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
277 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
278 call delete('Xfile') |
20178
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19695
diff
changeset
|
279 |
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19695
diff
changeset
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
286 " very long file name |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
287 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
|
288 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
|
289 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
|
290 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
291 " 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
|
292 if has('unix') && getfperm('/dev/loop0') != '' |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
293 \ && getftype('/dev/loop0') == 'bdev' && !IsRoot() |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
294 new |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
295 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
|
296 call assert_fails('write', 'E503: ') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
297 call assert_fails('write!', 'E503: ') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
298 close! |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
299 endif |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
300 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
301 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
302 " 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
|
303 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
|
304 CheckEnglish |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
305 CheckRunVimInTerminal |
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 " 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
|
308 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
|
309 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
|
310 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
|
311 call TermWait(buf) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
312 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
|
313 call TermWait(buf) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
314 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
315 " 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
|
316 " 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
|
317 " 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
|
318 sleep 1 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
319 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
|
320 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
|
321 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
|
322 sleep 100m |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
323 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
|
324 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
|
325 endwhile |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
326 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
327 " 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
|
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 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
|
331 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
|
332 \ term_getline(buf, 10)) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
333 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
|
334 call TermWait(buf) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
335 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
|
336 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
|
337 call TermWait(buf) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
338 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
|
339 call TermWait(buf) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
340 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
|
341 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
342 " clean up |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
343 call StopVimInTerminal(buf) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
344 call delete('Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
345 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
346 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
347 " 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
|
348 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
|
349 augroup WriteTest |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
350 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
|
351 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
352 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
|
353 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
|
354 augroup WriteTest |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
355 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
356 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
357 augroup! WriteTest |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
358 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
359 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
360 " 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
|
361 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
|
362 new Xfile |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
363 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
|
364 set buftype=acwrite |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
365 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
|
366 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
|
367 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
|
368 close! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
369 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
370 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
371 " 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
|
372 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
|
373 new Xfile |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
374 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
|
375 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
376 " 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
|
377 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
378 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
379 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
|
380 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
381 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
|
382 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
383 " 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
|
384 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
385 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
386 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
|
387 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
388 %d |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
389 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
|
390 1,2w! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
391 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
|
392 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
393 " 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
|
394 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
395 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
396 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
|
397 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
398 %d |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
399 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
|
400 w |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
401 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
|
402 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
403 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
404 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
405 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
406 augroup! WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
407 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
408 close! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
409 call delete('Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
410 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
411 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
412 " 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
|
413 func Test_write_readonly() |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
414 call writefile([], 'Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
415 call setfperm('Xfile', "r--------") |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
416 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
|
417 set noreadonly backupskip= |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
418 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
|
419 let save_cpo = &cpo |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
420 set cpo+=W |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
421 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
|
422 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
|
423 call setline(1, ['line1']) |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
424 write! |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
425 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
|
426 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
427 " 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
|
428 %bw! |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
429 e Xfile |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
430 set noreadonly autowriteall |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
431 call setline(1, ['aaaa']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
432 call assert_fails('n', 'E505:') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
433 set cpo+=W |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
434 call assert_fails('n', 'E504:') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
435 set cpo-=W |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
436 set autowriteall& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
437 |
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 backupskip& |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
439 call delete('Xfile') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
440 %bw! |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
441 endfunc |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
442 |
20812
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
443 " Test for 'patchmode' |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
444 func Test_patchmode() |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
445 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
|
446 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
|
447 new Xfile |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
448 call setline(1, 'two') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
449 " 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
|
450 write |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
451 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
|
452 call setline(1, 'three') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
453 " 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
|
454 write |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
455 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
|
456 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
457 " 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
|
458 " original file |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
459 call delete('Xfile') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
460 call delete('Xfile.orig') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
461 %bw! |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
462 set patchmode=.orig nobackup nowritebackup |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
463 edit Xfile |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
464 call setline(1, ['xxx']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
465 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
466 call assert_equal(['xxx'], readfile('Xfile')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
467 call assert_equal([], readfile('Xfile.orig')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
468 |
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 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
|
470 call delete('Xfile') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
471 call delete('Xfile.orig') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
472 endfunc |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
473 |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
474 " 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
|
475 " 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
|
476 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
|
477 " 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
|
478 CheckUnix |
24164
2259c73cc1d9
patch 8.2.2623: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
24057
diff
changeset
|
479 " 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
|
480 CheckNotRoot |
2259c73cc1d9
patch 8.2.2623: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
24057
diff
changeset
|
481 |
24669
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
482 call mkdir('Xdir/') |
20812
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
483 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
|
484 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
|
485 " 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
|
486 new Xdir/Xfile2 |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
487 call setline(1, 'two') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
488 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
|
489 " 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
|
490 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
|
491 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
|
492 set patchmode=.orig |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
493 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
|
494 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
|
495 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
|
496 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
|
497 endfunc |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
498 |
20861
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20812
diff
changeset
|
499 " 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
|
500 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
|
501 new |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20812
diff
changeset
|
502 call setline(1, 'abc') |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20812
diff
changeset
|
503 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
|
504 close! |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20812
diff
changeset
|
505 endfunc |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20812
diff
changeset
|
506 |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
507 " 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
|
508 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
|
509 CheckMSWindows |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
510 let save_encoding = &encoding |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
511 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
|
512 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
|
513 let text =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
514 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
|
515 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
|
516 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
|
517 END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
518 call writefile(text, 'Xfile') |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
519 edit Xfile |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
520 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
521 " write tests: |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
522 " 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
|
523 " 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
|
524 call cursor(1, 1) |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
525 set encoding=utf-8 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
526 .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
|
527 .w ++enc=cp1251 >> Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
528 .w ++enc=cp866 >> Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
529 .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
|
530 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
531 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
|
532 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
|
533 1 utf-8 text: „«ï Vim version 6.2. ®á«¥¤¥¥ ¨§¬¥¥¨¥: 1970 Jan 01 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
534 END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
535 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
|
536 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
537 call cursor(2, 1) |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
538 set encoding=cp1251 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
539 .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
|
540 .w ++enc=cp1251 >> Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
541 .w ++enc=cp866 >> Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
542 .w! ++enc=cp1251 Xcp1251 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
543 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
544 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
|
545 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
|
546 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
|
547 END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
548 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
|
549 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
550 call cursor(3, 1) |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
551 set encoding=cp866 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
552 .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
|
553 .w ++enc=cp1251 >> Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
554 .w ++enc=cp866 >> Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
555 .w! ++enc=cp866 Xcp866 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
556 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
557 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
|
558 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
|
559 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
|
560 END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
561 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
|
562 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
563 " 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
|
564 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
|
565 e Xutf8 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
566 .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
|
567 e Xcp1251 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
568 .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
|
569 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
|
570 e Xcp866 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
571 .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
|
572 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
573 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
|
574 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
|
575 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
|
576 END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
577 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
|
578 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
579 " 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
|
580 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
|
581 e Xutf8 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
582 .w! ++enc=cp1251 Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
583 e Xcp1251 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
584 .w ++enc=cp1251 >> Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
585 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
|
586 e Xcp866 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
587 .w ++enc=cp1251 >> Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
588 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
589 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
|
590 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
|
591 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
|
592 END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
593 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
|
594 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
595 " 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
|
596 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
|
597 e Xutf8 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
598 .w! ++enc=cp866 Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
599 e Xcp1251 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
600 .w ++enc=cp866 >> Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
601 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
|
602 e Xcp866 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
603 .w ++enc=cp866 >> Xtest |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
604 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
605 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
|
606 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
|
607 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
|
608 END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
609 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
|
610 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
611 call delete('Xfile') |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
612 call delete('Xtest') |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
613 call delete('Xutf8') |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
614 call delete('Xcp1251') |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
615 call delete('Xcp866') |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
616 let &encoding = save_encoding |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
617 let &fileencodings = save_fileencodings |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
618 %bw! |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
619 endfunc |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
620 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
621 " 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
|
622 " 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
|
623 " 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
|
624 " 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
|
625 " 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
|
626 " 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
|
627 " 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
|
628 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 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
|
634 let save_fileencoding = &fileencoding |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
635 set cpoptions+=S |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
636 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
637 " 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
|
638 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
|
639 edit Xtest1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
640 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
|
641 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
|
642 set fenc=latin1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
643 write Xfile2 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
644 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
|
645 set bomb fenc=latin1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
646 write Xtest3 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
647 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
|
648 set bomb& |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
649 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
650 " Check utf-8 BOM |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
651 %bw! |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
652 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
|
653 edit! Xtest1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 set fenc=latin1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
658 write! Xfile2 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
659 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
|
660 set fenc=utf-8 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
661 w! Xtest3 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
662 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
|
663 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
664 " 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
|
665 %bw! |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
666 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
|
667 edit! Xtest1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
668 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
|
669 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
|
670 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
|
671 set fenc=latin1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
672 write! Xfile2 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
673 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
|
674 set fenc=utf-8 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
675 w! Xtest3 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
676 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
|
677 \ readfile('Xtest3', 'b')) |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
678 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
679 " Check ucs-2 BOM |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
680 %bw! |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
681 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
|
682 edit! Xtest1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
683 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
|
684 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
|
685 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
|
686 set fenc=latin1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
687 write! Xfile2 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
688 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
|
689 set fenc=ucs-2 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
690 w! Xtest3 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
691 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
|
692 \ readfile('Xtest3', 'b')) |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
693 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
694 " Check ucs-2le BOM |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
695 %bw! |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
696 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
|
697 " 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
|
698 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
|
699 edit! Xtest1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
700 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
|
701 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
|
702 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
|
703 set fenc=latin1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
704 write! Xfile2 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
705 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
|
706 set fenc=ucs-2le |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
707 w! Xtest3 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
708 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
|
709 \ readfile('Xtest3', 'b')) |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
710 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
711 " Check ucs-4 BOM |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
712 %bw! |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
713 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
|
714 edit! Xtest1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
715 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
|
716 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
|
717 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
|
718 set fenc=latin1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
719 write! Xfile2 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
720 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
|
721 set fenc=ucs-4 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
722 w! Xtest3 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
723 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
|
724 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
725 " Check ucs-4le BOM |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
726 %bw! |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
727 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
|
728 " 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
|
729 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
|
730 edit! Xtest1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
731 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
|
732 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
|
733 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
|
734 set fenc=latin1 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
735 write! Xfile2 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
736 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
|
737 set fenc=ucs-4le |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
738 w! Xtest3 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
739 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
|
740 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
741 set cpoptions-=S |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
742 let &fileencoding = save_fileencoding |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
743 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
|
744 call delete('Xfile2') |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
745 call delete('Xtest3') |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
746 %bw! |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
747 endfunc |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
748 |
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 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
|
750 " 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
|
751 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
|
752 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
|
753 |
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 " 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
|
755 set nofixeol |
7d09c9cdaab8
patch 8.2.2202: write file test still fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
23312
diff
changeset
|
756 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
|
757 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
|
758 |
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 " 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
|
760 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
|
761 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
|
762 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
|
763 |
4d6c1b17f66a
patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
764 call delete('XNoEolSetEol') |
24669
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
765 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
|
766 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
|
767 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
|
768 |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
769 " 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
|
770 func Test_backupcopy() |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
771 CheckUnix |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
772 set backupskip= |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
773 " 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
|
774 " should not break the link. |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
775 set backupcopy& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
776 call writefile(['1111'], 'Xfile1') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
777 silent !ln -s Xfile1 Xfile2 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
778 new Xfile2 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
779 call setline(1, ['2222']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
780 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
781 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
782 call assert_equal(['2222'], readfile('Xfile1')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
783 call assert_equal('Xfile1', resolve('Xfile2')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
784 call assert_equal('link', getftype('Xfile2')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
785 call delete('Xfile1') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
786 call delete('Xfile2') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
787 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
788 " 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
|
789 " should break the link. |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
790 set backupcopy=yes,breaksymlink |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
791 call writefile(['1111'], 'Xfile1') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
792 silent !ln -s Xfile1 Xfile2 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
793 new Xfile2 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
794 call setline(1, ['2222']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
795 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
796 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
797 call assert_equal(['1111'], readfile('Xfile1')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
798 call assert_equal(['2222'], readfile('Xfile2')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
799 call assert_equal('Xfile2', resolve('Xfile2')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
800 call assert_equal('file', getftype('Xfile2')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
801 call delete('Xfile1') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
802 call delete('Xfile2') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
803 set backupcopy& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
804 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
805 " 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
|
806 " should not break the link. |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
807 set backupcopy& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
808 call writefile(['1111'], 'Xfile1') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
809 silent !ln Xfile1 Xfile2 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
810 new Xfile2 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
811 call setline(1, ['2222']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
812 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
813 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
814 call assert_equal(['2222'], readfile('Xfile1')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
815 call delete('Xfile1') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
816 call delete('Xfile2') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
817 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
818 " 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
|
819 " should break the link. |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
820 set backupcopy=yes,breakhardlink |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
821 call writefile(['1111'], 'Xfile1') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
822 silent !ln Xfile1 Xfile2 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
823 new Xfile2 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
824 call setline(1, ['2222']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
825 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
826 call assert_equal(['1111'], readfile('Xfile1')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
827 call assert_equal(['2222'], readfile('Xfile2')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
828 call delete('Xfile1') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
829 call delete('Xfile2') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
830 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
831 " 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
|
832 " 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
|
833 " 'no'. |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
834 %bw |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
835 call writefile(['aaaa'], 'Xfile') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
836 call writefile(['bbbb'], 'Xfile.bak') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
837 set backupcopy=yes backupext=.bak |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
838 new Xfile |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
839 call setline(1, ['cccc']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
840 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
841 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
842 call assert_equal(['cccc'], readfile('Xfile')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
843 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
|
844 set backupcopy=no backupext=.bak |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
845 new Xfile |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
846 call setline(1, ['dddd']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
847 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
848 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
849 call assert_equal(['dddd'], readfile('Xfile')) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
850 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
|
851 call delete('Xfile') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
852 call delete('Xfile.bak') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
853 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
854 " 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
|
855 if has('unix') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
856 set writebackup backupcopy=yes nobackup |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
857 new |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
858 call setline(1, ['aaaa']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
859 let output = execute('write! /dev/null') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
860 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
|
861 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
862 set writebackup backupcopy=no nobackup |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
863 new |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
864 call setline(1, ['aaaa']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
865 let output = execute('write! /dev/null') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
866 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
|
867 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
868 set backup writebackup& backupcopy& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
869 new |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
870 call setline(1, ['aaaa']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
871 let output = execute('write! /dev/null') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
872 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
|
873 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
874 endif |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
875 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
876 set backupcopy& backupskip& backupext& backup& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
877 endfunc |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
878 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
879 " 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
|
880 func Test_write_utf16() |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
881 new |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
882 call setline(1, ["\U00010001"]) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
883 write ++enc=utf-16 Xfile |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
884 bw! |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
885 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
|
886 call delete('Xfile') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
887 endfunc |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
888 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
889 " 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
|
890 " 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
|
891 func Test_write_backup_symlink() |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
892 CheckUnix |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
893 call writefile(['1111'], 'Xfile') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
894 silent !ln -s Xfile Xfile.bak |
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 new Xfile |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
897 set backup backupcopy=yes backupext=.bak |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
898 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
899 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
|
900 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
|
901 set backup& backupcopy& backupext& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
902 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
903 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
904 call delete('Xfile') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
905 call delete('Xfile.bak') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
906 endfunc |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
907 |
24669
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
908 " 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
|
909 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
|
910 " 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
|
911 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
|
912 new Xfile1 |
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
913 write ++bin Xfile2 |
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
914 write ++nobin Xfile3 |
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
915 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
|
916 if has('win32') |
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
917 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
|
918 else |
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
919 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
|
920 endif |
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
921 call delete('Xfile1') |
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
922 call delete('Xfile2') |
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
923 call delete('Xfile3') |
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
924 endfunc |
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
925 |
24723
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
926 " 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
|
927 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
|
928 edit Xsomefile |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
929 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
|
930 split |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
931 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
|
932 augroup Testing |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
933 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
|
934 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
|
935 augroup END |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
936 wq |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
937 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
|
938 |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
939 augroup Testing |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
940 au! |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
941 augroup END |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
942 bwipe! |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
943 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
|
944 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
|
945 endfunc |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
946 |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
947 " vim: shiftwidth=2 sts=2 expandtab |