diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2022-08-04 16:00:30 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-04 16:00:30 -0400 |
| commit | 4725867ec66b9a0f5e5ad95a1fd94c2f97fa2d2c (patch) | |
| tree | f4dcf668bb66469273e630f69eebe123d390f2c0 /lua/telescope/testharness/helpers.lua | |
| parent | 75a5e5065376d9103fc4bafc3ae6327304cee6e9 (diff) | |
fix: restore testing framework to actually work (#2070)
after refactor to some new asynchronous items for finders,
the tests stopped actually doing anything.
now they do things again.
Diffstat (limited to 'lua/telescope/testharness/helpers.lua')
| -rw-r--r-- | lua/telescope/testharness/helpers.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lua/telescope/testharness/helpers.lua b/lua/telescope/testharness/helpers.lua new file mode 100644 index 0000000..5296c45 --- /dev/null +++ b/lua/telescope/testharness/helpers.lua @@ -0,0 +1,56 @@ +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_best_result = function() + local results = test_helpers.get_results() + local picker = test_helpers.get_picker() + + if picker.sorting_strategy == "ascending" then + return results[1] + else + return results[#results] + end +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 + GetBestResult = test_helpers.get_best_result -- luacheck: globals GetBestResult + + GetSelection = test_helpers.get_selection -- luacheck: globals GetSelection + GetSelectionValue = test_helpers.get_selection_value -- luacheck: globals GetSelectionValue +end + +return test_helpers |
