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