@@ -4,13 +4,16 @@ runtime! macros/matchit.vim
4
4
runtime ! plugin /textobj/ * .vim
5
5
set visualbell
6
6
7
- function ! InvokeFromLine (line , type )
8
- execute " normal " .a: line ." G"
9
- execute " normal v\<Plug> (textobj-rubyblock-" .a: type ." )\<Esc> "
7
+ function ! SelectInsideFrom (number , position)
8
+ execute " normal " .a: number ." G" .a: position
9
+ execute " normal v\<Plug> (textobj-rubyblock-i)\<Esc> "
10
+ return [a: number , line (" '<" ), line (" '>" )]
10
11
endfunction
11
12
12
- function ! SelectedRange ()
13
- return [line (" '<" ), line (" '>" )]
13
+ function ! SelectAroundFrom (number , position)
14
+ execute " normal " .a: number ." G" .a: position
15
+ execute " normal v\<Plug> (textobj-rubyblock-a)\<Esc> "
16
+ return [a: number , line (" '<" ), line (" '>" )]
14
17
endfunction
15
18
16
19
describe ' rubyblock'
@@ -58,8 +61,7 @@ describe '<Plug>(textobj-rubyblock-i)'
58
61
end
59
62
60
63
it ' selects inside of a class'
61
- execute " normal v\<Plug> (textobj-rubyblock-i)\<Esc> "
62
- Expect SelectedRange () == # [2 , 2 ]
64
+ Expect SelectInsideFrom (1 , ' ^' ) == # [1 , 2 , 2 ]
63
65
end
64
66
65
67
end
@@ -74,8 +76,7 @@ describe '<Plug>(textobj-rubyblock-a)'
74
76
end
75
77
76
78
it ' selects all of a class'
77
- execute " normal v\<Plug> (textobj-rubyblock-a)\<Esc> "
78
- Expect SelectedRange () == # [1 , 3 ]
79
+ Expect SelectAroundFrom (1 , ' ^' ) == # [1 , 1 , 3 ]
79
80
end
80
81
81
82
end
@@ -92,7 +93,7 @@ describe '<Plug>(textobj-rubyblock-i)'
92
93
it ' ignores "end" keyword inside of a comment'
93
94
execute " normal v\<Plug> (textobj-rubyblock-i)\<Esc> "
94
95
TODO
95
- Expect SelectedRange ( ) == # [2 , 2 ]
96
+ Expect SelectInsideFrom ( 1 , ' ^ ' ) == # [1 , 2 , 2 ]
96
97
end
97
98
98
99
end
@@ -107,24 +108,20 @@ describe 'if/else blocks'
107
108
end
108
109
109
110
it ' ignores nested if/else block'
110
- for num in [1 ,2 ,8 ]
111
- call InvokeFromLine (num, ' i' )
112
- Expect SelectedRange () == # [2 , 7 ]
111
+ for number in [1 ,2 ,8 ]
112
+ Expect SelectInsideFrom (number , ' ^' ) == # [number , 2 , 7 ]
113
113
endfor
114
- for num in [1 ,2 ,7 ,8 ]
115
- call InvokeFromLine (num, ' a' )
116
- Expect SelectedRange () == # [1 , 8 ]
114
+ for number in [1 ,2 ,7 ,8 ]
115
+ Expect SelectAroundFrom (number , ' ^' ) == # [number , 1 , 8 ]
117
116
endfor
118
117
end
119
118
120
119
it ' selects nested if/else block'
121
- for num in [3 ,4 ,5 ,6 ,7 ]
122
- call InvokeFromLine (num, ' i' )
123
- Expect SelectedRange () == # [4 , 6 ]
120
+ for number in [3 ,4 ,5 ,6 ,7 ]
121
+ Expect SelectInsideFrom (number , ' ^' ) == # [number , 4 , 6 ]
124
122
endfor
125
- for num in [3 ,4 ,5 ,6 ]
126
- call InvokeFromLine (num, ' a' )
127
- Expect SelectedRange () == # [3 , 7 ]
123
+ for number in [3 ,4 ,5 ,6 ]
124
+ Expect SelectAroundFrom (number , ' ^' ) == # [number , 3 , 7 ]
128
125
endfor
129
126
end
130
127
0 commit comments