-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathgo_to_matching_spec.rb
64 lines (51 loc) · 1.76 KB
/
go_to_matching_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require_relative './spec_helper'
# This test simulates what happens in plugin/matchparen.vim, to ensure syntax/scala.vim
# uses style names that use the correct magic words.
describe 'default matching behavior' do
it 'jumps over parentheses in single-quotes' do
with_fixture('misc/jump_to_matching_paren.scala') do |file|
start_vim do |vim|
vim.edit file.path
vim.command 'set ft=scala'
vim.normal '2gg'
vim.normal '6|'
line_num, col_num = searchpairpos(vim, '(', '', ')', 'nW')
line_num.must_equal '2'
col_num.must_equal '10'
vim.normal '3gg'
vim.normal '10|'
line_num, col_num = searchpairpos(vim, '(', '', ')', 'bnW')
line_num.must_equal '3'
col_num.must_equal '6'
end
end
end
it 'jumps over curly braces in single-quotes' do
with_fixture('misc/jump_to_matching_curly.scala') do |file|
start_vim do |vim|
vim.edit file.path
vim.command 'set ft=scala'
vim.normal '1gg'
vim.normal '13|'
line_num, col_num = searchpairpos(vim, '{', '', '}', 'nW')
line_num.must_equal '4'
col_num.must_equal '1'
vim.normal '4gg'
vim.normal '1|'
line_num, col_num = searchpairpos(vim, '{', '', '}', 'bnW')
line_num.must_equal '1'
col_num.must_equal '13'
end
end
end
end
def read_pair(str)
str.match(/\[(\d+), (\d+)\]/)[1, 2]
end
def searchpairpos(vim, head, middle, tail, flags)
# distilled from vim80/plugin/matchparen.vim.
expr = <<-EXPR
searchpairpos('#{head}', '#{middle}', '#{tail}', '#{flags}', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\\\|character\\\\|singlequote\\\\|escape\\\\|comment"')
EXPR
read_pair vim.echo expr
end