Mercurial > vim
annotate src/testdir/test_writefile.vim @ 33776:9503dc55b5ed v9.0.2108
patch 9.0.2108: [security]: overflow with count for :s command
Commit: https://github.com/vim/vim/commit/ac63787734fda2e294e477af52b3bd601517fa78
Author: Christian Brabandt <cb@256bit.org>
Date: Tue Nov 14 20:45:48 2023 +0100
patch 9.0.2108: [security]: overflow with count for :s command
Problem: [security]: overflow with count for :s command
Solution: Abort the :s command if the count is too large
If the count after the :s command is larger than what fits into a
(signed) long variable, abort with e_value_too_large.
Adds a test with INT_MAX as count and verify it correctly fails.
It seems the return value on Windows using mingw compiler wraps around,
so the initial test using :s/./b/9999999999999999999999999990 doesn't
fail there, since the count is wrapping around several times and finally
is no longer larger than 2147483647. So let's just use 2147483647 in the
test, which hopefully will always cause a failure
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 16 Nov 2023 22:15:10 +0100 |
parents | f79c9a5a1753 |
children |
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() |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
8 call writefile(["over", "written"], f, "bD") |
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
9 call writefile(["hello", "world"], f, "b") |
10068
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]) |
19695
1697a25328fd
patch 8.2.0404: writefile() error does not give a hint
Bram Moolenaar <Bram@vim.org>
parents:
19425
diff
changeset
|
19 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
20 call assert_fails('call writefile("text", "Xwffile")', '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
|
21 endfunc |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
22 |
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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 |
11519
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
28 func Test_writefile_fails_gently() |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
29 call assert_fails('call writefile(["test"], "Xwffile", [])', 'E730:') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
30 call assert_false(filereadable("Xwffile")) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
31 call delete("Xwffile") |
11519
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
32 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
33 call assert_fails('call writefile(["test", [], [], [], "tset"], "Xwffile")', 'E730:') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
34 call assert_false(filereadable("Xwffile")) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
35 call delete("Xwffile") |
11519
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
36 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
37 call assert_fails('call writefile([], "Xwffile", [])', 'E730:') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
38 call assert_false(filereadable("Xwffile")) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
39 call delete("Xwffile") |
11519
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
40 |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
41 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
|
42 endfunc |
11605
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
43 |
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
44 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
|
45 CheckFeature iconv |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21580
diff
changeset
|
46 if has('sun') |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21580
diff
changeset
|
47 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
|
48 endif |
16694
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
49 " Without a backup file the write won't happen if there is a conversion |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
50 " error. |
16869
e264d45f268a
patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents:
16694
diff
changeset
|
51 set nobackup nowritebackup backupdir=. backupskip= |
11605
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
52 new |
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
53 let contents = ["line one", "line two"] |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
54 call writefile(contents, 'Xwfcfile', 'D') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
55 edit Xwfcfile |
11605
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
56 call setline(1, ["first line", "cannot convert \u010b", "third line"]) |
16694
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
57 call assert_fails('write ++enc=cp932', 'E513:') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
58 call assert_equal(contents, readfile('Xwfcfile')) |
11605
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
59 |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
60 " 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
|
61 " still created. |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
62 set backupcopy=yes writebackup& backup& |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
63 call delete('Xwfcfile' .. &backupext) |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
64 call assert_fails('write ++enc=cp932', 'E513:') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
65 call assert_equal(contents, readfile('Xwfcfile')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
66 call assert_equal(contents, readfile('Xwfcfile' .. &backupext)) |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
67 set backupcopy& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
68 %bw! |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
69 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
70 " Conversion error during write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
71 new |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
72 call setline(1, ["\U10000000"]) |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
73 let output = execute('write! ++enc=utf-16 Xwfcfile') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
74 call assert_match('CONVERSION ERROR', output) |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
75 let output = execute('write! ++enc=ucs-2 Xwfcfile') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
76 call assert_match('CONVERSION ERROR', output) |
30090
bd62c3173f72
patch 9.0.0381: writefile test leaves files behind
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
77 call delete('Xwfcfilz~') |
bd62c3173f72
patch 9.0.0381: writefile test leaves files behind
Bram Moolenaar <Bram@vim.org>
parents:
30083
diff
changeset
|
78 call delete('Xwfcfily~') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
79 %bw! |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
80 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
81 call delete('Xwfcfile' .. &backupext) |
11605
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
82 bwipe! |
16869
e264d45f268a
patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents:
16694
diff
changeset
|
83 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
|
84 endfunc |
12624
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
85 |
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
|
86 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
|
87 CheckFeature iconv |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21580
diff
changeset
|
88 if has('sun') |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
21580
diff
changeset
|
89 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
|
90 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
|
91 " 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
|
92 " 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
|
93 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
|
94 let contents = ["line one", "line two"] |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
95 call writefile(contents, 'Xwf2file_conversion_err', 'D') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
96 edit Xwf2file_conversion_err |
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
|
97 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
|
98 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
|
99 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
|
100 call assert_match('CONVERSION ERROR', output) |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
101 call assert_equal(contents, readfile('Xwf2file_conversion_err~')) |
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
|
102 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
103 call delete('Xwf2file_conversion_err~') |
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
|
104 bwipe! |
16869
e264d45f268a
patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents:
16694
diff
changeset
|
105 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
|
106 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
|
107 |
12624
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
108 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
|
109 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
|
110 endfunc |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
111 |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
112 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
|
113 " 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
|
114 augroup testgroup |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
115 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
|
116 augroup END |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
117 e! Xwqsfile |
12624
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
118 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
|
119 wq |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
120 |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
121 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
|
122 " 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
|
123 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
|
124 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
|
125 sleep 50m |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
126 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
|
127 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
|
128 endif |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
129 au! testgroup |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
130 bwipe Xwqsfile |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
131 call delete('Xwqsfile') |
12624
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
132 endfunc |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
133 |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
134 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
|
135 " Prevent exiting by opening a help window. |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
136 e! Xnqsfile |
12624
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
137 help |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
138 wincmd w |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
139 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
|
140 |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
141 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
|
142 " 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
|
143 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
|
144 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
|
145 sleep 50m |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
146 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
|
147 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
|
148 endif |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
149 bwipe Xnqsfile |
12624
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
150 endfunc |
12857
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
151 |
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
152 func Test_writefile_sync_arg() |
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
153 " This doesn't check if fsync() works, only that the argument is accepted. |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
154 call writefile(['one'], 'Xtest', 'sD') |
12857
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
155 call writefile(['two'], 'Xtest', 'S') |
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
156 endfunc |
12926
98503d690368
patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents:
12857
diff
changeset
|
157 |
98503d690368
patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents:
12857
diff
changeset
|
158 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
|
159 CheckUnix |
13744
d6553cde1292
patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents:
12926
diff
changeset
|
160 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
|
161 " 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
|
162 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
|
163 else |
d6553cde1292
patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents:
12926
diff
changeset
|
164 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
|
165 endif |
12926
98503d690368
patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents:
12857
diff
changeset
|
166 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
|
167 |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 |
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 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
|
180 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_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
|
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 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 |
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 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 " 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 |
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 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
|
203 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
|
204 endfunc |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
205 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
206 " 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
|
207 " command. |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
208 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
|
209 CheckUnix |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
210 new |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
211 call setline(1, ['L1', 'L2', 'L3', 'L4']) |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
212 2,3w !cat > Xptfile |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
213 call assert_equal(['L2', 'L3'], readfile('Xptfile')) |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
214 close! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
215 call delete('Xptfile') |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
216 endfunc |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
217 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
218 " Test for :saveas |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
219 func Test_saveas() |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
220 call assert_fails('saveas', 'E471:') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
221 call writefile(['L1'], 'Xsafile') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
222 new Xsafile |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
223 new |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
224 call setline(1, ['L1']) |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
225 call assert_fails('saveas Xsafile', 'E139:') |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
226 close! |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
227 enew | only |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
228 call delete('Xsafile') |
25569
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
229 |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
230 " :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
|
231 syntax on |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
232 saveas! Xsaveas.pl |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
233 call assert_equal('perl', &filetype) |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
234 syntax off |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
235 %bw! |
8e9886ce88b3
patch 8.2.3321: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
24747
diff
changeset
|
236 call delete('Xsaveas.pl') |
30347
ea2935ec4435
patch 9.0.0509: confusing error for "saveas" command with "nofile" buffer
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
237 |
ea2935ec4435
patch 9.0.0509: confusing error for "saveas" command with "nofile" buffer
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
238 " :saveas fails for "nofile" buffer |
ea2935ec4435
patch 9.0.0509: confusing error for "saveas" command with "nofile" buffer
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
239 set buftype=nofile |
ea2935ec4435
patch 9.0.0509: confusing error for "saveas" command with "nofile" buffer
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
240 call assert_fails('saveas Xsafile', 'E676: No matching autocommands for buftype=nofile buffer') |
ea2935ec4435
patch 9.0.0509: confusing error for "saveas" command with "nofile" buffer
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
241 |
ea2935ec4435
patch 9.0.0509: confusing error for "saveas" command with "nofile" buffer
Bram Moolenaar <Bram@vim.org>
parents:
30150
diff
changeset
|
242 bwipe! |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
243 endfunc |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
244 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
245 func Test_write_errors() |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
246 " Test for writing partial buffer |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
247 call writefile(['L1', 'L2', 'L3'], 'Xwefile') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
248 new Xwefile |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
249 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
|
250 close! |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
251 |
19384
6c944fee0d7e
patch 8.2.0250: test_clear_search_pat() is unused
Bram Moolenaar <Bram@vim.org>
parents:
19277
diff
changeset
|
252 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
|
253 |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
254 " Try to overwrite a directory |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
255 if has('unix') |
29970
d891115c0aea
patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
256 call mkdir('Xwerdir1') |
d891115c0aea
patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
257 call assert_fails('write Xwerdir1', 'E17:') |
d891115c0aea
patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
258 call delete('Xwerdir1', 'd') |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
259 endif |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
260 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
261 " 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
|
262 enew | only |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
263 call setline(1, ['L1']) |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
264 call assert_fails('wall', 'E141:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
265 enew! |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
266 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
267 " Test for writing a 'readonly' file |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
268 new Xwefile |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
269 set readonly |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
270 call assert_fails('write', 'E45:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
271 close |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
272 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
273 " Test for writing to a read-only file |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
274 new Xwefile |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
275 call setfperm('Xwefile', 'r--r--r--') |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
276 call assert_fails('write', 'E505:') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
277 call setfperm('Xwefile', 'rw-rw-rw-') |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
278 close |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
279 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
280 call delete('Xwefile') |
20178
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19695
diff
changeset
|
281 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
282 call writefile(test_null_list(), 'Xwefile') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
283 call assert_false(filereadable('Xwefile')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
284 call writefile(test_null_blob(), 'Xwefile') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
285 call assert_false(filereadable('Xwefile')) |
20178
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19695
diff
changeset
|
286 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
|
287 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
288 " very long file name |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
293 " 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
|
294 if has('unix') && getfperm('/dev/loop0') != '' |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
295 \ && getftype('/dev/loop0') == 'bdev' && !IsRoot() |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
296 new |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
297 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
|
298 call assert_fails('write', 'E503: ') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
299 call assert_fails('write!', 'E503: ') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
300 close! |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
301 endif |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
302 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
303 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
304 " 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
|
305 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
|
306 CheckEnglish |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
307 CheckRunVimInTerminal |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
308 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
309 " First read the file into a buffer |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
310 call writefile(["Line1", "Line2"], 'Xwfmfile', 'D') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
311 let old_ftime = getftime('Xwfmfile') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
312 let buf = RunVimInTerminal('Xwfmfile', #{rows : 10}) |
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 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
|
315 call TermWait(buf) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
316 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
317 " 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
|
318 " 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
|
319 " 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
|
320 sleep 1 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
321 call writefile(["Line3", "Line4"], 'Xwfmfile') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
322 let new_ftime = getftime('Xwfmfile') |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
323 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
|
324 sleep 100m |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
325 call writefile(["Line3", "Line4"], 'Xwfmfile') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
326 let new_ftime = getftime('Xwfmfile') |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
327 endwhile |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
328 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
329 " 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
|
330 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
|
331 call TermWait(buf) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
332 call WaitForAssert({-> assert_equal("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
|
333 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
|
334 \ term_getline(buf, 10)) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
335 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
|
336 call TermWait(buf) |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
337 call assert_equal(new_ftime, getftime('Xwfmfile')) |
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, ":w\<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 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
|
341 call TermWait(buf) |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
342 call WaitForAssert({-> assert_equal('Line2', readfile('Xwfmfile')[1])}) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
343 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
344 " clean up |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
345 call StopVimInTerminal(buf) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
346 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
347 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
348 " 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
|
349 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
|
350 augroup WriteTest |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
351 autocmd BufWritePre Xwaufile enew | write |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
352 augroup END |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
353 e Xwaufile |
22087
ff21e2962490
patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents:
21897
diff
changeset
|
354 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
|
355 augroup WriteTest |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
356 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
357 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
358 augroup! WriteTest |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
359 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
360 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
361 " 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
|
362 func Test_write_acwrite_error() |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
363 new Xwaefile |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
364 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
|
365 set buftype=acwrite |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
366 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
|
367 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
|
368 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
|
369 close! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
370 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
371 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
372 " 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
|
373 func Test_write_autocmd_add_remove_lines() |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
374 new Xwaafile |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
375 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
|
376 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
377 " 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
|
378 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
379 au! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
380 autocmd FileWritePre Xwaafile 1,2d |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
381 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
382 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
|
383 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
384 " 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
|
385 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
386 au! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
387 autocmd FileWritePre Xwaafile call append(0, ['xxx', 'yyy']) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
388 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
389 %d |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
390 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
|
391 1,2w! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
392 call assert_equal(['xxx', 'yyy', 'aaa', 'bbb'], readfile('Xwaafile')) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
393 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
394 " 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
|
395 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
396 au! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
397 autocmd BufWritePre Xwaafile 1,2d |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
398 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
399 %d |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
400 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
|
401 w |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
402 call assert_equal(['ccc', 'ddd'], readfile('Xwaafile')) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
403 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
404 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
405 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
406 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
407 augroup! WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
408 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
409 close! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
410 call delete('Xwaafile') |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
411 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
412 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
413 " 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
|
414 func Test_write_readonly() |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
415 call writefile([], 'Xwrofile', 'D') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
416 call setfperm('Xwrofile', "r--------") |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
417 edit Xwrofile |
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
|
418 set noreadonly backupskip= |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
419 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
|
420 let save_cpo = &cpo |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
421 set cpo+=W |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
422 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
|
423 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
|
424 call setline(1, ['line1']) |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
425 write! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
426 call assert_equal(['line1'], readfile('Xwrofile')) |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
427 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
428 " 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
|
429 %bw! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
430 e Xwrofile |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
431 set noreadonly autowriteall |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
432 call setline(1, ['aaaa']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
433 call assert_fails('n', 'E505:') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
434 set cpo+=W |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
435 call assert_fails('n', 'E504:') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
436 set cpo-=W |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
437 set autowriteall& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
438 |
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
|
439 set backupskip& |
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() |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
445 call writefile(['one'], 'Xpafile', 'D') |
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 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
447 new Xpafile |
20812
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 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
451 call assert_equal(['one'], readfile('Xpafile.orig')) |
20812
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 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
455 call assert_equal(['one'], readfile('Xpafile.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 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
459 call delete('Xpafile') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
460 call delete('Xpafile.orig') |
24620
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 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
463 edit Xpafile |
24620
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 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
466 call assert_equal(['xxx'], readfile('Xpafile')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
467 call assert_equal([], readfile('Xpafile.orig')) |
24620
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& |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
470 call delete('Xpafile.orig') |
20812
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
471 endfunc |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
472 |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
473 " 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
|
474 " 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
|
475 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
|
476 " 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
|
477 CheckUnix |
24164
2259c73cc1d9
patch 8.2.2623: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
24057
diff
changeset
|
478 " 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
|
479 CheckNotRoot |
2259c73cc1d9
patch 8.2.2623: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
24057
diff
changeset
|
480 |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
481 call mkdir('Xrodir/', 'R') |
29970
d891115c0aea
patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
482 call writefile(['one'], 'Xrodir/Xfile1') |
d891115c0aea
patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
483 call setfperm('Xrodir', 'r-xr--r--') |
20812
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
484 " try to create a new file in the directory |
29970
d891115c0aea
patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
485 new Xrodir/Xfile2 |
20812
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
486 call setline(1, 'two') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
487 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
|
488 " try to create a backup file in the directory |
29970
d891115c0aea
patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
489 edit! Xrodir/Xfile1 |
d891115c0aea
patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
490 set backupdir=./Xrodir backupskip= |
20812
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
491 set patchmode=.orig |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
492 call assert_fails('write', 'E509:') |
29970
d891115c0aea
patch 9.0.0323: using common name in tests leads to flaky tests
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
493 call setfperm('Xrodir', 'rwxr--r--') |
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
|
494 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
|
495 endfunc |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
496 |
20861
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20812
diff
changeset
|
497 " 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
|
498 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
|
499 new |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20812
diff
changeset
|
500 call setline(1, 'abc') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
501 call assert_fails('write ++enc=axbyc Xiefile', 'E213:') |
20861
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20812
diff
changeset
|
502 close! |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20812
diff
changeset
|
503 endfunc |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20812
diff
changeset
|
504 |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
505 " 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
|
506 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
|
507 CheckMSWindows |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
508 let save_encoding = &encoding |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
509 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
|
510 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
|
511 let text =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
512 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
|
513 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
|
514 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
|
515 END |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
516 call writefile(text, 'Xwfefile', 'D') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
517 edit Xwfefile |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
518 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
519 " write tests: |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
520 " 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
|
521 " 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
|
522 call cursor(1, 1) |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
523 set encoding=utf-8 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
524 .w! ++enc=utf-8 Xwfetest |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
525 .w ++enc=cp1251 >> Xwfetest |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
526 .w ++enc=cp866 >> Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
527 .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
|
528 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
529 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
|
530 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
|
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 END |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
533 call assert_equal(expected, readfile('Xwfetest')) |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
534 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
535 call cursor(2, 1) |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
536 set encoding=cp1251 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
537 .w! ++enc=utf-8 Xwfetest |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
538 .w ++enc=cp1251 >> Xwfetest |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
539 .w ++enc=cp866 >> Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
540 .w! ++enc=cp1251 Xcp1251 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
541 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
542 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
|
543 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
|
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 END |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
546 call assert_equal(expected, readfile('Xwfetest')) |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
547 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
548 call cursor(3, 1) |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
549 set encoding=cp866 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
550 .w! ++enc=utf-8 Xwfetest |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
551 .w ++enc=cp1251 >> Xwfetest |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
552 .w ++enc=cp866 >> Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
553 .w! ++enc=cp866 Xcp866 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
554 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
555 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
|
556 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
|
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 END |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
559 call assert_equal(expected, readfile('Xwfetest')) |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
560 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
561 " 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
|
562 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
|
563 e Xutf8 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
564 .w! ++enc=utf-8 Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
565 e Xcp1251 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
566 .w ++enc=utf-8 >> Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
567 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
|
568 e Xcp866 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
569 .w ++enc=utf-8 >> Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
570 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
571 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
|
572 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
|
573 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
|
574 END |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
575 call assert_equal(expected, readfile('Xwfetest')) |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
576 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
577 " 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
|
578 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
|
579 e Xutf8 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
580 .w! ++enc=cp1251 Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
581 e Xcp1251 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
582 .w ++enc=cp1251 >> Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
583 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
|
584 e Xcp866 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
585 .w ++enc=cp1251 >> Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
586 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
587 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
|
588 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
|
589 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
|
590 END |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
591 call assert_equal(expected, readfile('Xwfetest')) |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
592 |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
593 " 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
|
594 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
|
595 e Xutf8 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
596 .w! ++enc=cp866 Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
597 e Xcp1251 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
598 .w ++enc=cp866 >> Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
599 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
|
600 e Xcp866 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
601 .w ++enc=cp866 >> Xwfetest |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
602 let expected =<< trim END |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
603 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
|
604 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
|
605 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
|
606 END |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
607 call assert_equal(expected, readfile('Xwfetest')) |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
608 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
609 call delete('Xwfetest') |
21510
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
610 call delete('Xutf8') |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
611 call delete('Xcp1251') |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
612 call delete('Xcp866') |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
613 let &encoding = save_encoding |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
614 let &fileencodings = save_fileencodings |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
615 %bw! |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
616 endfunc |
31cb78014fe4
patch 8.2.1305: some tests are still old style
Bram Moolenaar <Bram@vim.org>
parents:
21265
diff
changeset
|
617 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
618 " 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
|
619 " 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
|
620 " 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
|
621 " 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
|
622 " 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
|
623 " 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
|
624 " 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
|
625 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
|
626 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 let save_fileencoding = &fileencoding |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
632 set cpoptions+=S |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
633 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
634 " Check that editing a latin1 file doesn't see a BOM |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
635 call writefile(["\xFE\xFElatin-1"], 'Xrwtest1', 'D') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
636 edit Xrwtest1 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
637 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
|
638 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
|
639 set fenc=latin1 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
640 write Xrwfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
641 call assert_equal(["\xFE\xFElatin-1", ''], readfile('Xrwfile2', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
642 set bomb fenc=latin1 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
643 write Xrwtest3 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
644 call assert_equal(["\xFE\xFElatin-1", ''], readfile('Xrwtest3', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
645 set bomb& |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
646 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
647 " Check utf-8 BOM |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
648 %bw! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
649 call writefile([utf8_bom .. "utf-8"], 'Xrwtest1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
650 edit! Xrwtest1 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
651 call assert_equal('utf-8', &fileencoding) |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
652 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
|
653 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
|
654 set fenc=latin1 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
655 write! Xrwfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
656 call assert_equal(['utf-8', ''], readfile('Xrwfile2', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
657 set fenc=utf-8 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
658 w! Xrwtest3 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
659 call assert_equal([utf8_bom .. "utf-8", ''], readfile('Xrwtest3', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
660 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
661 " 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
|
662 %bw! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
663 call writefile([utf8_bom .. "utf-8\x80err"], 'Xrwtest1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
664 edit! Xrwtest1 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
665 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
|
666 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
|
667 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
|
668 set fenc=latin1 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
669 write! Xrwfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
670 call assert_equal([utf8_bom .. "utf-8\x80err", ''], readfile('Xrwfile2', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
671 set fenc=utf-8 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
672 w! Xrwtest3 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
673 call assert_equal(["\xC3\xAF\xC2\xBB\xC2\xBFutf-8\xC2\x80err", ''], |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
674 \ readfile('Xrwtest3', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
675 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
676 " Check ucs-2 BOM |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
677 %bw! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
678 call writefile([utf16be_bom .. "\nu\nc\ns\n-\n2\n"], 'Xrwtest1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
679 edit! Xrwtest1 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
680 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
|
681 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
|
682 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
|
683 set fenc=latin1 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
684 write! Xrwfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
685 call assert_equal(["ucs-2", ''], readfile('Xrwfile2', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
686 set fenc=ucs-2 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
687 w! Xrwtest3 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
688 call assert_equal([utf16be_bom .. "\nu\nc\ns\n-\n2\n", ''], |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
689 \ readfile('Xrwtest3', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
690 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
691 " Check ucs-2le BOM |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
692 %bw! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
693 call writefile([utf16le_bom .. "u\nc\ns\n-\n2\nl\ne\n"], 'Xrwtest1') |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
694 " Need to add a NUL byte after the NL byte |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
695 call writefile(0z00, 'Xrwtest1', 'a') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
696 edit! Xrwtest1 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
697 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
|
698 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
|
699 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
|
700 set fenc=latin1 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
701 write! Xrwfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
702 call assert_equal(["ucs-2le", ''], readfile('Xrwfile2', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
703 set fenc=ucs-2le |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
704 w! Xrwtest3 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
705 call assert_equal([utf16le_bom .. "u\nc\ns\n-\n2\nl\ne\n", "\n"], |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
706 \ readfile('Xrwtest3', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
707 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
708 " Check ucs-4 BOM |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
709 %bw! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
710 call writefile([utf32be_bom .. "\n\n\nu\n\n\nc\n\n\ns\n\n\n-\n\n\n4\n\n\n"], 'Xrwtest1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
711 edit! Xrwtest1 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
712 call assert_equal('ucs-4', &fileencoding) |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
713 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
|
714 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
|
715 set fenc=latin1 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
716 write! Xrwfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
717 call assert_equal(["ucs-4", ''], readfile('Xrwfile2', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
718 set fenc=ucs-4 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
719 w! Xrwtest3 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
720 call assert_equal([utf32be_bom .. "\n\n\nu\n\n\nc\n\n\ns\n\n\n-\n\n\n4\n\n\n", ''], readfile('Xrwtest3', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
721 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
722 " Check ucs-4le BOM |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
723 %bw! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
724 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"], 'Xrwtest1') |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
725 " Need to add three NUL bytes after the NL byte |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
726 call writefile(0z000000, 'Xrwtest1', 'a') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
727 edit! Xrwtest1 |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
728 call assert_equal('ucs-4le', &fileencoding) |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
729 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
|
730 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
|
731 set fenc=latin1 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
732 write! Xrwfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
733 call assert_equal(["ucs-4le", ''], readfile('Xrwfile2', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
734 set fenc=ucs-4le |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
735 w! Xrwtest3 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
736 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('Xrwtest3', 'b')) |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
737 |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
738 set cpoptions-=S |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
739 let &fileencoding = save_fileencoding |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
740 call delete('Xrwfile2') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
741 call delete('Xrwtest3') |
21532
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
742 %bw! |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
743 endfunc |
dc1c26547a42
patch 8.2.1316: test 42 is still old style
Bram Moolenaar <Bram@vim.org>
parents:
21510
diff
changeset
|
744 |
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
|
745 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
|
746 " write file missing EOL |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
747 call writefile(['noeol'], "XNoEolSetEol", 'bSD') |
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
|
748 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
|
749 |
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 " 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
|
751 set nofixeol |
7d09c9cdaab8
patch 8.2.2202: write file test still fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
23312
diff
changeset
|
752 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
|
753 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
|
754 |
4d6c1b17f66a
patch 8.2.2199: first write after setting 'eol' does not have NL added
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
755 " 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
|
756 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
|
757 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
|
758 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
|
759 |
24669
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
760 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
|
761 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
|
762 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
|
763 |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
764 " 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
|
765 func Test_backupcopy() |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
766 CheckUnix |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
767 set backupskip= |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
768 " 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
|
769 " should not break the link. |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
770 set backupcopy& |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
771 call writefile(['1111'], 'Xbcfile1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
772 silent !ln -s Xbcfile1 Xbcfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
773 new Xbcfile2 |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
774 call setline(1, ['2222']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
775 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
776 close |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
777 call assert_equal(['2222'], readfile('Xbcfile1')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
778 call assert_equal('Xbcfile1', resolve('Xbcfile2')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
779 call assert_equal('link', getftype('Xbcfile2')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
780 call delete('Xbcfile1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
781 call delete('Xbcfile2') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
782 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
783 " 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
|
784 " should break the link. |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
785 set backupcopy=yes,breaksymlink |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
786 call writefile(['1111'], 'Xbcfile1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
787 silent !ln -s Xbcfile1 Xbcfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
788 new Xbcfile2 |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
789 call setline(1, ['2222']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
790 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
791 close |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
792 call assert_equal(['1111'], readfile('Xbcfile1')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
793 call assert_equal(['2222'], readfile('Xbcfile2')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
794 call assert_equal('Xbcfile2', resolve('Xbcfile2')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
795 call assert_equal('file', getftype('Xbcfile2')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
796 call delete('Xbcfile1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
797 call delete('Xbcfile2') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
798 set backupcopy& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
799 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
800 " 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
|
801 " should not break the link. |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
802 set backupcopy& |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
803 call writefile(['1111'], 'Xbcfile1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
804 silent !ln Xbcfile1 Xbcfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
805 new Xbcfile2 |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
806 call setline(1, ['2222']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
807 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
808 close |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
809 call assert_equal(['2222'], readfile('Xbcfile1')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
810 call delete('Xbcfile1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
811 call delete('Xbcfile2') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
812 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
813 " 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
|
814 " should break the link. |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
815 set backupcopy=yes,breakhardlink |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
816 call writefile(['1111'], 'Xbcfile1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
817 silent !ln Xbcfile1 Xbcfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
818 new Xbcfile2 |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
819 call setline(1, ['2222']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
820 write |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
821 call assert_equal(['1111'], readfile('Xbcfile1')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
822 call assert_equal(['2222'], readfile('Xbcfile2')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
823 call delete('Xbcfile1') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
824 call delete('Xbcfile2') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
825 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
826 " 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
|
827 " 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
|
828 " 'no'. |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
829 %bw |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
830 call writefile(['aaaa'], 'Xbcfile') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
831 call writefile(['bbbb'], 'Xbcfile.bak') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
832 set backupcopy=yes backupext=.bak |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
833 new Xbcfile |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
834 call setline(1, ['cccc']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
835 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
836 close |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
837 call assert_equal(['cccc'], readfile('Xbcfile')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
838 call assert_equal(['bbbb'], readfile('Xbcfile.bak')) |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
839 set backupcopy=no backupext=.bak |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
840 new Xbcfile |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
841 call setline(1, ['dddd']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
842 write |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
843 close |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
844 call assert_equal(['dddd'], readfile('Xbcfile')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
845 call assert_equal(['bbbb'], readfile('Xbcfile.bak')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
846 call delete('Xbcfile') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
847 call delete('Xbcfile.bak') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
848 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
849 " 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
|
850 if has('unix') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
851 set writebackup backupcopy=yes nobackup |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
852 new |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
853 call setline(1, ['aaaa']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
854 let output = execute('write! /dev/null') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
855 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
|
856 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
857 set writebackup backupcopy=no nobackup |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
858 new |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
859 call setline(1, ['aaaa']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
860 let output = execute('write! /dev/null') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
861 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
|
862 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
863 set backup writebackup& backupcopy& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
864 new |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
865 call setline(1, ['aaaa']) |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
866 let output = execute('write! /dev/null') |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
867 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
|
868 close |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
869 endif |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
870 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
871 set backupcopy& backupskip& backupext& backup& |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
872 endfunc |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
873 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
874 " 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
|
875 func Test_write_utf16() |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
876 new |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
877 call setline(1, ["\U00010001"]) |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
878 write ++enc=utf-16 Xw16file |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
879 bw! |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
880 call assert_equal(0zD800DC01, readfile('Xw16file', 'B')[0:3]) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
881 call delete('Xw16file') |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
882 endfunc |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
883 |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
884 " 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
|
885 " 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
|
886 func Test_write_backup_symlink() |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
887 CheckUnix |
28081
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
25569
diff
changeset
|
888 call mkdir('Xbackup') |
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
25569
diff
changeset
|
889 let save_backupdir = &backupdir |
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
25569
diff
changeset
|
890 set backupdir=.,./Xbackup |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
891 call writefile(['1111'], 'Xwbsfile', 'D') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
892 silent !ln -s Xwbsfile Xwbsfile.bak |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
893 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
894 new Xwbsfile |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
895 set backup backupcopy=yes backupext=.bak |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
896 write |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
897 call assert_equal('link', getftype('Xwbsfile.bak')) |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
898 call assert_equal('Xwbsfile', resolve('Xwbsfile.bak')) |
28081
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
25569
diff
changeset
|
899 " backup file should be created in the 'backup' directory |
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
25569
diff
changeset
|
900 if !has('bsd') |
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
25569
diff
changeset
|
901 " This check fails on FreeBSD |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
902 call assert_true(filereadable('./Xbackup/Xwbsfile.bak')) |
28081
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
25569
diff
changeset
|
903 endif |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
904 set backup& backupcopy& backupext& |
28081
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
25569
diff
changeset
|
905 %bw |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
906 |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
907 call delete('Xwbsfile.bak') |
28081
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
25569
diff
changeset
|
908 call delete('Xbackup', 'rf') |
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
25569
diff
changeset
|
909 let &backupdir = save_backupdir |
24620
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
910 endfunc |
9f48b262539b
patch 8.2.2849: bufwrite not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
24164
diff
changeset
|
911 |
24669
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
912 " 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
|
913 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
|
914 " create a file without an eol/eof character |
30869
bff3fa5f4c74
patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
30347
diff
changeset
|
915 call writefile(0z616161, 'Xwbfile1', 'bD') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
916 new Xwbfile1 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
917 write ++bin Xwbfile2 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
918 write ++nobin Xwbfile3 |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
919 call assert_equal(0z616161, readblob('Xwbfile2')) |
24669
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
920 if has('win32') |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
921 call assert_equal(0z6161610D.0A, readblob('Xwbfile3')) |
24669
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
922 else |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
923 call assert_equal(0z6161610A, readblob('Xwbfile3')) |
24669
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
924 endif |
30051
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
925 call delete('Xwbfile2') |
13b02c1ea0f7
patch 9.0.0363: common names in test files causes tests to be flaky
Bram Moolenaar <Bram@vim.org>
parents:
29970
diff
changeset
|
926 call delete('Xwbfile3') |
24669
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
927 endfunc |
d7644bffe128
patch 8.2.2873: not enough tests for writing buffers
Bram Moolenaar <Bram@vim.org>
parents:
24634
diff
changeset
|
928 |
30083
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
929 func DoWriteDefer() |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
930 call writefile(['some text'], 'XdeferDelete', 'D') |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
931 call assert_equal(['some text'], readfile('XdeferDelete')) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
932 endfunc |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
933 |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
934 def DefWriteDefer() |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
935 writefile(['some text'], 'XdefdeferDelete', 'D') |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
936 assert_equal(['some text'], readfile('XdefdeferDelete')) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
937 enddef |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
938 |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
939 func Test_write_with_deferred_delete() |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
940 call DoWriteDefer() |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
941 call assert_equal('', glob('XdeferDelete')) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
942 call DefWriteDefer() |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
943 call assert_equal('', glob('XdefdeferDelete')) |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
944 endfunc |
a542dfb1c1a2
patch 9.0.0379: cleaning up after writefile() is a hassle
Bram Moolenaar <Bram@vim.org>
parents:
30051
diff
changeset
|
945 |
30150
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
946 func DoWriteFile() |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
947 call writefile(['text'], 'Xthefile', 'D') |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
948 cd .. |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
949 endfunc |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
950 |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
951 func Test_write_defer_delete_chdir() |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
952 let dir = getcwd() |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
953 call DoWriteFile() |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
954 call assert_notequal(dir, getcwd()) |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
955 call chdir(dir) |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
956 call assert_equal('', glob('Xthefile')) |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
957 endfunc |
0fe61fa4e5d1
patch 9.0.0411: only created files can be cleaned up with one call
Bram Moolenaar <Bram@vim.org>
parents:
30090
diff
changeset
|
958 |
24723
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
959 " 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
|
960 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
|
961 edit Xsomefile |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
962 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
|
963 split |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
964 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
|
965 augroup Testing |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
966 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
|
967 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
|
968 augroup END |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
969 wq |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
970 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
|
971 |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
972 augroup Testing |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
973 au! |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
974 augroup END |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
975 bwipe! |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
976 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
|
977 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
|
978 endfunc |
5194fba32954
patch 8.2.2900: QuitPre is triggered before :wq writes the file
Bram Moolenaar <Bram@vim.org>
parents:
24669
diff
changeset
|
979 |
33408
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
980 func Test_write_with_xattr_support() |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
981 CheckLinux |
33410
b14a47736a1c
patch 9.0.1963: Configure script may not detect xattr
Christian Brabandt <cb@256bit.org>
parents:
33408
diff
changeset
|
982 CheckFeature xattr |
33408
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
983 CheckExecutable setfattr |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
984 |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
985 let contents = ["file with xattrs", "line two"] |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
986 call writefile(contents, 'Xwattr.txt', 'D') |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
987 " write a couple of xattr |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
988 call system('setfattr -n user.cookie -v chocolate Xwattr.txt') |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
989 call system('setfattr -n user.frieda -v bar Xwattr.txt') |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
990 call system('setfattr -n user.empty Xwattr.txt') |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
991 |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
992 set backupcopy=no writebackup& backup& |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
993 sp Xwattr.txt |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
994 w |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
995 $r! getfattr -d % |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
996 let expected = ['file with xattrs', 'line two', '# file: Xwattr.txt', 'user.cookie="chocolate"', 'user.empty=""', 'user.frieda="bar"', ''] |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
997 call assert_equal(expected, getline(1,'$')) |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
998 |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
999 set backupcopy& |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
1000 bw! |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
1001 endfunc |
dcfbfe57141c
patch 9.0.1962: No support for writing extended attributes
Christian Brabandt <cb@256bit.org>
parents:
30869
diff
changeset
|
1002 |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
1003 " vim: shiftwidth=2 sts=2 expandtab |