blob: ed64dd79b73086505aec9a959e9a3cdc46e5e845 [file] [log] [blame]
Bram Moolenaar4a6fcf82017-10-12 21:29:22 +02001" Test for commands that close windows and/or buffers:
2" :quit
3" :close
4" :hide
5" :only
6" :sall
7" :all
8" :ball
9" :buf
10" :edit
11"
12func Test_winbuf_close()
13 enew | only
14
15 call writefile(['testtext 1'], 'Xtest1')
16 call writefile(['testtext 2'], 'Xtest2')
17 call writefile(['testtext 3'], 'Xtest3')
18
19 next! Xtest1 Xtest2
20 call setline(1, 'testtext 1 1')
21
22 " test for working :n when hidden set
23 set hidden
24 next
25 call assert_equal('Xtest2', bufname('%'))
26
27 " test for failing :rew when hidden not set
28 set nohidden
29 call setline(1, 'testtext 2 2')
30 call assert_fails('rewind', 'E37')
31 call assert_equal('Xtest2', bufname('%'))
32 call assert_equal('testtext 2 2', getline(1))
33
34 " test for working :rew when hidden set
35 set hidden
36 rewind
37 call assert_equal('Xtest1', bufname('%'))
38 call assert_equal('testtext 1 1', getline(1))
39
40 " test for :all keeping a buffer when it's modified
41 set nohidden
42 call setline(1, 'testtext 1 1 1')
43 split
44 next Xtest2 Xtest3
45 all
46 1wincmd w
47 call assert_equal('Xtest1', bufname('%'))
48 call assert_equal('testtext 1 1 1', getline(1))
49
50 " test abandoning changed buffer, should be unloaded even when 'hidden' set
51 set hidden
52 call setline(1, 'testtext 1 1 1 1')
53 quit!
54 call assert_equal('Xtest2', bufname('%'))
55 call assert_equal('testtext 2 2', getline(1))
56 unhide
57 call assert_equal('Xtest2', bufname('%'))
58 call assert_equal('testtext 2 2', getline(1))
59
60 " test ":hide" hides anyway when 'hidden' not set
61 set nohidden
62 call setline(1, 'testtext 2 2 2')
63 hide
64 call assert_equal('Xtest3', bufname('%'))
65 call assert_equal('testtext 3', getline(1))
66
67 " test ":edit" failing in modified buffer when 'hidden' not set
68 call setline(1, 'testtext 3 3')
69 call assert_fails('edit Xtest1', 'E37')
70 call assert_equal('Xtest3', bufname('%'))
71 call assert_equal('testtext 3 3', getline(1))
72
73 " test ":edit" working in modified buffer when 'hidden' set
74 set hidden
75 edit Xtest1
76 call assert_equal('Xtest1', bufname('%'))
77 call assert_equal('testtext 1', getline(1))
78
79 " test ":close" not hiding when 'hidden' not set in modified buffer
80 split Xtest3
81 set nohidden
82 call setline(1, 'testtext 3 3 3')
83 call assert_fails('close', 'E37')
84 call assert_equal('Xtest3', bufname('%'))
85 call assert_equal('testtext 3 3 3', getline(1))
86
87 " test ":close!" does hide when 'hidden' not set in modified buffer;
88 call setline(1, 'testtext 3 3 3 3')
89 close!
90 call assert_equal('Xtest1', bufname('%'))
91 call assert_equal('testtext 1', getline(1))
92
93 set nohidden
94
95 " test ":all!" hides changed buffer
96 split Xtest4
97 call setline(1, 'testtext 4')
98 all!
99 1wincmd w
100 call assert_equal('Xtest2', bufname('%'))
101 call assert_equal('testtext 2 2 2', getline(1))
102
103 " test ":q!" and hidden buffer.
104 bwipe! Xtest1 Xtest2 Xtest3 Xtest4
105 split Xtest1
106 wincmd w
107 bwipe!
108 set modified
109 bot split Xtest2
110 set modified
111 bot split Xtest3
112 set modified
113 wincmd t
114 hide
115 call assert_equal('Xtest2', bufname('%'))
116 quit!
117 call assert_equal('Xtest3', bufname('%'))
118 call assert_fails('silent! quit!', 'E162')
119 call assert_equal('Xtest1', bufname('%'))
120
121 call delete('Xtest1')
122 call delete('Xtest2')
123 call delete('Xtest3')
124endfunc