File tree Expand file tree Collapse file tree 2 files changed +95
-0
lines changed Expand file tree Collapse file tree 2 files changed +95
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Basic folding' do
6
+ def self . it_folds_lines ( content , lines , tags = nil )
7
+ it ( "folds #{ lines } lines on \n #{ content } " , tags ) do
8
+ expect ( content ) . to fold_lines ( lines , tags )
9
+ end
10
+ end
11
+
12
+ it_folds_lines ( <<~EOF , 2 )
13
+ defmodule M do
14
+ end
15
+ "not in fold"
16
+ EOF
17
+
18
+ it_folds_lines ( <<~EOF , 4 )
19
+ defmodule M do
20
+ def some_func do
21
+ end
22
+ end
23
+ "not in fold"
24
+ EOF
25
+
26
+ it_folds_lines ( <<~EOF , 2 , on_line : 2 )
27
+ defmodule M do
28
+ def some_func do
29
+ end
30
+ end
31
+ "not in fold"
32
+ EOF
33
+
34
+ it_folds_lines ( <<~EOF , 2 )
35
+ if true do
36
+ end
37
+ "not in fold"
38
+ EOF
39
+
40
+ it_folds_lines ( <<~EOF , 3 , on_line : 3 )
41
+ if true do
42
+ nil
43
+ else
44
+ nil
45
+ end
46
+ "not in fold"
47
+ EOF
48
+
49
+ it_folds_lines ( <<~EOF , 5 , skip : "broken" )
50
+ if true do
51
+ nil
52
+ else
53
+ nil
54
+ end
55
+ "not in fold"
56
+ EOF
57
+ end
58
+
Original file line number Diff line number Diff line change @@ -61,6 +61,18 @@ def syntax(content, pattern)
61
61
syngroups . gsub! ( /["'\[ \] ]/ , '' ) . split ( ', ' )
62
62
end
63
63
64
+ def fold_and_delete ( content , opts )
65
+ start_line = opts [ :on_line ]
66
+ with_file content do
67
+ @vim . command ( "set foldmethod=syntax" )
68
+
69
+ @vim . normal ( "zO" )
70
+ @vim . normal ( "#{ start_line } G" )
71
+ @vim . normal ( "zc" )
72
+ @vim . normal ( "dd" )
73
+ end
74
+ end
75
+
64
76
private
65
77
66
78
def with_file ( content = nil )
@@ -193,6 +205,31 @@ def self.new
193
205
end
194
206
end
195
207
208
+ RSpec ::Matchers . define :fold_lines do |lines , opts |
209
+ buffer = Buffer . new ( VIM , :ex )
210
+ opts ||= { }
211
+ start_line = opts [ :on_line ] ||= 1
212
+
213
+ after = nil
214
+
215
+ match do |code |
216
+ after = buffer . fold_and_delete ( code , opts )
217
+
218
+ code . lines . count - after . lines . count == lines
219
+ end
220
+
221
+ failure_message do |code |
222
+ <<~EOF
223
+ expected
224
+ #{ code }
225
+ to fold #{ lines } lines at line #{ start_line } ,
226
+ but after folding at line #{ start_line } and deleting a line I got
227
+ #{ after }
228
+ back
229
+ EOF
230
+ end
231
+ end
232
+
196
233
Vimrunner ::RSpec . configure do |config |
197
234
config . reuse_server = true
198
235
You can’t perform that action at this time.
0 commit comments