-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fennel treesitter queries and tests
- Loading branch information
1 parent
ffc009f
commit 136e560
Showing
7 changed files
with
302 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(list) @form | ||
(sequence) @form | ||
(table) @form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
local paredit = require("nvim-paredit.api") | ||
|
||
local prepare_buffer = require("tests.nvim-paredit.utils").prepare_buffer | ||
local expect = require("tests.nvim-paredit.utils").expect | ||
|
||
describe("element raising", function() | ||
vim.api.nvim_set_option_value("filetype", "fennel", { | ||
buf = 0, | ||
}) | ||
|
||
it("should raise the element", function() | ||
prepare_buffer({ | ||
content = "(a (b))", | ||
cursor = { 1, 4 }, | ||
}) | ||
paredit.raise_element() | ||
expect({ | ||
content = "(a b)", | ||
cursor = { 1, 3 }, | ||
}) | ||
end) | ||
|
||
it("should raise form elements when cursor is placed on edge", function() | ||
prepare_buffer({ | ||
content = "(a (b))", | ||
cursor = { 1, 3 }, | ||
}) | ||
|
||
paredit.raise_element() | ||
expect({ | ||
content = "(b)", | ||
cursor = { 1, 0 }, | ||
}) | ||
|
||
prepare_buffer({ | ||
content = "(a #(b))", | ||
cursor = { 1, 3 }, | ||
}) | ||
|
||
paredit.raise_element() | ||
expect({ | ||
content = "#(b)", | ||
cursor = { 1, 0 }, | ||
}) | ||
end) | ||
|
||
it("should raise a multi-line element", function() | ||
prepare_buffer({ | ||
content = { "(a (b", " c))" }, | ||
cursor = { 1, 3 }, | ||
}) | ||
|
||
paredit.raise_element() | ||
expect({ | ||
content = { "(b", " c)" }, | ||
cursor = { 1, 0 }, | ||
}) | ||
end) | ||
|
||
it("should do nothing if it is a direct child of the document root", function() | ||
prepare_buffer({ | ||
content = { "a", "b" }, | ||
cursor = { 1, 0 }, | ||
}) | ||
paredit.raise_form() | ||
expect({ | ||
content = { "a", "b" }, | ||
cursor = { 1, 0 }, | ||
}) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
local paredit = require("nvim-paredit.api") | ||
|
||
local prepare_buffer = require("tests.nvim-paredit.utils").prepare_buffer | ||
local expect_all = require("tests.nvim-paredit.utils").expect_all | ||
local expect = require("tests.nvim-paredit.utils").expect | ||
|
||
describe("form raising", function() | ||
vim.api.nvim_set_option_value("filetype", "fennel", { | ||
buf = 0, | ||
}) | ||
|
||
it("should raise the form", function() | ||
expect_all(paredit.raise_form, { | ||
{ | ||
"list", | ||
before_content = "(a (b c))", | ||
before_cursor = { 1, 6 }, | ||
after_content = "(b c)", | ||
after_cursor = { 1, 0 }, | ||
}, | ||
{ | ||
"list with reader", | ||
before_content = "(a #(b c))", | ||
before_cursor = { 1, 5 }, | ||
after_content = "#(b c)", | ||
after_cursor = { 1, 0 }, | ||
}, | ||
}) | ||
end) | ||
|
||
it("should raise a multi-line form", function() | ||
prepare_buffer({ | ||
content = { "(a (b ", "c))" }, | ||
cursor = { 1, 4 }, | ||
}) | ||
|
||
paredit.raise_form() | ||
expect({ | ||
content = { "(b ", "c)" }, | ||
cursor = { 1, 0 }, | ||
}) | ||
end) | ||
|
||
it("should do nothing if it is a direct child of the document root", function() | ||
prepare_buffer({ | ||
content = { "(a)", "b" }, | ||
cursor = { 1, 1 }, | ||
}) | ||
paredit.raise_form() | ||
expect({ | ||
content = { "(a)", "b" }, | ||
cursor = { 1, 1 }, | ||
}) | ||
end) | ||
|
||
it("should do nothing if it is outside of a form", function() | ||
prepare_buffer({ | ||
content = { "a", "b" }, | ||
cursor = { 1, 0 }, | ||
}) | ||
paredit.raise_form() | ||
expect({ | ||
content = { "a", "b" }, | ||
cursor = { 1, 0 }, | ||
}) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
local paredit = require("nvim-paredit.api") | ||
|
||
local prepare_buffer = require("tests.nvim-paredit.utils").prepare_buffer | ||
local expect = require("tests.nvim-paredit.utils").expect | ||
|
||
describe("motions", function() | ||
vim.api.nvim_set_option_value("filetype", "fennel", { | ||
buf = 0, | ||
}) | ||
|
||
it("should jump to next element in form (tail)", function() | ||
prepare_buffer({ | ||
content = "(aa (bb) #(cc))", | ||
cursor = { 1, 2 }, | ||
}) | ||
|
||
paredit.move_to_next_element_tail() | ||
expect({ | ||
cursor = { 1, 7 }, | ||
}) | ||
|
||
paredit.move_to_next_element_tail() | ||
expect({ | ||
cursor = { 1, 13 }, | ||
}) | ||
|
||
paredit.move_to_next_element_tail() | ||
expect({ | ||
cursor = { 1, 13 }, | ||
}) | ||
end) | ||
|
||
it("should jump to next element in form (head)", function() | ||
prepare_buffer({ | ||
content = "(aa (bb) #(cc))", | ||
cursor = { 1, 2 }, | ||
}) | ||
|
||
paredit.move_to_next_element_head() | ||
expect({ | ||
cursor = { 1, 4 }, | ||
}) | ||
|
||
paredit.move_to_next_element_head() | ||
expect({ | ||
cursor = { 1, 9 }, | ||
}) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
local paredit = require("nvim-paredit.api") | ||
|
||
local prepare_buffer = require("tests.nvim-paredit.utils").prepare_buffer | ||
local expect_all = require("tests.nvim-paredit.utils").expect_all | ||
local expect = require("tests.nvim-paredit.utils").expect | ||
|
||
describe("slurping forward", function() | ||
vim.api.nvim_set_option_value("filetype", "fennel", { | ||
buf = 0, | ||
}) | ||
local parser = vim.treesitter.get_parser(0) | ||
if not parser then | ||
return error("Failed to get parser for fennel") | ||
end | ||
|
||
it("should slurp forward different form types", function() | ||
expect_all(paredit.slurp_forwards, { | ||
{ | ||
"list", | ||
before_content = "() a", | ||
before_cursor = { 1, 1 }, | ||
after_content = "( a)", | ||
after_cursor = { 1, 1 }, | ||
}, | ||
{ | ||
"vector", | ||
before_content = "[] a", | ||
before_cursor = { 1, 1 }, | ||
after_content = "[ a]", | ||
after_cursor = { 1, 1 }, | ||
}, | ||
{ | ||
"quoted list", | ||
before_content = "`() a", | ||
before_cursor = { 1, 2 }, | ||
after_content = "`( a)", | ||
after_cursor = { 1, 2 }, | ||
}, | ||
}) | ||
end) | ||
|
||
it("should skip comments", function() | ||
prepare_buffer({ | ||
content = { "()", ";; comment", "a" }, | ||
cursor = { 1, 1 }, | ||
}) | ||
paredit.slurp_forwards() | ||
expect({ | ||
content = { "(", ";; comment", "a)" }, | ||
cursor = { 1, 0 }, | ||
}) | ||
end) | ||
|
||
it("should recursively slurp the next sibling", function() | ||
prepare_buffer({ | ||
content = "(()) 1 2", | ||
cursor = { 1, 2 }, | ||
}) | ||
|
||
paredit.slurp_forwards() | ||
expect({ | ||
content = "(() 1) 2", | ||
cursor = { 1, 2 }, | ||
}) | ||
|
||
parser:parse() | ||
|
||
paredit.slurp_forwards() | ||
expect({ | ||
content = "(( 1)) 2", | ||
cursor = { 1, 2 }, | ||
}) | ||
|
||
parser:parse() | ||
|
||
prepare_buffer({ | ||
content = "(( 1)) 2", | ||
cursor = { 1, 2 }, | ||
}) | ||
|
||
paredit.slurp_forwards() | ||
expect({ | ||
content = "(( 1) 2)", | ||
cursor = { 1, 2 }, | ||
}) | ||
|
||
parser:parse() | ||
|
||
paredit.slurp_forwards() | ||
expect({ | ||
content = "(( 1 2))", | ||
cursor = { 1, 2 }, | ||
}) | ||
end) | ||
|
||
it("should follow the bracket with cursor", function() | ||
prepare_buffer({ | ||
content = "() 1 2", | ||
cursor = { 1, 1 }, | ||
}) | ||
paredit.slurp_forwards({ cursor_behaviour = "follow" }) | ||
expect({ | ||
content = "( 1) 2", | ||
cursor = { 1, 3 }, | ||
}) | ||
end) | ||
end) |