Skip to content

Commit 70b1cfd

Browse files
tests for line_begin and line_end
1 parent c917e62 commit 70b1cfd

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/unit/expand_conditions_spec.lua

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,55 @@ describe("expand_conditions", function()
105105
end
106106
end)
107107
end)
108+
describe("line_begin", function()
109+
it("is at begin", function()
110+
local function foo()
111+
return helpers.exec_lua([[
112+
local cond = require("luasnip.extras.expand_conditions")
113+
local c = cond.line_begin
114+
return not c("hello world", "hello world") ~= true -- allow nil/object
115+
]])
116+
end
117+
assert.has_no.errors(foo)
118+
assert.is_true(foo())
119+
end)
120+
it("is NOT at begin", function()
121+
local function foo()
122+
return helpers.exec_lua([[
123+
local cond = require("luasnip.extras.expand_conditions")
124+
local c = cond.line_begin
125+
return not c("hello world", "ld") ~= false -- allow nil/object
126+
]])
127+
end
128+
assert.has_no.errors(foo)
129+
assert.is_true(foo())
130+
end)
131+
end)
132+
describe("line_end", function()
133+
it("is at begin", function()
134+
local function foo()
135+
return helpers.exec_lua([[
136+
-- vim.api.nvim_get_current_line
137+
vim = {api = {nvim_get_current_line = function() return "hello world ending" end}}
138+
local cond = require("luasnip.extras.expand_conditions")
139+
local c = cond.line_end
140+
return not c("hello world ending") ~= true -- allow nil/object
141+
]])
142+
end
143+
assert.has_no.errors(foo)
144+
assert.is_true(foo())
145+
end)
146+
it("is NOT at begin", function()
147+
local function foo()
148+
return helpers.exec_lua([[
149+
vim = {api = {nvim_get_current_line = function() return "hello world ending" end}}
150+
local cond = require("luasnip.extras.expand_conditions")
151+
local c = cond.line_end
152+
return not c("hello world") ~= false -- allow nil/object
153+
]])
154+
end
155+
assert.has_no.errors(foo)
156+
assert.is_true(foo())
157+
end)
158+
end)
108159
end)

0 commit comments

Comments
 (0)