blob: 8a71f5035164292f654617d44983c66ee1866db6 [file] [log] [blame]
Bram Moolenaar0c0590d2017-01-28 13:48:10 +01001" Tests for Unicode manipulations
Bram Moolenaar0c0590d2017-01-28 13:48:10 +01002
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
Bram Moolenaar1e115362019-01-09 23:01:02 +010025func CustomComplete1(lead, line, pos)
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010026 return ['あ', 'い']
Bram Moolenaar1e115362019-01-09 23:01:02 +010027endfunc
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010028
Bram Moolenaar1e115362019-01-09 23:01:02 +010029func CustomComplete2(lead, line, pos)
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010030 return ['あたし', 'あたま', 'あたりめ']
Bram Moolenaar1e115362019-01-09 23:01:02 +010031endfunc
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010032
Bram Moolenaar1e115362019-01-09 23:01:02 +010033func CustomComplete3(lead, line, pos)
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010034 return ['Nこ', 'Nん', 'Nぶ']
Bram Moolenaar1e115362019-01-09 23:01:02 +010035endfunc
Bram Moolenaar0c0590d2017-01-28 13:48:10 +010036
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