robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.4 KiB89 linesraw
1-- Tests for Unicode manipulations
2
3local t = require('test.testutil')
4local n = require('test.functional.testnvim')()
5
6local describe, it, before_each = t.describe, t.it, t.before_each
7local clear, feed, insert = n.clear, n.feed, n.insert
8local command, expect = n.command, n.expect
9local eq, eval = t.eq, n.eval
10local source = n.source
11local poke_eventloop = n.poke_eventloop
12
13describe('utf8', function()
14  before_each(clear)
15
16  it('is working', function()
17    insert('start:')
18
19    command('new')
20    command('call setline(1, ["aaa", "あああ", "bbb"])')
21
22    -- Visual block Insert adjusts for multi-byte char
23    feed('gg0l<C-V>jjIx<Esc>')
24    poke_eventloop()
25
26    command('let r = getline(1, "$")')
27    command('bwipeout!')
28    command('$put=r')
29    command('call garbagecollect(1)')
30
31    expect([[
32      start:
33      axaa
34       xあああ
35      bxbb]])
36  end)
37
38  it('strchars()', function()
39    eq(1, eval('strchars("a")'))
40    eq(1, eval('strchars("a", 0)'))
41    eq(1, eval('strchars("a", 1)'))
42
43    eq(3, eval('strchars("あいa")'))
44    eq(3, eval('strchars("あいa", 0)'))
45    eq(3, eval('strchars("あいa", 1)'))
46
47    eq(2, eval('strchars("A\\u20dd")'))
48    eq(2, eval('strchars("A\\u20dd", 0)'))
49    eq(1, eval('strchars("A\\u20dd", 1)'))
50
51    eq(3, eval('strchars("A\\u20dd\\u20dd")'))
52    eq(3, eval('strchars("A\\u20dd\\u20dd", 0)'))
53    eq(1, eval('strchars("A\\u20dd\\u20dd", 1)'))
54
55    eq(1, eval('strchars("\\u20dd")'))
56    eq(1, eval('strchars("\\u20dd", 0)'))
57    eq(1, eval('strchars("\\u20dd", 1)'))
58  end)
59
60  -- luacheck: ignore 613 (Trailing whitespace in a string)
61  it('customlist completion', function()
62    source([[
63      function! CustomComplete1(lead, line, pos)
64        return ['あ', 'い']
65      endfunction
66      command -nargs=1 -complete=customlist,CustomComplete1 Test1 echo]])
67    feed(":Test1 <C-L>'<C-B>$put='<CR>")
68
69    source([[
70      function! CustomComplete2(lead, line, pos)
71        return ['あたし', 'あたま', 'あたりめ']
72      endfunction
73      command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo]])
74    feed(":Test2 <C-L>'<C-B>$put='<CR>")
75
76    source([[
77      function! CustomComplete3(lead, line, pos)
78        return ['Nこ', 'Nん', 'Nぶ']
79      endfunction
80      command -nargs=1 -complete=customlist,CustomComplete3 Test3 echo]])
81    feed(":Test3 <C-L>'<C-B>$put='<CR>")
82
83    expect([[
84
85      Test1 
86      Test2 あた
87      Test3 N]])
88  end)
89end)