diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2021-07-01 02:41:58 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-01 05:41:58 -0400 |
| commit | 5a53ec5c2fdab10ca8775d3979b1a85e63d57953 (patch) | |
| tree | 40c62f0a260a3328c3b5578c06a729b76d36d5cb /lua/tests | |
| parent | e5bd4963da81b5d044749ee4507061801aeb0f78 (diff) | |
feat: Consistent and sensible layout_config (#922)
* feat: Consistent and sensible layout_config
* [docgen] Update doc/telescope.txt
skip-checks: true
* [WIP]: Thu 17 Jun 2021 03:36:44 PM EDT
* [WIP]: Thu 17 Jun 2021 03:38:11 PM EDT
* layout_default -> layout_defaults
* remove options from bug repot
* Conni2461 suggestions: part 1
* [docgen] Update doc/telescope.txt
skip-checks: true
* Conni2461 suggestions: part 2
* [docgen] Update doc/telescope.txt
skip-checks: true
* Linting
* Improve deprecation checks
- Move `layout_defaults` handling to `deprecated.lua`
- Check for "layout keys" outside of `layout_config` on `setup`
* fixup: Just add a few more words
Co-authored-by: Luke Kershaw <35707277+l-kershaw@users.noreply.github.com>
Co-authored-by: Github Actions <actions@github>
Diffstat (limited to 'lua/tests')
| -rw-r--r-- | lua/tests/automated/layout_strategies_spec.lua | 92 | ||||
| -rw-r--r-- | lua/tests/automated/pickers/find_files_spec.lua | 10 |
2 files changed, 100 insertions, 2 deletions
diff --git a/lua/tests/automated/layout_strategies_spec.lua b/lua/tests/automated/layout_strategies_spec.lua new file mode 100644 index 0000000..a4d2c50 --- /dev/null +++ b/lua/tests/automated/layout_strategies_spec.lua @@ -0,0 +1,92 @@ +-- local tester = require('telescope.pickers._test') +local config = require('telescope.config') +local resolve = require('telescope.config.resolve') +local layout_strats = require('telescope.pickers.layout_strategies') + +local validate_layout_config = layout_strats._validate_layout_config + +local eq = assert.are.same + +describe('layout_strategies', function() + it('should have validator', function() + assert(validate_layout_config, "Has validator") + end) + + local test_height = function(should, output, input, opts) + opts = opts or {} + + local max_columns, max_lines = opts.max_columns or 100, opts.max_lines or 100 + it(should, function() + local layout_config = validate_layout_config("horizontal", { height = true }, { height = input }) + + eq(output, resolve.resolve_height(layout_config.height)({}, max_columns, max_lines)) + end) + end + + test_height('should handle numbers', 10, 10) + + test_height('should handle percentage: 100', 10, 0.1, { max_lines = 100 }) + test_height('should handle percentage: 110', 11, 0.1, { max_lines = 110 }) + + test_height('should call functions: simple', 5, function() return 5 end) + test_height('should call functions: percentage', 15, function(_, _, lines) return 0.1 * lines end, { max_lines = 150 }) + + local test_defaults_key = function(should, key, strat, output, ours, theirs, override) + ours = ours or {} + theirs = theirs or {} + override = override or {} + + it(should, function() + config.clear_defaults() + config.set_defaults({layout_config=theirs}, {layout_config={ours,'description'}}) + local layout_config = validate_layout_config(strat, layout_strats._configurations[strat], override) + eq(output, layout_config[key]) + end) + end + + test_defaults_key("should use ours if theirs and override don't give the key", + 'height','horizontal',50, + {height=50}, {width=100}, {width=120} + ) + + test_defaults_key("should use ours if theirs and override don't give the key for this strategy", + 'height','horizontal',50, + {height=50}, {vertical={height=100}}, {vertical={height=120}} + ) + + test_defaults_key("should use theirs if override doesn't give the key", + 'height','horizontal',100, + {height=50}, {height=100}, {width=120} + ) + + test_defaults_key("should use override if key given", + 'height','horizontal',120, + {height=50}, {height=100}, {height=120} + ) + + test_defaults_key("should use override if key given for this strategy", + 'height','horizontal',120, + {height=50}, {height=100}, {horizontal={height=120}} + ) + + test_defaults_key("should use theirs if override doesn't give key (even if ours has strategy specific)", + 'height','horizontal',100, + {horizontal={height=50}}, {height=100}, {width=120} + ) + + test_defaults_key("should use override (even if ours has strategy specific)", + 'height','horizontal',120, + {horizontal={height=50}}, {height=100}, {height=120} + ) + + test_defaults_key("should use override (even if theirs has strategy specific)", + 'height','horizontal',120, + {height=50}, {horizontal={height=100}}, {height=120} + ) + + test_defaults_key("should use override (even if ours and theirs have strategy specific)", + 'height','horizontal',120, + {horizontal={height=50}}, {horizontal={height=100}}, {height=120} + ) + +end) diff --git a/lua/tests/automated/pickers/find_files_spec.lua b/lua/tests/automated/pickers/find_files_spec.lua index b3af1d6..b01dc51 100644 --- a/lua/tests/automated/pickers/find_files_spec.lua +++ b/lua/tests/automated/pickers/find_files_spec.lua @@ -35,8 +35,11 @@ describe('builtin.find_files', function() }, vim.tbl_extend("force", { disable_devicons = true, sorter = require('telescope.sorters').get_fzy_sorter(), - results_height = max_results, layout_strategy = 'center', + layout_config = { + height = max_results, + width = 0.9, + }, }, vim.fn.json_decode([==[%s]==]))) ]], vim.fn.json_encode(configuration))) end) @@ -57,8 +60,11 @@ describe('builtin.find_files', function() }, vim.tbl_extend("force", { disable_devicons = true, sorter = require('telescope.sorters').get_fzy_sorter(), - results_height = 5, layout_strategy = 'center', + layout_config = { + height = max_results, + width = 0.9, + }, }, vim.fn.json_decode([==[%s]==]))) ]], expected, vim.fn.json_encode(configuration))) end) |
