spacevim/bundle/telescope.nvim-0.1.5/lua/tests/automated/scroller_spec.lua
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

144 lines
4.6 KiB
Lua

local p_scroller = require "telescope.pickers.scroller"
local log = require "telescope.log"
log.use_console = false
local eq = assert.are.same
describe("scroller", function()
local max_results = 10
describe("ascending cycle", function()
local cycle_scroller = p_scroller.create("cycle", "ascending")
it("should return values within the max results", function()
eq(5, cycle_scroller(max_results, max_results, 5))
end)
it("should return 0 at 0", function()
eq(0, cycle_scroller(max_results, max_results, 0))
end)
it("should cycle you to the top when you go below 0", function()
eq(max_results - 1, cycle_scroller(max_results, max_results, -1))
end)
it("should cycle you to 0 when you go past the results", function()
eq(0, cycle_scroller(max_results, max_results, max_results + 1))
end)
it("should cycle when current results is less than max_results", function()
eq(0, cycle_scroller(max_results, 5, 7))
end)
end)
describe("ascending limit", function()
local limit_scroller = p_scroller.create("limit", "ascending")
it("should return values within the max results", function()
eq(5, limit_scroller(max_results, max_results, 5))
end)
it("should return 0 at 0", function()
eq(0, limit_scroller(max_results, max_results, 0))
end)
it("should not cycle", function()
eq(0, limit_scroller(max_results, max_results, -1))
end)
it("should not cycle you to 0 when you go past the results", function()
eq(max_results - 1, limit_scroller(max_results, max_results, max_results + 1))
end)
it("should stay at current results when current results is less than max_results", function()
local current = 5
eq(current - 1, limit_scroller(max_results, current, 7))
end)
end)
describe("descending cycle", function()
local cycle_scroller = p_scroller.create("cycle", "descending")
it("should return values within the max results", function()
eq(5, cycle_scroller(max_results, max_results, 5))
end)
it("should return max_results - 1 at 0", function()
eq(0, cycle_scroller(max_results, max_results, 0))
end)
it("should cycle you to the bot when you go below 0", function()
eq(max_results - 1, cycle_scroller(max_results, max_results, -1))
end)
it("should cycle you to 0 when you go past the results", function()
eq(0, cycle_scroller(max_results, max_results, max_results + 1))
end)
it("should cycle when current results is less than max_results", function()
eq(9, cycle_scroller(max_results, 5, 4))
end)
end)
describe("descending limit", function()
local limit_scroller = p_scroller.create("limit", "descending")
it("should return values within the max results", function()
eq(5, limit_scroller(max_results, max_results, 5))
end)
it("should return 0 at 0", function()
eq(0, limit_scroller(max_results, max_results, 0))
end)
it("should not cycle", function()
eq(0, limit_scroller(max_results, max_results, -1))
end)
it("should not cycle you to 0 when you go past the results", function()
eq(max_results - 1, limit_scroller(max_results, max_results, max_results + 1))
end)
it("should stay at current results when current results is less than max_results", function()
local current = 5
eq(max_results - current, limit_scroller(max_results, current, 4))
end)
end)
describe("https://github.com/nvim-telescope/telescope.nvim/pull/293#issuecomment-751463224", function()
it("should handle having many more results than necessary", function()
local scroller = p_scroller.create("cycle", "descending")
-- 23 112 23
eq(0, scroller(23, 112, 23))
end)
end)
describe("should give top, middle and bottom index", function()
it("should handle ascending", function()
eq(0, p_scroller.top("ascending", 20, 1000))
eq(19, p_scroller.bottom("ascending", 20, 1000))
eq(0, p_scroller.top("ascending", 20, 10))
eq(9, p_scroller.bottom("ascending", 20, 10))
eq(5, p_scroller.middle("ascending", 11, 100))
eq(10, p_scroller.middle("ascending", 20, 100))
eq(12, p_scroller.middle("ascending", 25, 100))
end)
it("should handle descending", function()
eq(0, p_scroller.top("descending", 20, 1000))
eq(19, p_scroller.bottom("descending", 20, 1000))
eq(10, p_scroller.top("descending", 20, 10))
eq(19, p_scroller.bottom("descending", 20, 10))
eq(25, p_scroller.middle("descending", 30, 10))
eq(50, p_scroller.middle("descending", 60, 20))
eq(105, p_scroller.middle("descending", 120, 30))
end)
end)
end)