-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicker_fzf_lua_spec.lua
More file actions
45 lines (39 loc) · 1.51 KB
/
Copy pathpicker_fzf_lua_spec.lua
File metadata and controls
45 lines (39 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
describe("peekstack.picker.fzf_lua", function()
local picker = require("peekstack.picker.fzf_lua")
it("should select the correct item when labels collide", function()
local original = package.loaded["fzf-lua"]
local picked = nil
local captured_opts = nil
package.loaded["fzf-lua"] = {
fzf_exec = function(source, opts)
captured_opts = opts
local lines = source()
assert.is_true(lines[1]:match("^/tmp/same.lua:1:1\t") ~= nil)
assert.is_true(lines[2]:match("^/tmp/same.lua:1:1\t") ~= nil)
assert.is_true(lines[1]:match("\t1$") ~= nil)
assert.is_true(lines[2]:match("\t2$") ~= nil)
opts.actions["default"]({ lines[2] })
end,
}
local loc1 = {
uri = "file:///tmp/same.lua",
range = { start = { line = 0, character = 0 }, ["end"] = { line = 0, character = 0 } },
provider = "test",
}
local loc2 = {
uri = "file:///tmp/same.lua",
range = { start = { line = 0, character = 0 }, ["end"] = { line = 0, character = 0 } },
provider = "test",
}
picker.pick({ loc1, loc2 }, nil, function(choice)
picked = choice
end)
assert.are.same(loc2, picked)
assert.equals("builtin", captured_opts.previewer)
assert.equals("Peekstack> ", captured_opts.prompt)
assert.equals("\t", captured_opts.fzf_opts["--delimiter"])
assert.equals("2", captured_opts.fzf_opts["--with-nth"])
assert.equals("2", captured_opts.fzf_opts["--nth"])
package.loaded["fzf-lua"] = original
end)
end)