mirror of
https://github.com/zoriya/telescope.nvim.git
synced 2025-12-06 06:46:10 +00:00
feat: quickfix (#293)
* feat: quickfix (not implemented) * [WIP]: Wed 09 Dec 2020 11:11:30 PM EST * somewhat working linked list impl * getting closer * might be working * might be working for real * works and implemented basic example * dont forget to close prompt * fix descending and add more tests * test fixes * fix test * more logging * Fix some more tests * Fix logging messing up tests * fix: lint * fix: multi select stuffs
This commit is contained in:
@@ -4,8 +4,6 @@ local log = require('telescope.log')
|
||||
log.level = 'info'
|
||||
-- log.use_console = false
|
||||
|
||||
local EntryManager = require('telescope.entry_manager')
|
||||
|
||||
--[[
|
||||
lua RELOAD('plenary'); require("plenary.test_harness"):test_directory("busted", "./tests/automated")
|
||||
--]]
|
||||
@@ -16,103 +14,6 @@ describe('Picker', function()
|
||||
assert(true)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('process_result', function()
|
||||
it('works with one entry', function()
|
||||
local manager = EntryManager:new(5, nil)
|
||||
|
||||
manager:add_entry(nil, 1, "hello")
|
||||
|
||||
assert.are.same(1, manager:get_score(1))
|
||||
end)
|
||||
|
||||
it('works with two entries', function()
|
||||
local manager = EntryManager:new(5, nil)
|
||||
|
||||
manager:add_entry(nil, 1, "hello")
|
||||
manager:add_entry(nil, 2, "later")
|
||||
|
||||
assert.are.same("hello", manager:get_entry(1))
|
||||
assert.are.same("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)
|
||||
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")
|
||||
|
||||
assert.are.same("better result", manager:get_entry(1))
|
||||
assert.are.same("worse result", manager:get_entry(2))
|
||||
|
||||
-- once to insert "worse"
|
||||
-- once to insert "better"
|
||||
-- and then to move "worse"
|
||||
assert.are.same(3, called_count)
|
||||
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")
|
||||
|
||||
assert.are.same("better result", manager:get_entry(1))
|
||||
assert.are.same(1, called_count)
|
||||
end)
|
||||
|
||||
-- TODO: We should decide if we want to add this or not.
|
||||
-- it('should handle no scores', function()
|
||||
-- local manager = EntryManager:new(5, nil)
|
||||
|
||||
-- manager:add_entry(nil,
|
||||
-- end)
|
||||
|
||||
it('should allow simple entries', function()
|
||||
local manager = EntryManager:new(5)
|
||||
|
||||
local counts_executed = 0
|
||||
manager:add_entry(nil, 1, setmetatable({}, {
|
||||
__index = function(t, k)
|
||||
local val = nil
|
||||
if k == "ordinal" then
|
||||
counts_executed = counts_executed + 1
|
||||
|
||||
-- This could be expensive, only call later
|
||||
val = "wow"
|
||||
end
|
||||
|
||||
rawset(t, k, val)
|
||||
return val
|
||||
end,
|
||||
}))
|
||||
|
||||
assert.are.same("wow", manager:get_ordinal(1))
|
||||
assert.are.same("wow", manager:get_ordinal(1))
|
||||
assert.are.same("wow", manager:get_ordinal(1))
|
||||
|
||||
assert.are.same(1, counts_executed)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('Sorters', function()
|
||||
|
||||
Reference in New Issue
Block a user