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:
142
lua/tests/automated/entry_manager_spec.lua
Normal file
142
lua/tests/automated/entry_manager_spec.lua
Normal file
@@ -0,0 +1,142 @@
|
||||
local EntryManager = require('telescope.entry_manager')
|
||||
|
||||
local eq = assert.are.same
|
||||
|
||||
describe('process_result', function()
|
||||
it('works with one entry', function()
|
||||
local manager = EntryManager:new(5, nil)
|
||||
|
||||
manager:add_entry(nil, 1, "hello")
|
||||
|
||||
eq(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")
|
||||
|
||||
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)
|
||||
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")
|
||||
|
||||
eq("better result", manager:get_entry(1))
|
||||
eq("worse result", manager:get_entry(2))
|
||||
|
||||
eq(2, 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")
|
||||
|
||||
eq("better result", manager:get_entry(1))
|
||||
eq(1, called_count)
|
||||
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,
|
||||
}))
|
||||
|
||||
eq("wow", manager:get_ordinal(1))
|
||||
eq("wow", manager:get_ordinal(1))
|
||||
eq("wow", manager:get_ordinal(1))
|
||||
|
||||
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")
|
||||
manager:add_entry(nil, 3, "result 3")
|
||||
manager:add_entry(nil, 4, "result 4")
|
||||
|
||||
eq(3, manager.worst_acceptable_score)
|
||||
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")
|
||||
|
||||
-- Once for insert 5
|
||||
-- Once for prepend 4
|
||||
-- Once for prepend 2
|
||||
eq(3, called_count)
|
||||
|
||||
eq("better result", manager:get_entry(1))
|
||||
eq(4, manager.worst_acceptable_score)
|
||||
end)
|
||||
end)
|
||||
133
lua/tests/automated/linked_list_spec.lua
Normal file
133
lua/tests/automated/linked_list_spec.lua
Normal file
@@ -0,0 +1,133 @@
|
||||
local LinkedList = require('telescope.algos.linked_list')
|
||||
|
||||
describe('LinkedList', function()
|
||||
it('can create a list', function()
|
||||
local l = LinkedList:new()
|
||||
|
||||
assert.are.same(0, l.size)
|
||||
end)
|
||||
|
||||
it('can add a single entry to the list', function()
|
||||
local l = LinkedList:new()
|
||||
l:append('hello')
|
||||
|
||||
assert.are.same(1, l.size)
|
||||
end)
|
||||
|
||||
it('can iterate over one item', function()
|
||||
local l = LinkedList:new()
|
||||
l:append('hello')
|
||||
|
||||
for val in l:iter() do
|
||||
assert.are.same('hello', val)
|
||||
end
|
||||
end)
|
||||
|
||||
it('iterates in order', function()
|
||||
local l = LinkedList:new()
|
||||
l:append('hello')
|
||||
l:append('world')
|
||||
|
||||
local x = {}
|
||||
for val in l:iter() do
|
||||
table.insert(x, val)
|
||||
end
|
||||
|
||||
assert.are.same({'hello', 'world'}, x)
|
||||
end)
|
||||
|
||||
it('iterates in order, for prepend', function()
|
||||
local l = LinkedList:new()
|
||||
l:prepend('world')
|
||||
l:prepend('hello')
|
||||
|
||||
local x = {}
|
||||
for val in l:iter() do
|
||||
table.insert(x, val)
|
||||
end
|
||||
|
||||
assert.are.same({'hello', 'world'}, x)
|
||||
end)
|
||||
|
||||
it('iterates in order, for combo', function()
|
||||
local l = LinkedList:new()
|
||||
l:prepend('world')
|
||||
l:prepend('hello')
|
||||
l:append('last')
|
||||
l:prepend('first')
|
||||
|
||||
local x = {}
|
||||
for val in l:iter() do
|
||||
table.insert(x, val)
|
||||
end
|
||||
|
||||
assert.are.same({'first', 'hello', 'world', 'last'}, x)
|
||||
assert.are.same(#x, l.size)
|
||||
end)
|
||||
|
||||
it('has ipairs', function()
|
||||
local l = LinkedList:new()
|
||||
l:prepend('world')
|
||||
l:prepend('hello')
|
||||
l:append('last')
|
||||
l:prepend('first')
|
||||
|
||||
local x = {}
|
||||
for v in l:iter() do
|
||||
table.insert(x, v)
|
||||
end
|
||||
assert.are.same({'first', 'hello', 'world', 'last'}, x)
|
||||
|
||||
local expected = {}
|
||||
for i, v in ipairs(x) do
|
||||
table.insert(expected, {i, v})
|
||||
end
|
||||
|
||||
local actual = {}
|
||||
for i, v in l:ipairs() do
|
||||
table.insert(actual, {i, v})
|
||||
end
|
||||
|
||||
assert.are.same(expected, actual)
|
||||
end)
|
||||
|
||||
describe('track_at', function()
|
||||
it('should update tracked when only appending', function()
|
||||
local l = LinkedList:new { track_at = 2 }
|
||||
l:append("first")
|
||||
l:append("second")
|
||||
l:append("third")
|
||||
|
||||
assert.are.same("second", l.tracked)
|
||||
end)
|
||||
|
||||
it('should update tracked when first some prepend and then append', function()
|
||||
local l = LinkedList:new { track_at = 2 }
|
||||
l:prepend("first")
|
||||
l:append("second")
|
||||
l:append("third")
|
||||
|
||||
assert.are.same("second", l.tracked)
|
||||
end)
|
||||
|
||||
it('should update when only prepending', function()
|
||||
local l = LinkedList:new { track_at = 2 }
|
||||
l:prepend("third")
|
||||
l:prepend("second")
|
||||
l:prepend("first")
|
||||
|
||||
assert.are.same("second", l.tracked)
|
||||
end)
|
||||
|
||||
it('should update when lots of prepend and append', function()
|
||||
local l = LinkedList:new { track_at = 2 }
|
||||
l:prepend("third")
|
||||
l:prepend("second")
|
||||
l:prepend("first")
|
||||
l:append("fourth")
|
||||
l:prepend("zeroth")
|
||||
|
||||
assert.are.same("first", l.tracked)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -2,6 +2,10 @@ require('plenary.reload').reload_module('telescope')
|
||||
|
||||
local tester = require('telescope.pickers._test')
|
||||
|
||||
local disp = function(val)
|
||||
return vim.inspect(val, { newline = " ", indent = "" })
|
||||
end
|
||||
|
||||
describe('builtin.find_files', function()
|
||||
it('should find the readme', function()
|
||||
tester.run_file('find_files__readme')
|
||||
@@ -11,45 +15,76 @@ describe('builtin.find_files', function()
|
||||
tester.run_file('find_files__with_ctrl_n')
|
||||
end)
|
||||
|
||||
it('should not display devicons when disabled', function()
|
||||
tester.run_string [[
|
||||
tester.builtin_picker('find_files', 'README.md', {
|
||||
post_typed = {
|
||||
{ "> README.md", GetPrompt },
|
||||
{ "> README.md", GetLastResult },
|
||||
},
|
||||
post_close = {
|
||||
{ 'README.md', GetFile },
|
||||
{ 'README.md', GetFile },
|
||||
}
|
||||
}, {
|
||||
disable_devicons = true,
|
||||
sorter = require('telescope.sorters').get_fzy_sorter(),
|
||||
})
|
||||
]]
|
||||
end)
|
||||
for _, configuration in ipairs {
|
||||
{ sorting_strategy = 'descending', },
|
||||
{ sorting_strategy = 'ascending', },
|
||||
} do
|
||||
it('should not display devicons when disabled: ' .. disp(configuration), function()
|
||||
tester.run_string(string.format([[
|
||||
local max_results = 5
|
||||
|
||||
it('use devicons, if it has it when enabled', function()
|
||||
if not pcall(require, 'nvim-web-devicons') then
|
||||
return
|
||||
end
|
||||
tester.builtin_picker('find_files', 'README.md', {
|
||||
post_typed = {
|
||||
{ "> README.md", GetPrompt },
|
||||
{ "> README.md", GetBestResult },
|
||||
},
|
||||
post_close = {
|
||||
{ 'README.md', GetFile },
|
||||
{ 'README.md', GetFile },
|
||||
}
|
||||
}, vim.tbl_extend("force", {
|
||||
disable_devicons = true,
|
||||
sorter = require('telescope.sorters').get_fzy_sorter(),
|
||||
results_height = max_results,
|
||||
layout_strategy = 'center',
|
||||
}, vim.fn.json_decode([==[%s]==])))
|
||||
]], vim.fn.json_encode(configuration)))
|
||||
end)
|
||||
|
||||
tester.run_string [[
|
||||
tester.builtin_picker('find_files', 'README.md', {
|
||||
post_typed = {
|
||||
{ "> README.md", GetPrompt },
|
||||
{ "> README.md", GetLastResult }
|
||||
},
|
||||
post_close = {
|
||||
{ 'README.md', GetFile },
|
||||
{ 'README.md', GetFile },
|
||||
}
|
||||
}, {
|
||||
disable_devicons = false,
|
||||
sorter = require('telescope.sorters').get_fzy_sorter(),
|
||||
})
|
||||
]]
|
||||
end)
|
||||
it('should only save one line for ascending, but many for descending', function()
|
||||
local expected
|
||||
if configuration.sorting_strategy == 'descending' then
|
||||
expected = 5
|
||||
else
|
||||
expected = 1
|
||||
end
|
||||
|
||||
tester.run_string(string.format([[
|
||||
tester.builtin_picker('find_files', 'README.md', {
|
||||
post_typed = {
|
||||
{ %s, function() return #GetResults() end },
|
||||
},
|
||||
}, vim.tbl_extend("force", {
|
||||
disable_devicons = true,
|
||||
sorter = require('telescope.sorters').get_fzy_sorter(),
|
||||
results_height = 5,
|
||||
layout_strategy = 'center',
|
||||
}, vim.fn.json_decode([==[%s]==])))
|
||||
]], expected, vim.fn.json_encode(configuration)))
|
||||
end)
|
||||
|
||||
it('use devicons, if it has it when enabled', function()
|
||||
if not pcall(require, 'nvim-web-devicons') then
|
||||
return
|
||||
end
|
||||
|
||||
tester.run_string(string.format([[
|
||||
tester.builtin_picker('find_files', 'README.md', {
|
||||
post_typed = {
|
||||
{ "> README.md", GetPrompt },
|
||||
{ "> README.md", GetBestResult }
|
||||
},
|
||||
post_close = {
|
||||
{ 'README.md', GetFile },
|
||||
{ 'README.md', GetFile },
|
||||
}
|
||||
}, vim.tbl_extend("force", {
|
||||
disable_devicons = false,
|
||||
sorter = require('telescope.sorters').get_fzy_sorter(),
|
||||
}, vim.fn.json_decode([==[%s]==])))
|
||||
]], vim.fn.json_encode(configuration)))
|
||||
end)
|
||||
end
|
||||
|
||||
it('should find the readme, using lowercase', function()
|
||||
tester.run_string [[
|
||||
|
||||
9
lua/tests/automated/pickers/scrolling_spec.lua
Normal file
9
lua/tests/automated/pickers/scrolling_spec.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
require('plenary.reload').reload_module('telescope')
|
||||
|
||||
local tester = require('telescope.pickers._test')
|
||||
|
||||
describe('scrolling strategies', function()
|
||||
it('should handle cycling for full list', function()
|
||||
tester.run_file [[find_files__scrolling_descending_cycle]]
|
||||
end)
|
||||
end)
|
||||
@@ -99,7 +99,16 @@ describe('scroller', function()
|
||||
|
||||
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, 4))
|
||||
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)
|
||||
end)
|
||||
|
||||
@@ -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