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