aboutsummaryrefslogtreecommitdiff
path: root/test/functional/legacy/utf8_spec.lua
blob: c16b1c45f4d2caf26fbb45bcec4e2a6a2c2daa35 (plain) (blame)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- Tests for Unicode manipulations

local helpers = require('test.functional.helpers')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local execute, expect = helpers.execute, helpers.expect
local eq, eval = helpers.eq, helpers.eval

describe('utf8', function()
  setup(clear)

  it('is working', function()
    insert('start:')

    execute('new')
    execute('call setline(1, ["aaa", "あああ", "bbb"])')

    -- Visual block Insert adjusts for multi-byte char
    feed('gg0l<C-V>jjIx<Esc>')

    execute('let r = getline(1, "$")')
    execute('bwipeout!')
    execute('$put=r')
    execute('call garbagecollect(1)')

    expect([[
      start:
      axaa
      xあああ
      bxbb]])
  end)

  it('strchars()', function()
    eq(1, eval('strchars("a")'))
    eq(1, eval('strchars("a", 0)'))
    eq(1, eval('strchars("a", 1)'))

    eq(3, eval('strchars("あいa")'))
    eq(3, eval('strchars("あいa", 0)'))
    eq(3, eval('strchars("あいa", 1)'))

    eq(2, eval('strchars("A\\u20dd")'))
    eq(2, eval('strchars("A\\u20dd", 0)'))
    eq(1, eval('strchars("A\\u20dd", 1)'))

    eq(3, eval('strchars("A\\u20dd\\u20dd")'))
    eq(3, eval('strchars("A\\u20dd\\u20dd", 0)'))
    eq(1, eval('strchars("A\\u20dd\\u20dd", 1)'))

    eq(1, eval('strchars("\\u20dd")'))
    eq(1, eval('strchars("\\u20dd", 0)'))
    eq(1, eval('strchars("\\u20dd", 1)'))
  end)
end)