diff --git a/tests/integration/session_spec.lua b/tests/integration/session_spec.lua index 339665ec3..e4d44e621 100644 --- a/tests/integration/session_spec.lua +++ b/tests/integration/session_spec.lua @@ -1188,4 +1188,558 @@ describe("session", function() jump(1) screen:expect{unchanged=true} end) + it("Insertion into non-interactive node works correctly", function() + feed("ifn") + expand() + + -- expand snippet in textNode, ie. s.t. it can't be properly linked up. + feed("kifn") + expand() + screen:expect{grid=[[ + /** | + * A short Description | + /** | + * A short Description | + */ | + ^public void myFunc() { {4:●} | + | + } */ | + public void myFunc() { {4:●} | + | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + -- jump into startNode, and back into current node. + jump(-1) jump(-1) + screen:expect{grid=[[ + /** | + * A short Description | + /** | + * A short Description | + */ | + public void myFunc() { | + | + } */ | + ^public void myFunc() { {4:●} | + | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + + -- check jumping out in other direction. + feed("jjifn") + expand() + -- jump to one before jumping out of child-snippet. + jump(1) jump(1) jump(1) jump(1) jump(1) jump(1) + screen:expect{grid=[[ + /** | + * A short Description | + /** | + * A short Description | + */ | + public void myFunc() { | + | + } */ | + public void myFunc() { {4:●} | + | + /** | + * A short Description | + */ | + public void myFunc() { | + ^ | + }} | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + -- leave child. + jump(1) + -- check back in current node. + screen:expect{grid=[[ + /** | + * A short Description | + /** | + * A short Description | + */ | + public void myFunc() { | + | + } */ | + ^public void myFunc() { {4:●} | + | + /** | + * A short Description | + */ | + public void myFunc() { | + | + }} | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + end) + it("All operations work as expected in a longer session.", function() + exec_lua([[ + ls.setup({ + keep_roots = true, + link_roots = true, + link_children = true, + delete_check_events = "TextChanged", + ext_opts = { + [require("luasnip.util.types").choiceNode] = { + active = { + virt_text = {{"●", "ErrorMsg"}}, + priority = 0 + }, + } + }, + }) + ]]) + feed("ifn") + expand() + feed("kkwwwifn") + expand() + screen:expect{grid=[[ + /** | + * A /** | + * A short Description | + */ | + ^public void myFunc() { {4:●} | + | + }short Description | + */ | + public void myFunc() { | + | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + + feed("ggOfn") + expand() + screen:expect{grid=[[ + /** | + * A short Description | + */ | + ^public void myFunc() { {4:●} | + | + } | + /** | + * A /** | + * A short Description | + */ | + public void myFunc() { | + | + }short Description | + */ | + public void myFunc() { | + | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + + -- ensure correct linkage. + jump(1) jump(1) jump(1) + jump(1) jump(1) jump(1) + jump(1) + screen:expect{grid=[[ + /** | + * A short Description | + */ | + public void myFunc() { | + | + } | + /** | + * A /** | + * A short Description | + */ | + public void myFunc() { | + | + }short Description | + */ | + ^public void myFunc() { {4:●} | + | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + + -- enter third choiceNode of second expanded snippet. + feed("kkkk$h") + exec_lua([[require("luasnip").activate_node()]]) + screen:expect{grid=[[ + /** | + * A short Description | + */ | + public void myFunc() { | + | + } | + /** | + * A /** | + * A short Description | + */ | + public void myFunc()^ { {4:●} | + | + }short Description | + */ | + public void myFunc() { | + | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + + -- check connectivity. + jump(1) jump(1) jump(1) + screen:expect{grid=[[ + /** | + * A short Description | + */ | + public void myFunc() { | + | + } | + /** | + * A /** | + * A short Description | + */ | + public void myFunc() { | + | + }short Description | + */ | + public void myFunc() { | + ^ | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + -- stay at last node. + jump(1) + screen:expect{unchanged = true} + + -- expand in textNode. + feed("kkbifn") + expand() + + -- check connectivity. + jump(-1) jump(-1) + screen:expect{grid=[[ + /** | + * A short Description | + */ | + public void myFunc() { | + | + } | + /** | + * ^A{3: /**} | + {3: * A short Description} | + {3: */} | + {3: public void myFunc() {} | + {3: } | + {3: }short Description} | + /** | + * A short Description | + */ | + public void myFunc() { | + | + }*/ | + public void myFunc() { | + | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- SELECT --} |]]} + + -- end up back in last node, not in textNode-expanded snippet. + jump(1) jump(1) jump(1) jump(1) + jump(1) jump(1) jump(1) jump(1) + screen:expect{grid=[[ + /** | + * A short Description | + */ | + public void myFunc() { | + | + } | + /** | + * A /** | + * A short Description | + */ | + public void myFunc() { | + | + }short Description | + /** | + * A short Description | + */ | + public void myFunc() { | + | + }*/ | + public void myFunc() { | + ^ | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + + feed("gg") + exec_lua([[require("luasnip").activate_node()]]) + + feed("Vjjjjjx") + exec_lua("ls.unlink_current_if_deleted()") + screen:expect{grid=[[ + ^/** | + * A /** | + * A short Description | + */ | + public void myFunc() { | + | + }short Description | + /** | + * A short Description | + */ | + public void myFunc() { | + | + }*/ | + public void myFunc() { | + | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + 6 fewer lines |]]} + -- first snippet is active again. + jump(1) + screen:expect{grid=[[ + /** | + * A /** | + * A short Description | + */ | + public void myFunc() { | + | + }short Description | + /** | + * A short Description | + */ | + public void myFunc() { | + | + }*/ | + ^public void myFunc() { {4:●} | + | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + + -- make sure the deleted snippet got disconnected properly. + assert.are.same(exec_lua([[return ls.session.current_nodes[1].parent.snippet.prev.prev and "Node before" or "No node before"]]), "No node before") + + -- jump a bit into snippet, so exit_out_of_region changes the current snippet. + jump(1) jump(1) jump(1) jump(1) + jump(1) jump(1) + screen:expect{grid=[[ + /** | + * A /** | + * A short Description | + */ | + ^public void myFunc() { {4:●} | + | + }short Description | + /** | + * A short Description | + */ | + public void myFunc() { | + | + }*/ | + public void myFunc() { | + | + } | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- INSERT --} |]]} + + feed("Go") + exec_lua("ls.exit_out_of_region(ls.session.current_nodes[1])") + jump(-1) + screen:expect{grid=[[ + /** | + * ^A{3: /**} | + {3: * A short Description} | + {3: */} | + {3: public void myFunc() {} | + {3: } | + {3: }short Description} | + /** | + * A short Description | + */ | + public void myFunc() { | + | + }*/ | + public void myFunc() { | + | + } | + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {2:-- SELECT --} |]]} + end) end)