Skip to content

Commit

Permalink
add the rest of the block opener keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiahkellick committed Aug 11, 2018
1 parent 2b882e2 commit c9c7655
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugin/textobj/rubyblock.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ call textobj#user#plugin('rubyblock', {

" Misc. "{{{1
let s:comment_escape = '\v^[^#]*'
let s:block_openers = '\zs(<def>|<if>|<do>|<module>|<class>)'
let s:block_openers = '\zs(<def>|<if>|<unless>|<do>|<module>|<class>|<case>'
let s:block_openers .= '|<for>|<while>|<until>|<begin>)'
let s:start_pattern = s:comment_escape . s:block_openers
let s:end_pattern = s:comment_escape . '\zs<end>'
let s:skip_pattern = 'getline(".") =~ "\\v\\S\\s<(if|unless)>\\s\\S"'
Expand Down
16 changes: 16 additions & 0 deletions t/examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,19 @@ def hello
bar
end

def method_with_while
var1 = 1
i = 0
while i < 10
i += 1
end
var2 = 2
end

def method_with_unless
var1 = 1
unless condition
puts 'foo'
end
var2 = 2
end
17 changes: 17 additions & 0 deletions t/rubyblock_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ describe '<Plug>(textobj-rubyblock-a)'

end

describe 'nested while and unless blocks'

before
silent tabnew t/examples.rb
end

after
silent tabclose
end

it 'ignores nested while and unless blocks'
Expect SelectAroundFrom(69, '^') ==# [69, 68, 75]
Expect SelectAroundFrom(78, '^') ==# [78, 77, 83]
end

end

describe '<Plug>(textobj-rubyblock-i)'

before
Expand Down

0 comments on commit c9c7655

Please sign in to comment.