Skip to content

Commit fd2339d

Browse files
committed
ci: added testing for fzf_live API
1 parent 1671952 commit fd2339d

19 files changed

Lines changed: 179 additions & 19 deletions

lua/fzf-lua/test/helpers.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ M.FzfLua = setmetatable({}, {
398398

399399
-- When using `fzf_exec` opts are at index[2], or otherwise at index[1]
400400
-- remove index[1] into "contents" so index[1] is always our "opts"
401-
local contents = api == "fzf_exec" and (table.remove(args, 1) .. ",") or ""
401+
local contents = (api == "fzf_exec" or api == "fzf_live")
402+
and (table.remove(args, 1) .. ",") or ""
402403

403404
-- Split "opts" and "ci_opts" which are double underscore prefixed
404405
local opts, ci_opts = (function()

tests/api_spec.lua

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ T["api"] = new_set()
1212
T["api"]["fzf_exec"] = new_set()
1313

1414
T["api"]["fzf_exec"]["table"] = function()
15-
helpers.FzfLua.fzf_exec(child,
16-
[==[(function()
15+
helpers.FzfLua.fzf_exec(child, [==[(function()
1716
local contents = {}
1817
for i = 1, 100 do
1918
for j, s in ipairs({ "foo", "bar", "baz" }) do
@@ -44,11 +43,84 @@ T["api"]["fzf_exec"]["function"] = new_set({ parametrize = { { "sync" }, { "asyn
4443
coroutine.yield()
4544
end
4645
fzf_cb(nil)
47-
end))
48-
]==],
46+
end))]==],
4947
{ __expect_lines = true, __postprocess_wait = true })
5048
end
5149
end,
5250
})
5351

52+
T["api"]["fzf_live"] = new_set()
53+
54+
T["api"]["fzf_live"]["table"] = function()
55+
helpers.FzfLua.fzf_live(child, [==[function(args)
56+
local q = args[1]
57+
if not tonumber(q) then
58+
return { "Invalid number: " .. tostring(q) }
59+
end
60+
local lines = {}
61+
for i = 1, tonumber(q) do
62+
for j, s in ipairs({ "foo", "bar", "baz" }) do
63+
table.insert(lines, tostring((i - 1) * 3 + j) .. ": " .. s)
64+
end
65+
end
66+
return lines
67+
end]==],
68+
{
69+
__expect_lines = true,
70+
__postprocess_wait = true,
71+
query = 100,
72+
})
73+
end
74+
75+
T["api"]["fzf_live"]["function"] = new_set({ parametrize = { { "sync" }, { "async" } } }, {
76+
function(type)
77+
if type == "sync" then
78+
helpers.FzfLua.fzf_live(child, [==[function(args)
79+
local q = args[1]
80+
return function(fzf_cb)
81+
if not tonumber(q) then
82+
fzf_cb("Invalid number: " .. tostring(q))
83+
else
84+
for i = 1, tonumber(q) do
85+
for j, s in ipairs({ "foo", "bar", "baz" }) do
86+
fzf_cb(tostring((i - 1) * 3 + j) .. ": " .. s)
87+
end
88+
end
89+
end
90+
fzf_cb(nil)
91+
end
92+
end]==],
93+
{
94+
__expect_lines = true,
95+
__postprocess_wait = true,
96+
query = 100,
97+
})
98+
else
99+
helpers.FzfLua.fzf_live(child, [==[function(args)
100+
local q = args[1]
101+
return coroutine.wrap(function(fzf_cb)
102+
local co = coroutine.running()
103+
if not tonumber(q) then
104+
fzf_cb("Invalid number: " .. tostring(q), function() coroutine.resume(co) end)
105+
coroutine.yield()
106+
else
107+
for i = 1, tonumber(q) do
108+
for j, s in ipairs({ "foo", "bar", "baz" }) do
109+
fzf_cb(tostring((i - 1) * 3 + j) .. ": " .. s, function() coroutine.resume(co) end)
110+
coroutine.yield()
111+
end
112+
end
113+
end
114+
fzf_cb(nil)
115+
end)
116+
end]==],
117+
{
118+
__expect_lines = true,
119+
__postprocess_wait = true,
120+
query = 100,
121+
})
122+
end
123+
end,
124+
})
125+
54126
return T
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--|---------|---------|---------|---------|---------|---------|----
2+
01|
3+
02|~
4+
03|~ ╭─────────────────────────────────────────────────╮
5+
04|~ │> 100 300/300 │
6+
05|~ │──────────────────────────────────────────────── │
7+
06|~ │▌ 1: foo ││
8+
07|~ │ 2: bar │
9+
08|~ │ 3: baz │
10+
09|~ │ 4: foo │
11+
10|~ │ 5: bar │
12+
11|~ │ 6: baz │
13+
12|~ │ 7: foo │
14+
13|~ │ 8: bar │
15+
14|~ │ 9: baz │
16+
15|~ │ 10: foo │
17+
16|~ │ 11: bar │
18+
17|~ │ 12: baz │
19+
18|~ │ 13: foo │
20+
19|~ │ 14: bar │
21+
20|~ │ 15: baz │
22+
21|~ │ 16: foo │
23+
22|~ ╰─────────────────────────────────────────────────╯
24+
23|~
25+
24|[No Name] 0,0-1 All
26+
25|
27+
26|
28+
27|
29+
28|-- TERMINAL -- 1,0-1 All
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--|---------|---------|---------|---------|---------|---------|----
2+
01|
3+
02|~
4+
03|~ ╭─────────────────────────────────────────────────╮
5+
04|~ │> 100 300/300 │
6+
05|~ │──────────────────────────────────────────────── │
7+
06|~ │▌ 1: foo ││
8+
07|~ │ 2: bar │
9+
08|~ │ 3: baz │
10+
09|~ │ 4: foo │
11+
10|~ │ 5: bar │
12+
11|~ │ 6: baz │
13+
12|~ │ 7: foo │
14+
13|~ │ 8: bar │
15+
14|~ │ 9: baz │
16+
15|~ │ 10: foo │
17+
16|~ │ 11: bar │
18+
17|~ │ 12: baz │
19+
18|~ │ 13: foo │
20+
19|~ │ 14: bar │
21+
20|~ │ 15: baz │
22+
21|~ │ 16: foo │
23+
22|~ ╰─────────────────────────────────────────────────╯
24+
23|~
25+
24|[No Name] 0,0-1 All
26+
25|
27+
26|
28+
27|
29+
28|-- TERMINAL -- 1,0-1 All
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--|---------|---------|---------|---------|---------|---------|----
2+
01|
3+
02|~
4+
03|~ ╭─────────────────────────────────────────────────╮
5+
04|~ │> 100 300/300 │
6+
05|~ │──────────────────────────────────────────────── │
7+
06|~ │▌ 1: foo ││
8+
07|~ │ 2: bar │
9+
08|~ │ 3: baz │
10+
09|~ │ 4: foo │
11+
10|~ │ 5: bar │
12+
11|~ │ 6: baz │
13+
12|~ │ 7: foo │
14+
13|~ │ 8: bar │
15+
14|~ │ 9: baz │
16+
15|~ │ 10: foo │
17+
16|~ │ 11: bar │
18+
17|~ │ 12: baz │
19+
18|~ │ 13: foo │
20+
19|~ │ 14: bar │
21+
20|~ │ 15: baz │
22+
21|~ │ 16: foo │
23+
22|~ ╰─────────────────────────────────────────────────╯
24+
23|~
25+
24|[No Name] 0,0-1 All
26+
25|
27+
26|
28+
27|
29+
28|-- TERMINAL -- 1,0-1 All

tests/screenshots/tests-file-ui_spec.lua---files---close-abort---1-+-args-{-'-c-c-'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 108/108 (0) │
5+
04|~ │> 111/111 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] [mt] rg --files --sort=path ││
88
07|~ │ LICENSE ││

tests/screenshots/tests-file-ui_spec.lua---files---close-abort---1-+-args-{-'-esc-'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 108/108 (0) │
5+
04|~ │> 111/111 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] [mt] rg --files --sort=path ││
88
07|~ │ LICENSE ││

tests/screenshots/tests-file-ui_spec.lua---files---executable---1-+-args-{-'fd'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭─────────────────── Files h ────────────────────╮
5-
04|~ │> 119/119 (0) │
5+
04|~ │> 122/122 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] [mt] fd --hidden --color=never --typ··││
88
07|~ │ .editorconfig ││

tests/screenshots/tests-file-ui_spec.lua---files---executable---1-+-args-{-'find-dir'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭───────────────────── Files ─────────────────────╮
5-
04|~ │> 119/119 (0) │
5+
04|~ │> 122/122 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] [mt] find . -type f \! -path '*/.git··││
88
07|~ │ .editorconfig ││

tests/screenshots/tests-file-ui_spec.lua---files---executable---1-+-args-{-'rg'-}

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
01|
33
02|~
44
03|~ ╭─────────────────── Files h ────────────────────╮
5-
04|~ │> 119/119 (0) │
5+
04|~ │> 122/122 (0) │
66
05|~ │──────────────────────────────────────────────── │
77
06|~ │▌ [DEBUG] [mt] rg --hidden --files -g "!.git" ··││
88
07|~ │ .editorconfig ││

0 commit comments

Comments
 (0)