blob: cdf9fd314214e3d667b477dc5350c2b78ff5e8d0 [file] [log] [blame]
Bram Moolenaarded27822017-01-02 14:27:34 +01001" Test for folding
2
Bram Moolenaar1159b162017-02-28 21:53:56 +01003func! Test_address_fold()
Bram Moolenaarded27822017-01-02 14:27:34 +01004 new
5 call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
6 \ 'after fold 1', 'after fold 2', 'after fold 3'])
7 setl fen fdm=marker
8 " The next ccommands should all copy the same part of the buffer,
9 " regardless of the adressing type, since the part to be copied
10 " is folded away
11 :1y
12 call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
13 :.y
14 call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
15 :.+y
16 call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
17 :.,.y
18 call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
19 :sil .1,.y
20 call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
21 " use silent to make E493 go away
22 :sil .+,.y
23 call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
24 :,y
25 call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
26 :,+y
27 call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/','after fold 1'], getreg(0,1,1))
28 " using .+3 as second address should copy the whole folded line + the next 3
29 " lines
30 :.,+3y
31 call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/',
32 \ 'after fold 1', 'after fold 2', 'after fold 3'], getreg(0,1,1))
33 :sil .,-2y
34 call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1))
35
36 " now test again with folding disabled
37 set nofoldenable
38 :1y
39 call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
40 :.y
41 call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
42 :.+y
43 call assert_equal(['1'], getreg(0,1,1))
44 :.,.y
45 call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
46 " use silent to make E493 go away
47 :sil .1,.y
48 call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
49 " use silent to make E493 go away
50 :sil .+,.y
51 call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
52 :,y
53 call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1))
54 :,+y
55 call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1))
56 " using .+3 as second address should copy the whole folded line + the next 3
57 " lines
58 :.,+3y
59 call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3'], getreg(0,1,1))
60 :7
61 :sil .,-2y
62 call assert_equal(['4', '5', '}/*}}}*/'], getreg(0,1,1))
63
64 quit!
Bram Moolenaar1159b162017-02-28 21:53:56 +010065endfunc
Bram Moolenaar54b2bfa2017-01-02 14:57:08 +010066
Bram Moolenaar1159b162017-02-28 21:53:56 +010067func! Test_indent_fold()
Bram Moolenaar54b2bfa2017-01-02 14:57:08 +010068 new
69 call setline(1, ['', 'a', ' b', ' c'])
70 setl fen fdm=indent
71 2
72 norm! >>
73 let a=map(range(1,4), 'foldclosed(v:val)')
74 call assert_equal([-1,-1,-1,-1], a)
Bram Moolenaar1159b162017-02-28 21:53:56 +010075endfunc
Bram Moolenaar54b2bfa2017-01-02 14:57:08 +010076
Bram Moolenaar1159b162017-02-28 21:53:56 +010077func! Test_indent_fold()
Bram Moolenaar54b2bfa2017-01-02 14:57:08 +010078 new
79 call setline(1, ['', 'a', ' b', ' c'])
80 setl fen fdm=indent
81 2
82 norm! >>
83 let a=map(range(1,4), 'foldclosed(v:val)')
84 call assert_equal([-1,-1,-1,-1], a)
85 bw!
Bram Moolenaar1159b162017-02-28 21:53:56 +010086endfunc
Bram Moolenaar54b2bfa2017-01-02 14:57:08 +010087
Bram Moolenaar1159b162017-02-28 21:53:56 +010088func! Test_indent_fold2()
Bram Moolenaar54b2bfa2017-01-02 14:57:08 +010089 new
90 call setline(1, ['', '{{{', '}}}', '{{{', '}}}'])
91 setl fen fdm=marker
92 2
93 norm! >>
94 let a=map(range(1,5), 'foldclosed(v:val)')
95 call assert_equal([-1,-1,-1,4,4], a)
96 bw!
Bram Moolenaar1159b162017-02-28 21:53:56 +010097endfunc
98
99func Test_manual_fold_with_filter()
100 if !executable('cat')
101 return
102 endif
Bram Moolenaar3f3897e2017-03-04 15:28:53 +0100103 for type in ['manual', 'marker']
104 exe 'set foldmethod=' . type
105 new
106 call setline(1, range(1, 20))
107 4,$fold
108 %foldopen
109 10,$fold
110 %foldopen
111 " This filter command should not have an effect
112 1,8! cat
113 call feedkeys('5ggzdzMGdd', 'xt')
114 call assert_equal(['1', '2', '3', '4', '5', '6', '7', '8', '9'], getline(1, '$'))
115
116 bwipe!
117 set foldmethod&
118 endfor
Bram Moolenaar1159b162017-02-28 21:53:56 +0100119endfunc