(range:from_tsquery_caps) add tests
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m30s
All checks were successful
NeoVim tests / code-quality (push) Successful in 1m30s
This commit is contained in:
parent
099b713e52
commit
0978422a47
@ -238,6 +238,57 @@ describe('Range', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('from_tsquery_caps', function()
|
||||||
|
withbuf({
|
||||||
|
'-- a comment',
|
||||||
|
'',
|
||||||
|
'function foo(bar) end',
|
||||||
|
'',
|
||||||
|
'-- a middle comment',
|
||||||
|
'',
|
||||||
|
'function bar(baz) end',
|
||||||
|
'',
|
||||||
|
'-- another comment',
|
||||||
|
}, function()
|
||||||
|
vim.cmd.setfiletype 'lua'
|
||||||
|
|
||||||
|
--- @param contains_cursor? boolean
|
||||||
|
local function get_caps(contains_cursor)
|
||||||
|
if contains_cursor == nil then contains_cursor = true end
|
||||||
|
return (Range.from_tsquery_caps(
|
||||||
|
0,
|
||||||
|
'(function_declaration) @f',
|
||||||
|
{ contains_cursor = contains_cursor }
|
||||||
|
)).f or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local caps = get_caps(false)
|
||||||
|
assert.are.same(#caps, 2)
|
||||||
|
assert.are.same(vim.iter(caps):map(function(c) return c:text() end):totable(), {
|
||||||
|
'function foo(bar) end',
|
||||||
|
'function bar(baz) end',
|
||||||
|
})
|
||||||
|
|
||||||
|
Pos.new(0, 1, 1):save_to_pos '.'
|
||||||
|
caps = get_caps()
|
||||||
|
assert.are.same(#caps, 0)
|
||||||
|
|
||||||
|
Pos.new(0, 3, 18):save_to_pos '.'
|
||||||
|
caps = get_caps()
|
||||||
|
assert.are.same(#caps, 1)
|
||||||
|
assert.are.same(caps[1]:text(), 'function foo(bar) end')
|
||||||
|
|
||||||
|
Pos.new(0, 5, 1):save_to_pos '.'
|
||||||
|
caps = get_caps()
|
||||||
|
assert.are.same(#caps, 0)
|
||||||
|
|
||||||
|
Pos.new(0, 7, 1):save_to_pos '.'
|
||||||
|
caps = get_caps()
|
||||||
|
assert.are.same(#caps, 1)
|
||||||
|
assert.are.same(caps[1]:text(), 'function bar(baz) end')
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
it('should get nearest block', function()
|
it('should get nearest block', function()
|
||||||
withbuf({
|
withbuf({
|
||||||
'this is a {',
|
'this is a {',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user