blob: 699df62fe31983e6fc29c2345e6dc98429de75f7 [file] [log] [blame]
Bram Moolenaar0c0590d2017-01-28 13:48:10 +01001" Tests for Unicode manipulations
2if !has('multi_byte')
3 finish
4endif
5
6
7" Visual block Insert adjusts for multi-byte char
8func 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!
14endfunc
15
16" Test for built-in function strchars()
17func 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
25endfunc
26
27" Test for customlist completion
Bram Moolenaar1e115362019-01-09 23:01:02 +010028func CustomComplete1(lead, line, pos)
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010029 return ['あ', 'い']
Bram Moolenaar1e115362019-01-09 23:01:02 +010030endfunc
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010031
Bram Moolenaar1e115362019-01-09 23:01:02 +010032func CustomComplete2(lead, line, pos)
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010033 return ['あたし', 'あたま', 'あたりめ']
Bram Moolenaar1e115362019-01-09 23:01:02 +010034endfunc
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010035
Bram Moolenaar1e115362019-01-09 23:01:02 +010036func CustomComplete3(lead, line, pos)
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010037 return ['Nこ', 'Nん', 'Nぶ']
Bram Moolenaar1e115362019-01-09 23:01:02 +010038endfunc
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010039
40func 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)
54endfunc
55
56" Yank one 3 byte character and check the mark columns.
57func 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("']"))
65endfunc