diff options
Diffstat (limited to 'lua/tests')
| -rw-r--r-- | lua/tests/automated/find_and_sort_spec.lua | 2 | ||||
| -rw-r--r-- | lua/tests/automated/telescope_spec.lua | 23 | ||||
| -rw-r--r-- | lua/tests/manual/auto_picker.lua | 80 | ||||
| -rw-r--r-- | lua/tests/manual/large_search.lua | 4 | ||||
| -rw-r--r-- | lua/tests/manual/slow_oneshot.lua | 71 |
5 files changed, 160 insertions, 20 deletions
diff --git a/lua/tests/automated/find_and_sort_spec.lua b/lua/tests/automated/find_and_sort_spec.lua index 9e6b4cf..b1271f4 100644 --- a/lua/tests/automated/find_and_sort_spec.lua +++ b/lua/tests/automated/find_and_sort_spec.lua @@ -1,8 +1,6 @@ require('plenary.reload').reload_module('plenary') require('plenary.reload').reload_module('telescope') -PERF = function() end - --[[ Goals: diff --git a/lua/tests/automated/telescope_spec.lua b/lua/tests/automated/telescope_spec.lua index 3589a22..5ec3141 100644 --- a/lua/tests/automated/telescope_spec.lua +++ b/lua/tests/automated/telescope_spec.lua @@ -6,8 +6,7 @@ local log = require('telescope.log') log.level = 'info' -- log.use_console = false -local pickers = require('telescope.pickers') -local utils = require('telescope.utils') +local EntryManager = require('telescope.entry_manager') --[[ lua RELOAD('plenary'); require("plenary.test_harness"):test_directory("busted", "./tests/automated") @@ -22,7 +21,7 @@ describe('Picker', function() describe('process_result', function() it('works with one entry', function() - local manager = pickers.entry_manager(5, nil) + local manager = EntryManager:new(5, nil) manager:add_entry(1, "hello") @@ -30,7 +29,7 @@ describe('Picker', function() end) it('works with two entries', function() - local manager = pickers.entry_manager(5, nil) + local manager = EntryManager:new(5, nil) manager:add_entry(1, "hello") manager:add_entry(2, "later") @@ -41,7 +40,7 @@ describe('Picker', function() it('calls functions when inserting', function() local called_count = 0 - local manager = pickers.entry_manager(5, function() called_count = called_count + 1 end) + local manager = EntryManager:new(5, function() called_count = called_count + 1 end) assert(called_count == 0) manager:add_entry(1, "hello") @@ -50,7 +49,7 @@ describe('Picker', function() it('calls functions when inserting twice', function() local called_count = 0 - local manager = pickers.entry_manager(5, function() called_count = called_count + 1 end) + local manager = EntryManager:new(5, function() called_count = called_count + 1 end) assert(called_count == 0) manager:add_entry(1, "hello") @@ -60,7 +59,7 @@ describe('Picker', function() it('correctly sorts lower scores', function() local called_count = 0 - local manager = pickers.entry_manager(5, function() called_count = called_count + 1 end) + local manager = EntryManager:new(5, function() called_count = called_count + 1 end) manager:add_entry(5, "worse result") manager:add_entry(2, "better result") @@ -75,27 +74,23 @@ describe('Picker', function() it('respects max results', function() local called_count = 0 - local manager = pickers.entry_manager(1, function() called_count = called_count + 1 end) + local manager = EntryManager:new(1, function() called_count = called_count + 1 end) manager:add_entry(2, "better result") manager:add_entry(5, "worse result") assert.are.same("better result", manager:get_entry(1)) - - -- once to insert "worse" - -- once to insert "better" - -- and then to move "worse" 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 = pickers.entry_manager(5, nil) + -- local manager = EntryManager:new(5, nil) -- manager:add_entry(nil, -- end) it('should allow simple entries', function() - local manager = pickers.entry_manager(5) + local manager = EntryManager:new(5) local counts_executed = 0 manager:add_entry(1, setmetatable({}, { diff --git a/lua/tests/manual/auto_picker.lua b/lua/tests/manual/auto_picker.lua new file mode 100644 index 0000000..141eee4 --- /dev/null +++ b/lua/tests/manual/auto_picker.lua @@ -0,0 +1,80 @@ +RELOAD('telescope') + +local actions = require('telescope.actions') +local finders = require('telescope.finders') +local make_entry = require('telescope.make_entry') +local previewers = require('telescope.previewers') +local pickers = require('telescope.pickers') +local sorters = require('telescope.sorters') +local utils = require('telescope.utils') + +local find_files = function(opts) + opts = opts or {} + + local find_command = opts.find_command + + if not find_command then + if 1 == vim.fn.executable("fd") then + find_command = { 'fd', '--type', 'f' } + elseif 1 == vim.fn.executable("fdfind") then + find_command = { 'fdfind', '--type', 'f' } + elseif 1 == vim.fn.executable("rg") then + find_command = { 'rg', '--files' } + end + end + + if opts.cwd then + opts.cwd = vim.fn.expand(opts.cwd) + end + + opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts) + + local p = pickers.new(opts, { + prompt = 'Find Files', + finder = finders.new_oneshot_job( + find_command, + opts + ), + previewer = previewers.cat.new(opts), + sorter = sorters.get_fuzzy_file(), + + track = true, + }) + + local count = 0 + p:register_completion_callback(function(s) + print(count, vim.inspect(s.stats, { + process = function(item) + if type(item) == 'string' and item:sub(1, 1) == '_' then + return nil + end + + return item + end, + })) + + count = count + 1 + end) + + local feed = function(text) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(text, true, false, true), 'n', true) + end + + p:register_completion_callback(coroutine.wrap(function() + local input = "pickers.lua" + for i = 1, #input do + feed(input:sub(i, i)) + coroutine.yield() + end + + vim.wait(300, function() end) + + vim.cmd [[:q]] + vim.cmd [[:Messages]] + vim.cmd [[stopinsert]] + end)) + + p:find() +end + +find_files() diff --git a/lua/tests/manual/large_search.lua b/lua/tests/manual/large_search.lua index 3ad6b5a..eda5f16 100644 --- a/lua/tests/manual/large_search.lua +++ b/lua/tests/manual/large_search.lua @@ -7,9 +7,6 @@ local previewers = require('telescope.previewers') local pickers = require('telescope.pickers') local sorters = require('telescope.sorters') -PERF_DEBUG = 182 -vim.api.nvim_buf_set_lines(PERF_DEBUG, 0, -1, false, {}) - local cwd = vim.fn.expand("~/build/neovim") pickers.new { @@ -28,7 +25,6 @@ pickers.new { }:find() -COMPLETED = false -- vim.wait(3000, function() -- vim.cmd [[redraw!]] -- return COMPLETED diff --git a/lua/tests/manual/slow_oneshot.lua b/lua/tests/manual/slow_oneshot.lua new file mode 100644 index 0000000..f97c098 --- /dev/null +++ b/lua/tests/manual/slow_oneshot.lua @@ -0,0 +1,71 @@ +RELOAD('telescope') + +local actions = require('telescope.actions') +local finders = require('telescope.finders') +local make_entry = require('telescope.make_entry') +local previewers = require('telescope.previewers') +local pickers = require('telescope.pickers') +local sorters = require('telescope.sorters') +local utils = require('telescope.utils') + +local slow_proc = function(opts) + opts = opts or {} + + if opts.cwd then + opts.cwd = vim.fn.expand(opts.cwd) + end + + opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts) + + local p = pickers.new(opts, { + prompt = 'Slow Proc', + finder = finders.new_oneshot_job( + {"./scratch/slow_proc.sh"}, + opts + ), + previewer = previewers.cat.new(opts), + sorter = sorters.get_fuzzy_file(), + + track = true, + }) + + local count = 0 + p:register_completion_callback(function(s) + print(count, vim.inspect(s.stats, { + process = function(item) + if type(item) == 'string' and item:sub(1, 1) == '_' then + return nil + end + + return item + end, + })) + + count = count + 1 + end) + + local feed = function(text) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(text, true, false, true), 'n', true) + end + + if false then + p:register_completion_callback(coroutine.wrap(function() + local input = "pickers.lua" + for i = 1, #input do + feed(input:sub(i, i)) + coroutine.yield() + end + + vim.wait(300, function() end) + + vim.cmd [[:q]] + vim.cmd [[:Messages]] + vim.cmd [[stopinsert]] + end)) + end + + + p:find() +end + +slow_proc() |
