feat(fps): Add refresh style display for telescope

This commit is contained in:
TJ DeVries
2022-06-11 14:57:10 -04:00
parent e6b69b1488
commit 26b357789b
33 changed files with 1550 additions and 1597 deletions
+36 -87
View File
@@ -4,7 +4,7 @@ local eq = assert.are.same
describe("process_result", function()
it("works with one entry", function()
local manager = EntryManager:new(5, nil)
local manager = EntryManager:new(5)
manager:add_entry(nil, 1, "hello", "")
@@ -12,64 +12,32 @@ describe("process_result", function()
end)
it("works with two entries", function()
local manager = EntryManager:new(5, nil)
local manager = EntryManager:new(5)
manager:add_entry(nil, 1, "hello", "")
manager:add_entry(nil, 2, "later", "")
eq(2, manager.linked_states.size)
eq("hello", manager:get_entry(1))
eq("later", manager:get_entry(2))
end)
it("calls functions when inserting", function()
local called_count = 0
local manager = EntryManager:new(5, function()
called_count = called_count + 1
end)
assert(called_count == 0)
manager:add_entry(nil, 1, "hello", "")
assert(called_count == 1)
end)
it("calls functions when inserting twice", function()
local called_count = 0
local manager = EntryManager:new(5, function()
called_count = called_count + 1
end)
assert(called_count == 0)
manager:add_entry(nil, 1, "hello", "")
manager:add_entry(nil, 2, "world", "")
assert(called_count == 2)
eq("hello", manager:get_entry(0, 1))
eq("later", manager:get_entry(0, 2))
end)
it("correctly sorts lower scores", function()
local called_count = 0
local manager = EntryManager:new(5, function()
called_count = called_count + 1
end)
manager:add_entry(nil, 5, "worse result", "")
manager:add_entry(nil, 2, "better result", "")
local manager = EntryManager:new(5)
manager:add_entry(nil, 5, "worse result")
manager:add_entry(nil, 2, "better result")
eq("better result", manager:get_entry(1))
eq("worse result", manager:get_entry(2))
eq(2, called_count)
eq("better result", manager:get_entry(0, 1))
eq("worse result", manager:get_entry(0, 2))
end)
it("respects max results", function()
local called_count = 0
local manager = EntryManager:new(1, function()
called_count = called_count + 1
end)
manager:add_entry(nil, 2, "better result", "")
manager:add_entry(nil, 5, "worse result", "")
local manager = EntryManager:new(1)
manager:add_entry(nil, 2, "better result")
manager:add_entry(nil, 5, "worse result")
eq("better result", manager:get_entry(1))
eq(1, called_count)
eq("better result", manager:get_entry(0, 1))
end)
it("should allow simple entries", function()
@@ -103,31 +71,6 @@ describe("process_result", function()
eq(1, counts_executed)
end)
it("should not loop a bunch", function()
local info = {}
local manager = EntryManager:new(5, nil, info)
manager:add_entry(nil, 4, "better result", "")
manager:add_entry(nil, 3, "better result", "")
manager:add_entry(nil, 2, "better result", "")
-- Loops once to find 3 < 4
-- Loops again to find 2 < 3
eq(2, info.looped)
end)
it("should not loop a bunch, part 2", function()
local info = {}
local manager = EntryManager:new(5, nil, info)
manager:add_entry(nil, 4, "better result", "")
manager:add_entry(nil, 2, "better result", "")
manager:add_entry(nil, 3, "better result", "")
-- Loops again to find 2 < 4
-- Loops once to find 3 > 2
-- but less than 4
eq(3, info.looped)
end)
it("should update worst score in all append case", function()
local manager = EntryManager:new(2, nil)
manager:add_entry(nil, 2, "result 2", "")
@@ -138,20 +81,12 @@ describe("process_result", function()
end)
it("should update worst score in all prepend case", function()
local called_count = 0
local manager = EntryManager:new(2, function()
called_count = called_count + 1
end)
manager:add_entry(nil, 5, "worse result", "")
manager:add_entry(nil, 4, "less worse result", "")
manager:add_entry(nil, 2, "better result", "")
local manager = EntryManager:new(2)
manager:add_entry(nil, 5, "worse result")
manager:add_entry(nil, 4, "less worse result")
manager:add_entry(nil, 2, "better result")
-- Once for insert 5
-- Once for prepend 4
-- Once for prepend 2
eq(3, called_count)
eq("better result", manager:get_entry(1))
eq("better result", manager:get_entry(0, 1))
eq(4, manager.worst_acceptable_score)
end)
@@ -167,8 +102,8 @@ describe("process_result", function()
manager:add_entry(picker, 0.5, "same same", "asdf")
manager:add_entry(picker, 0.5, "same", "asdf")
eq("same", manager:get_entry(1))
eq("same same", manager:get_entry(2))
eq("same", manager:get_entry(0, 1))
eq("same same", manager:get_entry(0, 2))
end)
it("should call tiebreaker if score is the same, keep initial", function()
@@ -183,7 +118,21 @@ describe("process_result", function()
manager:add_entry(picker, 0.5, "same same", "asdf")
manager:add_entry(picker, 0.5, "same", "asdf")
eq("same", manager:get_entry(2))
eq("same same", manager:get_entry(1))
eq("same", manager:get_entry(0, 2))
eq("same same", manager:get_entry(0, 1))
end)
it(":window() should return table of resuls", function()
local manager = EntryManager:new(5, nil)
manager:add_entry(nil, 1, "first")
manager:add_entry(nil, 2, "second")
manager:add_entry(nil, 3, "third")
manager:add_entry(nil, 4, "fourth")
manager:add_entry(nil, 5, "sixth")
eq(5, manager.linked_states.size)
eq({ "second", "third" }, manager:window(2, 3))
end)
end)
@@ -1,6 +1,4 @@
require("plenary.reload").reload_module "telescope"
local tester = require "telescope.pickers._test"
local tester = require "telescope.testharness"
local disp = function(val)
return vim.inspect(val, { newline = " ", indent = "" })
@@ -11,6 +9,7 @@ describe("builtin.find_files", function()
tester.run_file "find_files__readme"
end)
<<<<<<< HEAD
it("should be able to move selections", function()
tester.run_file "find_files__with_ctrl_n"
end)
@@ -19,6 +18,14 @@ describe("builtin.find_files", function()
{ sorting_strategy = "descending" },
{ sorting_strategy = "ascending" },
} do
=======
for _, configuration in
ipairs {
{ sorting_strategy = "descending" },
{ sorting_strategy = "ascending" },
}
do
>>>>>>> 20a1519 (feat(fps): Add refresh style display for telescope)
it("should not display devicons when disabled: " .. disp(configuration), function()
tester.run_string(string.format(
[[
@@ -0,0 +1,109 @@
local tester = require "telescope.testharness"
--[[
Available functions are
- fixtures/file_a.txt
- fixtures/file_abc.txt
--]]
describe("scroll_cycle", function()
it("should be able to cycle selections: cycle", function()
tester.run_string [[
runner.picker("find_files", "fixtures/file<c-p>", {
post_close = {
{ "lua/tests/fixtures/file_abc.txt", helper.get_selection_value },
},
}, {
sorting_strategy = "ascending",
scroll_strategy = "cycle",
})
]]
end)
for _, sorting in ipairs { "ascending", "descending" } do
for _, key in ipairs { "<c-n>", "<c-p>" } do
it(string.format("Cycle: %sx2 %s", key, sorting), function()
tester.run_string(([[
runner.picker("find_files", "fixtures/file%s%s", {
post_typed = {
{ "lua/tests/fixtures/file_a.txt", helper.get_selection_value },
},
}, {
sorting_strategy = "%s",
scroll_strategy = "cycle",
}
) ]]):format(key, key, sorting))
end)
it(string.format("Cycle: %sx3 %s", key, sorting), function()
tester.run_string(([[
runner.picker("find_files", "fixtures/file%s%s%s", {
post_typed = {
{ "lua/tests/fixtures/file_abc.txt", helper.get_selection_value },
},
}, {
sorting_strategy = "%s",
scroll_strategy = "cycle",
}
) ]]):format(key, key, key, sorting))
end)
end
end
it("should be able to cycle selections: limit", function()
tester.run_string [[
runner.picker("find_files", "fixtures/file<c-p>", {
post_close = {
{ "lua/tests/fixtures/file_a.txt", helper.get_selection_value },
},
}, {
sorting_strategy = "ascending",
scroll_strategy = "limit",
})
]]
end)
it("long: cycle to top", function()
tester.run_string [[
runner.picker("find_files", "fixtures/long<c-p>", {
post_close = {
{ "lua/tests/fixtures/long_11111111111.md", helper.get_selection_value },
},
}, {
sorting_strategy = "ascending",
scroll_strategy = "cycle",
height = 10,
})
]]
end)
it("long: cycle to top", function()
tester.run_string [[
runner.picker("find_files", "fixtures/long<c-n>", {
post_close = {
{ "lua/tests/fixtures/long_11111111111.md", helper.get_selection_value },
},
}, {
sorting_strategy = "descending",
scroll_strategy = "cycle",
height = 10,
})
]]
end)
it("long: smash <c-p>", function()
tester.run_string [[
runner.picker("find_files", "fixtures/long<c-p><c-p><c-p><c-p><c-p>", {
post_typed = {
{ "lua/tests/fixtures/long_111111.md", helper.get_selection_value },
},
}, {
sorting_strategy = "descending",
scroll_strategy = "cycle",
layout_config = {
height = 8,
},
})
]]
end)
end)
@@ -1,9 +1,4 @@
require("plenary.reload").reload_module "telescope"
local tester = require "telescope.pickers._test"
local log = require "telescope.log"
log.use_console = false
local tester = require "telescope.testharness"
describe("scrolling strategies", function()
it("should handle cycling for full list", function()
@@ -0,0 +1,39 @@
local testharness = require "telescope.testharness"
describe("testing harness", function()
it("should find the readme, using lowercase", function()
testharness.run_string [[
runner.picker('find_files', 'readme.md', {
post_typed = {
{ "> readme.md", GetPrompt },
{ " README.md", GetBestResult },
},
post_close = {
{ 'README.md', GetFile },
}
}, {
disable_devicons = true,
})
]]
end)
it("should find the readme, using uppercase", function()
testharness.run_string [[
runner.picker('find_files', 'RE', {
post_close = {
{ 'README.md', GetFile },
}
})
]]
end)
it("Should find telescope prompt file", function()
testharness.run_string [[
runner.picker('find_files', 'TelescopePrompt', {
post_close = {
{ 'TelescopePrompt.lua', GetFile },
}
})
]]
end)
end)
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
+3 -3
View File
@@ -1,7 +1,7 @@
local tester = require "telescope.pickers._test"
local helper = require "telescope.pickers._test_helpers"
local helper = require "telescope.testharness.helpers"
local runner = require "telescope.testharness.runner"
tester.builtin_picker("find_files", "README.md", {
runner.picker("find_files", "README.md", {
post_close = {
{ "README.md", helper.get_file },
},
@@ -1,12 +1,11 @@
require("plenary.reload").reload_module "plenary"
require("plenary.reload").reload_module "telescope"
local tester = require "telescope.testharness"
local runner = require "telescope.testharness.runner"
local helper = require "telescope.testharness.helpers"
local tester = require "telescope.pickers._test"
local helper = require "telescope.pickers._test_helpers"
tester.builtin_picker("find_files", "telescope<c-n>", {
runner.picker("find_files", "plugin<c-n>", {
post_close = {
tester.not_ { "plugin/telescope.vim", helper.get_file },
tester.not_ { "telescope.vim", helper.get_file },
{ "TelescopePrompt.lua", helper.get_file },
},
}, {
sorting_strategy = "descending",
@@ -1,8 +0,0 @@
local tester = require "telescope.pickers._test"
local helper = require "telescope.pickers._test_helpers"
tester.builtin_picker("find_files", "fixtures/file<c-p>", {
post_close = {
{ "lua/tests/fixtures/file_abc.txt", helper.get_selection_value },
},
})