summaryrefslogtreecommitdiff
path: root/lua/tests/automated
diff options
context:
space:
mode:
authorJINNOUCHI Yasushi <me@delphinus.dev>2021-01-31 18:55:17 +0900
committerGitHub <noreply@github.com>2021-01-31 10:55:17 +0100
commit1ca1e7ccba203752f7b7f89c2bd3aca13586d460 (patch)
tree18dca4487c1a34759b3e7a26a6e8e2c93a1a767f /lua/tests/automated
parent4e0dfa2e705cd34b315315ed4740683988ef5403 (diff)
fix: Multi byte truncate for displayer (#464)
This is needed for calling strdisplaywidth() from Lua loop. See https://github.com/nvim-telescope/telescope.nvim/issues/414 See https://github.com/neovim/neovim/blob/a1ed941a7881122fda2fd48e71e890ed55e4d08e/src/nvim/eval/funcs.c#L9845-L9858 Co-authored-by: Simon Hauser <Simon-Hauser@outlook.de>
Diffstat (limited to 'lua/tests/automated')
-rw-r--r--lua/tests/automated/entry_display_spec.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/lua/tests/automated/entry_display_spec.lua b/lua/tests/automated/entry_display_spec.lua
new file mode 100644
index 0000000..fff78cd
--- /dev/null
+++ b/lua/tests/automated/entry_display_spec.lua
@@ -0,0 +1,32 @@
+local entry_display = require('telescope.pickers.entry_display')
+
+describe('truncate', function()
+ for _, ambiwidth in ipairs{'single', 'double'} do
+ for _, case in ipairs{
+ {args = {'abcde', 6}, expected = {single = 'abcde', double = 'abcde'}},
+ {args = {'abcde', 5}, expected = {single = 'abcde', double = 'abcde'}},
+ {args = {'abcde', 4}, expected = {single = 'abc…', double = 'ab…'}},
+ {args = {'アイウエオ', 11}, expected = {single = 'アイウエオ', double = 'アイウエオ'}},
+ {args = {'アイウエオ', 10}, expected = {single = 'アイウエオ', double = 'アイウエオ'}},
+ {args = {'アイウエオ', 9}, expected = {single = 'アイウエ…', double = 'アイウ…'}},
+ {args = {'アイウエオ', 8}, expected = {single = 'アイウ…', double = 'アイウ…'}},
+ {args = {'├─┤', 7}, expected = {single = '├─┤', double = '├─┤'}},
+ {args = {'├─┤', 6}, expected = {single = '├─┤', double = '├─┤'}},
+ {args = {'├─┤', 5}, expected = {single = '├─┤', double = '├…'}},
+ {args = {'├─┤', 4}, expected = {single = '├─┤', double = '├…'}},
+ {args = {'├─┤', 3}, expected = {single = '├─┤', double = '…'}},
+ {args = {'├─┤', 2}, expected = {single = '├…', double = '…'}},
+ } do
+ local msg = ('can truncate: ambiwidth = %s, [%s, %d] -> %s'):format(ambiwidth, case.args[1], case.args[2], case.expected[ambiwidth])
+ it(msg, function()
+ local original = vim.o.ambiwidth
+ vim.o.ambiwidth = ambiwidth
+ assert.are.same(
+ case.expected[ambiwidth],
+ entry_display.truncate(case.args[1], case.args[2])
+ )
+ vim.o.ambiwidth = original
+ end)
+ end
+ end
+end)