diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2020-12-23 13:31:05 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-23 13:31:05 -0500 |
| commit | 049602a2c5f436fd7758fe5dd2fd1fcea696b83b (patch) | |
| tree | df8297e7904e2f30bfe1a33587269a6794ddb962 /lua/telescope | |
| parent | 4850c6df6d04aa6b98912b1dac9def713b1eda44 (diff) | |
ci: more tests (#359)
* more tests
* lint
Diffstat (limited to 'lua/telescope')
| -rw-r--r-- | lua/telescope/pickers/_test.lua (renamed from lua/telescope/pickers/_tests.lua) | 52 | ||||
| -rw-r--r-- | lua/telescope/pickers/_test_helpers.lua | 50 |
2 files changed, 71 insertions, 31 deletions
diff --git a/lua/telescope/pickers/_tests.lua b/lua/telescope/pickers/_test.lua index b18b810..ddd245a 100644 --- a/lua/telescope/pickers/_tests.lua +++ b/lua/telescope/pickers/_test.lua @@ -30,17 +30,16 @@ tester.picker_feed = function(input, test_cases, debug) end end - vim.wait(100, function() end) + vim.wait(10, function() end) local timer = vim.loop.new_timer() - timer:start(200, 0, vim.schedule_wrap(function() + timer:start(20, 0, vim.schedule_wrap(function() if test_cases.post_close then for k, v in ipairs(test_cases.post_close) do io.stderr:write(vim.fn.json_encode({ case = k, expected = v[1], actual = v[2]() })) io.stderr:write("\n") end end - vim.wait(10) if debug then return @@ -48,7 +47,7 @@ tester.picker_feed = function(input, test_cases, debug) vim.defer_fn(function() vim.cmd [[qa!]] - end, 15) + end, 10) end)) if not debug then @@ -74,10 +73,25 @@ end -- { "README.md", function() return "README.md" end }, -- }, -- } + +local _VALID_KEYS = { + post_typed = true, + post_close = true, +} + tester.builtin_picker = function(key, input, test_cases, opts) opts = opts or {} local debug = opts.debug or false + for k, _ in pairs(test_cases) do + if not _VALID_KEYS[k] then + -- TODO: Make an error type for the json protocol. + io.stderr:write(vim.fn.json_encode({ case = k, expected = '<a valid key>', actual = k })) + io.stderr:write("\n") + vim.cmd [[qa!]] + end + end + opts.on_complete = { tester.picker_feed(input, test_cases, debug) } @@ -119,32 +133,10 @@ tester.run_string = function(contents) local tempname = vim.fn.tempname() contents = [[ - -- TODO: Add globals! - -- local tester = require('telescope.pickers._tests') - local tester = require('telescope.pickers._tests') - - local get_picker = function() - local state = require('telescope.state') - return state.get_status(vim.api.nvim_get_current_buf()).picker - end - - local get_results_bufnr = function() - local state = require('telescope.state') - return state.get_status(vim.api.nvim_get_current_buf()).results_bufnr - end - - local GetFile = function() return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":t") end - - local GetPrompt = function() return vim.api.nvim_buf_get_lines(0, 0, -1, false)[1] end - - local GetResults = function() - return vim.api.nvim_buf_get_lines(get_results_bufnr(), 0, -1, false) - end + local tester = require('telescope.pickers._test') + local helper = require('telescope.pickers._test_helpers') - local GetLastResult = function() - local results = GetResults() - return results[#results] - end + helper.make_globals() ]] .. contents vim.fn.writefile(vim.split(contents, "\n"), tempname) @@ -162,6 +154,4 @@ tester.run_file = function(filename) assert.are.same(result_table.expected, result_table.actual) end - - return tester diff --git a/lua/telescope/pickers/_test_helpers.lua b/lua/telescope/pickers/_test_helpers.lua new file mode 100644 index 0000000..a430fae --- /dev/null +++ b/lua/telescope/pickers/_test_helpers.lua @@ -0,0 +1,50 @@ +local test_helpers = {} + +test_helpers.get_picker = function() + local state = require('telescope.state') + return state.get_status(vim.api.nvim_get_current_buf()).picker +end + +test_helpers.get_results_bufnr = function() + local state = require('telescope.state') + return state.get_status(vim.api.nvim_get_current_buf()).results_bufnr +end + +test_helpers.get_file = function() + return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ":t") +end + +test_helpers.get_prompt = function() + return vim.api.nvim_buf_get_lines(0, 0, -1, false)[1] +end + +test_helpers.get_results = function() + return vim.api.nvim_buf_get_lines(test_helpers.get_results_bufnr(), 0, -1, false) +end + +test_helpers.get_last_result = function() + local results = test_helpers.get_results() + return results[#results] +end + +test_helpers.get_selection = function() + local state = require('telescope.state') + return state.get_global_key('selected_entry') +end + +test_helpers.get_selection_value = function() + return test_helpers.get_selection().value +end + +test_helpers.make_globals = function() + GetFile = test_helpers.get_file -- luacheck: globals GetFile + GetPrompt = test_helpers.get_prompt -- luacheck: globals GetPrompt + + GetResults = test_helpers.get_results -- luacheck: globals GetResults + GetLastResult = test_helpers.get_last_result -- luacheck: globals GetLastResult + + GetSelection = test_helpers.get_selection -- luacheck: globals GetSelection + GetSelectionValue = test_helpers.get_selection_value -- luacheck: globals GetSelectionValue +end + +return test_helpers |
