utf8_spec.lua 2.3 KB

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