Skip to content

Commit

Permalink
Merge pull request #60 from julienvincent/fix/support-for-reader-cond…
Browse files Browse the repository at this point in the history
…itionals

fix: adds `read_cond_lit` treesitter node
  • Loading branch information
armed authored Mar 30, 2024
2 parents 844b032 + 75b2b52 commit 8dd4ffd
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 2 deletions.
1 change: 1 addition & 0 deletions lua/nvim-paredit/lang/clojure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local common = require("nvim-paredit.utils.common")
local M = {}

local form_types = {
"read_cond_lit",
"list_lit",
"vec_lit",
"map_lit",
Expand Down
7 changes: 7 additions & 0 deletions tests/nvim-paredit/barf_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ describe("barfing ::", function()
after_content = "#{}a",
after_cursor = { 1, 2 },
},
{
"reader conditional",
before_content = "#?(:cljs a :clj b)",
before_cursor = { 1, 3 },
after_content = "#?(:cljs a :clj) b",
after_cursor = { 1, 3 },
}
})
end)

Expand Down
13 changes: 13 additions & 0 deletions tests/nvim-paredit/element_raise_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,17 @@ describe("element raising", function()
cursor = { 1, 0 },
})
end)

it("should raise a element inside reader conditional", function()
prepare_buffer({
content = { "#?(:clj (b", " c))" },
cursor = { 1, 8 },
})

paredit.raise_element()
expect({
content = { "(b", " c)" },
cursor = { 1, 0 },
})
end)
end)
7 changes: 7 additions & 0 deletions tests/nvim-paredit/form_raise_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ describe("form raising", function()
after_content = "#(b c)",
after_cursor = { 1, 0 },
},
{
"reader conditional",
before_content = "(let [z 1] #?(:clj a :cljs #{b c}))",
before_cursor = { 1, 14 },
after_content = "#?(:clj a :cljs #{b c})",
after_cursor = { 1, 0 },
},
})
end)

Expand Down
12 changes: 12 additions & 0 deletions tests/nvim-paredit/form_unwrap_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,16 @@ describe("form uwrap (e.g. splice)", function()
content = { "+ % 2 3" },
})
end)

it("should uwrap reader conditionsl under cursor", function()
prepare_buffer({
content = { "#?(:clj :foo/bar)" },
cursor = { 1, 10 },
})

unwrap.unwrap_form_under_cursor()
expect({
content = { ":clj :foo/bar" },
})
end)
end)
7 changes: 7 additions & 0 deletions tests/nvim-paredit/slurp_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ describe("slurping backward", function()
after_content = "#{a }",
after_cursor = { 1, 4 },
},
{
"reader conditional",
before_content = "a #?(:clj)",
before_cursor = { 1, 5 },
after_content = "#?(a :clj)",
after_cursor = { 1, 5 },
}
})
end)

Expand Down
28 changes: 26 additions & 2 deletions tests/nvim-paredit/text_object_selections_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ describe("form deletions", function()
})
end)

it("should delete the reader conditional form", function()
prepare_buffer({
content = "#?(:clj a :cljs a)",
cursor = { 1, 5 },
})
feedkeys("daf")
expect({
content = "",
cursor = { 1, 0 },
})
end)

it("should delete everything in the form", function()
prepare_buffer({
content = "(a b)",
Expand All @@ -74,6 +86,18 @@ describe("form deletions", function()
cursor = { 1, 1 },
})
end)

it("should delete everything in the reader conditional form", function()
prepare_buffer({
content = "#?(:clj a b)",
cursor = { 1, 4 },
})
feedkeys("dif")
expect({
content = "#?()",
cursor = { 1, 3 },
})
end)
end)

describe("top level form deletions", function()
Expand Down Expand Up @@ -149,7 +173,7 @@ describe("top form selections", function()

it("should select the root form and not the siblings", function()
prepare_buffer({
content = {"(+ 1 2)", "(foo (a", "a)) (/ 6 2)"},
content = { "(+ 1 2)", "(foo (a", "a)) (/ 6 2)" },
cursor = { 2, 6 },
})
feedkeys("vaF")
Expand All @@ -158,7 +182,7 @@ describe("top form selections", function()

it("should select within the form", function()
prepare_buffer({
content = {"(+ 1 2)", "(foo (a", "a)) (/ 6 2)"},
content = { "(+ 1 2)", "(foo (a", "a)) (/ 6 2)" },
cursor = { 2, 6 },
})
feedkeys("viF")
Expand Down

0 comments on commit 8dd4ffd

Please sign in to comment.