utf8_spec.lua 2.3 KB

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