Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
grierson committed Aug 12, 2023
1 parent a0a116d commit b5c78ea
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 142 deletions.
6 changes: 6 additions & 0 deletions fnl/formedit/selection.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
(let [node (ts.get_node_at_cursor)
form (tree.get-form node)
[start-row start-col end-row end-col] [(form:range)]
text (vim.api.nvim_buf_get_text 0 start-row start-col end-row end-col
{})
_ (print "Inner form text")
_ (print (vim.inspect text))
_ (print :range)
_ (print (vim.inspect [(form:range)]))
offset (if (or (= :set_lit (form:type)) (= :anon_fn_lit (form:type)))
2
1)]
Expand Down
36 changes: 36 additions & 0 deletions fnl/spec/delete_around_spec.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(local {: describe : it} (require :plenary.busted))
(local h (require :spec.helper))
(local selection (require :formedit.selection))

(describe "delete around"
(fn []
(it :list
(fn []
(h.setup {:content "(1)" :cursor [1 1]})
(selection.delete-around-form)
(h.expect {:content "" :cursor [1 0]})))
(it :vector
(fn []
(h.setup {:content "[1]" :cursor [1 1]})
(selection.delete-around-form)
(h.expect {:content "" :cursor [1 0]})))
(it :set
(fn []
(h.setup {:content "#{1}" :cursor [1 1]})
(selection.delete-around-form)
(h.expect {:content "" :cursor [1 0]})))
(it "anonymous function"
(fn []
(h.setup {:content "#(fn [x] x)" :cursor [1 1]})
(selection.delete-around-form)
(h.expect {:content "" :cursor [1 0]})))
(it "delete multiple children"
(fn []
(h.setup {:content "([1] [2])" :cursor [1 0]})
(selection.delete-around-form)
(h.expect {:content "" :cursor [1 0]})))
(it "delete across lines"
(fn []
(h.setup {:content ["([1]" "[2])"] :cursor [1 0]})
(selection.delete-around-form)
(h.expect {:content "" :cursor [1 0] :lines 1})))))
36 changes: 36 additions & 0 deletions fnl/spec/delete_inner_spec.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(local {: describe : it} (require :plenary.busted))
(local h (require :spec.helper))
(local selection (require :formedit.selection))

(describe "delete inner"
(fn []
(it :list
(fn []
(h.setup {:content "(1)" :cursor [1 1]})
(selection.delete-inner-form)
(h.expect {:content "()" :cursor [1 1]})))
(it :vector
(fn []
(h.setup {:content "[1]" :cursor [1 1]})
(selection.delete-inner-form)
(h.expect {:content "[]" :cursor [1 1]})))
(it :set
(fn []
(h.setup {:content "#{1}" :cursor [1 1]})
(selection.delete-inner-form)
(h.expect {:content "#{}" :cursor [1 1]})))
(it "anonymous function"
(fn []
(h.setup {:content "#(fn [x] x)" :cursor [1 1]})
(selection.delete-inner-form)
(h.expect {:content "#()" :cursor [1 1]})))
(it "delete multiple children"
(fn []
(h.setup {:content "([1] [2])" :cursor [1 0]})
(selection.delete-inner-form)
(h.expect {:content "()" :cursor [1 0]})))
(it "delete across lines"
(fn []
(h.setup {:content ["([1]," "[2])"] :cursor [1 0]})
(selection.delete-inner-form)
(h.expect {:content "()" :cursor [1 0] :lines 2})))))
28 changes: 18 additions & 10 deletions fnl/spec/helper.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
(local core (require :formedit.nfnl.core))

(fn setup [{: cursor : content}]
(vim.api.nvim_buf_set_option 0 :filetype :clojure)
(vim.api.nvim_buf_set_lines 0 0 -1 true [content])
(vim.api.nvim_win_set_cursor 0 cursor)
(: (vim.treesitter.get_parser 0) :parse))
(let [content (if (= (type content) :string)
[content]
content)]
(vim.api.nvim_buf_set_option 0 :filetype :clojure)
(vim.api.nvim_buf_set_lines 0 0 -1 true content)
(vim.api.nvim_win_set_cursor 0 cursor)
(: (vim.treesitter.get_parser 0) :parse)))

(fn expect [{: cursor : content}]
(when content
(assert.are.same content
(core.first (vim.api.nvim_buf_get_lines 0 0 -1 false))))
(when cursor
(assert.are.same cursor (vim.api.nvim_win_get_cursor 0))))
(fn expect [{: cursor : content : lines}]
(let [lines (or lines 0)
_ (print lines)
foo (vim.api.nvim_buf_get_lines 0 lines -1 false)
_ (print "found text in expect")
_ (print (vim.inspect foo))]
(when content
(assert.are.same content
(core.first (vim.api.nvim_buf_get_lines 0 lines -1 false))))
(when cursor
(assert.are.same cursor (vim.api.nvim_win_get_cursor 0)))))

{: setup : expect}
57 changes: 0 additions & 57 deletions fnl/spec/selection_spec.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(local h (require :spec.helper))
(local tree (require :formedit.tree))
(local assert (require :luassert.assert))
(local selection (require :formedit.selection))
(local ts (require :nvim-treesitter.ts_utils))

(describe :selection
Expand All @@ -13,59 +12,3 @@
(let [node (ts.get_node_at_cursor)
form (tree.get-form node)]
(assert.are.same [0 0 0 3] [(form:range)]))))))

(describe "delete around"
(fn []
(it :list
(fn []
(h.setup {:content "(1)" :cursor [1 1]})
(selection.delete-around-form)
(h.expect {:content "" :cursor [1 0]})))
(it :vector
(fn []
(h.setup {:content "[1]" :cursor [1 1]})
(selection.delete-around-form)
(h.expect {:content "" :cursor [1 0]})))
(it :set
(fn []
(h.setup {:content "#{1}" :cursor [1 1]})
(selection.delete-around-form)
(h.expect {:content "" :cursor [1 0]})))
(it "anonymous function"
(fn []
(h.setup {:content "#(fn [x] x)" :cursor [1 1]})
(selection.delete-around-form)
(h.expect {:content "" :cursor [1 0]})))
(it "delete multiple children"
(fn []
(h.setup {:content "([1] [2])" :cursor [1 0]})
(selection.delete-around-form)
(h.expect {:content "" :cursor [1 0]})))))

(describe "delete inner"
(fn []
(it :list
(fn []
(h.setup {:content "(1)" :cursor [1 1]})
(selection.delete-inner-form)
(h.expect {:content "()" :cursor [1 1]})))
(it :vector
(fn []
(h.setup {:content "[1]" :cursor [1 1]})
(selection.delete-inner-form)
(h.expect {:content "[]" :cursor [1 1]})))
(it :set
(fn []
(h.setup {:content "#{1}" :cursor [1 1]})
(selection.delete-inner-form)
(h.expect {:content "#{}" :cursor [1 1]})))
(it "anonymous function"
(fn []
(h.setup {:content "#(fn [x] x)" :cursor [1 1]})
(selection.delete-inner-form)
(h.expect {:content "#()" :cursor [1 1]})))
(it "delete multiple children"
(fn []
(h.setup {:content "([1] [2])" :cursor [1 0]})
(selection.delete-inner-form)
(h.expect {:content "()" :cursor [1 0]})))))
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ focus feature: prepare
-c "PlenaryBustedDirectory lua/spec/{{feature}} { minimal_init='lua/spec/init.lua', sequential=true }"

watch feature:
fswatch -o lua/formedit/{{feature}}.lua lua/spec/{{feature}}_spec.lua | xargs -n1 -I{} just file {{feature}}
fswatch -o lua/formedit/*.lua lua/spec/{{feature}}_spec.lua | xargs -n1 -I{} just file {{feature}}
5 changes: 5 additions & 0 deletions lua/formedit/selection.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions lua/spec/delete_around_spec.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions lua/spec/delete_inner_spec.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions lua/spec/helper.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b5c78ea

Please sign in to comment.