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