Skip to content

Commit

Permalink
Add some preliminary tests, for checking error-reporting mostly.
Browse files Browse the repository at this point in the history
Checking the happy path requires some more work, since the
treesitter-parsers for lua and vscode need to be installed.
Probably add those in makefile?
  • Loading branch information
L3MON4D3 committed Apr 19, 2023
1 parent f3bdf8c commit fd5b027
Showing 1 changed file with 138 additions and 0 deletions.
138 changes: 138 additions & 0 deletions tests/integration/source_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
local helpers = require("test.functional.helpers")(after_each)
local exec_lua, feed, exec = helpers.exec_lua, helpers.feed, helpers.exec
local ls_helpers = require("helpers")
local Screen = require("test.functional.ui.screen")
local assert = require("luassert")

describe("loaders:", function()
local screen

before_each(function()
helpers.clear()

screen = Screen.new(50, 8)
screen:attach()
screen:set_default_attr_ids({
[0] = { bold = true, foreground = Screen.colors.Blue },
[1] = { bold = true, foreground = Screen.colors.Brown },
[2] = { bold = true },
[3] = { background = Screen.colors.LightGray },
})
end)

after_each(function()
screen:detach()
end)

it("error-message when source not available", function()
ls_helpers.session_setup_luasnip({ no_snip_globals = true })
ls_helpers.loaders["vscode(rtp)"]()

feed("iall1")
exec_lua("ls.expand()")
screen:expect{grid=[[
expands? jumps? ^ ! |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{2:-- INSERT --} |]]}
feed("<esc>")
exec_lua([[require("luasnip.extras.snip_location").jump_to_active_snippet()]])
screen:expect{grid=[[
expands? jumps?^ ! |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
Snippet does not have a source. |]]}
end)

it("vscode: error-message when parser not installed.", function()
ls_helpers.session_setup_luasnip({ no_snip_globals = true, setup_extend = {loaders_store_source = true} })
ls_helpers.loaders["vscode(rtp)"]()

feed("iall1")
exec_lua("ls.expand()")
screen:expect{grid=[[
expands? jumps? ^ ! |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{2:-- INSERT --} |]]}
feed("<esc>")
exec_lua([[require("luasnip.extras.snip_location").jump_to_active_snippet()]])
screen:expect{grid=[[
^{ |
"snip1": { |
"prefix": "all1", |
"body": [ |
"expands? jumps? $1 $2 !" |
] |
}, |
Could not determine ran...r jsonc) not installed. |]]}
end)

it("lua: error-message when lua-parser not installed.", function()
ls_helpers.session_setup_luasnip({ no_snip_globals = true, setup_extend = {loaders_store_source = true} })
ls_helpers.loaders["lua(rtp)"]()

feed("iall1")
exec_lua("ls.expand()")
screen:expect{grid=[[
expands? jumps? ^ ! |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{2:-- INSERT --} |]]}
feed("<esc>")
exec_lua([[require("luasnip.extras.snip_location").jump_to_active_snippet()]])
screen:expect{grid=[[
return { |
^ s("all1", fmt("expands? jumps? {} {} !", {|
i(1), i(2) })), |
}, { |
parse("auto???", "autotriggered????????"),|
} |
{0:~ }|
Could not determine ran... for lua not installed. |]]}
end)

it("snipmate: highlights snippet-definition.", function()
ls_helpers.session_setup_luasnip({ no_snip_globals = true, setup_extend = {loaders_store_source = true} })
ls_helpers.loaders["snipmate(rtp)"]()

feed("iall1")
exec_lua("ls.expand()")
screen:expect{grid=[[
expands? jumps? ^ ! |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{2:-- INSERT --} |]]}
feed("<esc>")
exec_lua([[require("luasnip.extras.snip_location").jump_to_active_snippet()]])
screen:expect{grid=[[
# A comment |
{3:^snippet all1 A test snippet} |
{3: expands? jumps? $1 $2 !} |
snippet all2 Another snippet |
multi$1 |
# not removed?? |
line$2 |
|]]}
end)
end)

0 comments on commit fd5b027

Please sign in to comment.