blob: b3ce39552395a751948831104672ac7df0227107 [file] [log] [blame]
Bram Moolenaar2256c992016-11-15 21:17:07 +01001" Tests for :hide command/modifier and 'hidden' option
2
Bram Moolenaarbfe13cc2020-04-12 17:53:12 +02003func SetUp()
Bram Moolenaar2256c992016-11-15 21:17:07 +01004 let s:save_hidden = &hidden
5 let s:save_bufhidden = &bufhidden
6 let s:save_autowrite = &autowrite
7 set nohidden
8 set bufhidden=
9 set noautowrite
10endfunc
11
12function TearDown()
13 let &hidden = s:save_hidden
14 let &bufhidden = s:save_bufhidden
15 let &autowrite = s:save_autowrite
16endfunc
17
18function Test_hide()
19 let orig_bname = bufname('')
20 let orig_winnr = winnr('$')
21
22 new Xf1
23 set modified
24 call assert_fails('edit Xf2')
25 bwipeout! Xf1
26
27 new Xf1
28 set modified
29 edit! Xf2
30 call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
31 call assert_equal([1, 0], [buflisted('Xf1'), bufloaded('Xf1')])
32 bwipeout! Xf1
33 bwipeout! Xf2
34
35 new Xf1
36 set modified
37 " :hide as a command
38 hide
39 call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')])
Bram Moolenaar073e4b92019-08-18 23:01:56 +020040 call assert_equal([1, 1], ['Xf1'->buflisted(), 'Xf1'->bufloaded()])
Bram Moolenaar2256c992016-11-15 21:17:07 +010041 bwipeout! Xf1
42
43 new Xf1
44 set modified
45 " :hide as a command with trailing comment
46 hide " comment
47 call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')])
48 call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
49 bwipeout! Xf1
50
51 new Xf1
52 set modified
53 " :hide as a command with bar
54 hide | new Xf2 " comment
55 call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
56 call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
57 bwipeout! Xf1
58 bwipeout! Xf2
59
60 new Xf1
61 set modified
62 " :hide as a modifier with trailing comment
63 hide edit Xf2 " comment
64 call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
65 call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
66 bwipeout! Xf1
67 bwipeout! Xf2
68
69 new Xf1
70 set modified
71 " To check that the bar is not recognized to separate commands
72 hide echo "one|two"
73 call assert_equal(['Xf1', 2], [bufname(''), winnr('$')])
74 call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
75 bwipeout! Xf1
76
77 " set hidden
78 new Xf1
79 set hidden
80 set modified
81 edit Xf2 " comment
82 call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
83 call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
84 bwipeout! Xf1
85 bwipeout! Xf2
86
87 " set hidden bufhidden=wipe
88 new Xf1
89 set bufhidden=wipe
90 set modified
91 hide edit! Xf2 " comment
92 call assert_equal(['Xf2', 2], [bufname(''), winnr('$')])
93 call assert_equal([0, 0], [buflisted('Xf1'), bufloaded('Xf1')])
94 bwipeout! Xf2
95endfunc
96
97" vim: shiftwidth=2 sts=2 expandtab