xref: /vim-8.2.3635/src/testdir/test_utf8.vim (revision 01a6c216)
1" Tests for Unicode manipulations
2
3
4" Visual block Insert adjusts for multi-byte char
5func Test_visual_block_insert()
6  new
7  call setline(1, ["aaa", "あああ", "bbb"])
8  exe ":norm! gg0l\<C-V>jjIx\<Esc>"
9  call assert_equal(['axaa', 'xあああ', 'bxbb'], getline(1, '$'))
10  bwipeout!
11endfunc
12
13" Test for built-in function strchars()
14func Test_strchars()
15  let inp = ["a", "あいa", "A\u20dd", "A\u20dd\u20dd", "\u20dd"]
16  let exp = [[1, 1, 1], [3, 3, 3], [2, 2, 1], [3, 3, 1], [1, 1, 1]]
17  for i in range(len(inp))
18    call assert_equal(exp[i][0], strchars(inp[i]))
19    call assert_equal(exp[i][1], strchars(inp[i], 0))
20    call assert_equal(exp[i][2], strchars(inp[i], 1))
21  endfor
22endfunc
23
24" Test for customlist completion
25func CustomComplete1(lead, line, pos)
26	return ['あ', 'い']
27endfunc
28
29func CustomComplete2(lead, line, pos)
30	return ['あたし', 'あたま', 'あたりめ']
31endfunc
32
33func CustomComplete3(lead, line, pos)
34	return ['Nこ', 'Nん', 'Nぶ']
35endfunc
36
37func Test_customlist_completion()
38  command -nargs=1 -complete=customlist,CustomComplete1 Test1 echo
39  call feedkeys(":Test1 \<C-L>\<C-B>\"\<CR>", 'itx')
40  call assert_equal('"Test1 ', getreg(':'))
41
42  command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
43  call feedkeys(":Test2 \<C-L>\<C-B>\"\<CR>", 'itx')
44  call assert_equal('"Test2 あた', getreg(':'))
45
46  command -nargs=1 -complete=customlist,CustomComplete3 Test3 echo
47  call feedkeys(":Test3 \<C-L>\<C-B>\"\<CR>", 'itx')
48  call assert_equal('"Test3 N', getreg(':'))
49
50  call garbagecollect(1)
51endfunc
52
53" Yank one 3 byte character and check the mark columns.
54func Test_getvcol()
55  new
56  call setline(1, "x\u2500x")
57  normal 0lvy
58  call assert_equal(2, col("'["))
59  call assert_equal(4, col("']"))
60  call assert_equal(2, virtcol("'["))
61  call assert_equal(2, virtcol("']"))
62endfunc
63