diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2020-10-08 23:48:29 -0400 |
|---|---|---|
| committer | TJ DeVries <devries.timothyj@gmail.com> | 2020-10-08 23:48:29 -0400 |
| commit | ad12bf03d12660d04bb9d5fa13cc057e98a2ace4 (patch) | |
| tree | bc892c46116c69c39061bfaa09a12674cb9c98e5 /lua/tests/manual | |
| parent | 8c0f2630a00c97e62552203487494329332cdd14 (diff) | |
feat: Add a test file
Diffstat (limited to 'lua/tests/manual')
| -rw-r--r-- | lua/tests/manual/auto_picker.lua | 13 | ||||
| -rw-r--r-- | lua/tests/manual/find_and_sort_spec.lua | 115 |
2 files changed, 121 insertions, 7 deletions
diff --git a/lua/tests/manual/auto_picker.lua b/lua/tests/manual/auto_picker.lua index 141eee4..e0433f9 100644 --- a/lua/tests/manual/auto_picker.lua +++ b/lua/tests/manual/auto_picker.lua @@ -1,15 +1,14 @@ 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 {} + opts.prompt_prefix = '' local find_command = opts.find_command @@ -56,8 +55,9 @@ local find_files = function(opts) count = count + 1 end) - local feed = function(text) - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(text, true, false, true), 'n', true) + local feed = function(text, feed_opts) + feed_opts = feed_opts or 'n' + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(text, true, false, true), feed_opts, true) end p:register_completion_callback(coroutine.wrap(function() @@ -68,10 +68,9 @@ local find_files = function(opts) end vim.wait(300, function() end) + feed("<CR>", '') - vim.cmd [[:q]] - vim.cmd [[:Messages]] - vim.cmd [[stopinsert]] + coroutine.yield() end)) p:find() diff --git a/lua/tests/manual/find_and_sort_spec.lua b/lua/tests/manual/find_and_sort_spec.lua new file mode 100644 index 0000000..841399f --- /dev/null +++ b/lua/tests/manual/find_and_sort_spec.lua @@ -0,0 +1,115 @@ +require('plenary.reload').reload_module('plenary') +require('plenary.reload').reload_module('telescope') + +--[[ + +Goals: +1. Easily test a sorter and finder to make sure we get all the results we need. + +--]] + +local finders = require('telescope.finders') +local make_entry = require('telescope.make_entry') +local pickers = require('telescope.pickers') +local sorters = require('telescope.sorters') +local EntryManager = require('telescope.entry_manager') + +local find_and_sort_test = function(prompt, f, s) + local info = {} + + local start = vim.loop.hrtime() + + info.filtered = 0 + info.added = 0 + info.scoring_time = 0 + info.set_entry = 0 + + local entry_manager = EntryManager:new(25, function() + info.set_entry = info.set_entry + 1 + end, info) + + local completed = false + + local process_result = function(entry) + local score_start = vim.loop.hrtime() + local score = s:score(prompt, entry) + info.scoring_time = info.scoring_time + (vim.loop.hrtime() - score_start) / 1e9 + + -- Filter these out here. + if score == -1 then + info.filtered = info.filtered + 1 + return + end + + info.added = info.added + 1 + entry_manager:add_entry( + s:score(prompt, entry), + entry + ) + end + + local process_complete = function() + info.time = (vim.loop.hrtime() - start) / 1e9 + + info.total = info.filtered + info.added + completed = true + end + + f(prompt, process_result, process_complete) + + -- Wait until we're done to return + vim.wait(5000, function() return completed end, 10) + + return entry_manager, info +end + +local info_to_csv = function(info, filename) + local writer = io.open(filename, "a") + + writer:write(string.format("%.8f", info.scoring_time) .. "\t") + writer:write(string.format("%.8f", info.time) .. "\t") + writer:write(info.looped .. "\t") + writer:write(info.filtered .. "\t") + writer:write(info.added .. "\t") + writer:write(info.inserted .. "\t") + writer:write(info.total .. "\t") + writer:write(info.set_entry .. "\t") + writer:write(string.format("%.0f", collectgarbage("count")) .. "\t") + writer:write("\n") + + writer:close() +end + + +local cwd = vim.fn.expand("~/build/neovim") + +collectgarbage("collect") +for _ = 1, 1 do + + -- local s = sorters.get_fuzzy_file() + local s = sorters.get_generic_fuzzy_sorter() + local finder = finders.new_oneshot_job( + {"fdfind"}, + { + cwd = cwd, + entry_maker = make_entry.gen_from_file {cwd = cwd}, + -- disable_devicons = true, + -- maximum_results = 1000, + } + ) + + local res, info = find_and_sort_test( + "pickers.lua", + finder, + s + ) + + -- print(vim.inspect(res:get_entry(1))) + -- print(vim.inspect(info)) + + info_to_csv(info, "/home/tj/tmp/profile.csv") + + collectgarbage("collect") +end +-- No skip: 2,206,186 +-- Ya skip: 2,133 |
