summaryrefslogtreecommitdiff
path: root/lua/tests/automated/entry_display_spec.lua
blob: fff78cd71c3ea5433f8f2853d47aaa8bd3d33b41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)