1" Tests for Unicode manipulations 2 3source view_util.vim 4 5" Visual block Insert adjusts for multi-byte char 6func Test_visual_block_insert() 7 new 8 call setline(1, ["aaa", "あああ", "bbb"]) 9 exe ":norm! gg0l\<C-V>jjIx\<Esc>" 10 call assert_equal(['axaa', 'xあああ', 'bxbb'], getline(1, '$')) 11 bwipeout! 12endfunc 13 14" Test for built-in function strchars() 15func Test_strchars() 16 let inp = ["a", "あいa", "A\u20dd", "A\u20dd\u20dd", "\u20dd"] 17 let exp = [[1, 1, 1], [3, 3, 3], [2, 2, 1], [3, 3, 1], [1, 1, 1]] 18 for i in range(len(inp)) 19 call assert_equal(exp[i][0], strchars(inp[i])) 20 call assert_equal(exp[i][1], strchars(inp[i], 0)) 21 call assert_equal(exp[i][2], strchars(inp[i], 1)) 22 endfor 23endfunc 24 25" Test for customlist completion 26func CustomComplete1(lead, line, pos) 27 return ['あ', 'い'] 28endfunc 29 30func CustomComplete2(lead, line, pos) 31 return ['あたし', 'あたま', 'あたりめ'] 32endfunc 33 34func CustomComplete3(lead, line, pos) 35 return ['Nこ', 'Nん', 'Nぶ'] 36endfunc 37 38func Test_customlist_completion() 39 command -nargs=1 -complete=customlist,CustomComplete1 Test1 echo 40 call feedkeys(":Test1 \<C-L>\<C-B>\"\<CR>", 'itx') 41 call assert_equal('"Test1 ', getreg(':')) 42 43 command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo 44 call feedkeys(":Test2 \<C-L>\<C-B>\"\<CR>", 'itx') 45 call assert_equal('"Test2 あた', getreg(':')) 46 47 command -nargs=1 -complete=customlist,CustomComplete3 Test3 echo 48 call feedkeys(":Test3 \<C-L>\<C-B>\"\<CR>", 'itx') 49 call assert_equal('"Test3 N', getreg(':')) 50 51 call garbagecollect(1) 52endfunc 53 54" Yank one 3 byte character and check the mark columns. 55func Test_getvcol() 56 new 57 call setline(1, "x\u2500x") 58 normal 0lvy 59 call assert_equal(2, col("'[")) 60 call assert_equal(4, col("']")) 61 call assert_equal(2, virtcol("'[")) 62 call assert_equal(2, virtcol("']")) 63endfunc 64 65func Test_screenchar_utf8() 66 new 67 68 " 1-cell, with composing characters 69 call setline(1, ["ABC\u0308"]) 70 redraw 71 call assert_equal([0x0041], screenchars(1, 1)) 72 call assert_equal([0x0042], screenchars(1, 2)) 73 call assert_equal([0x0043, 0x0308], screenchars(1, 3)) 74 call assert_equal("A", screenstring(1, 1)) 75 call assert_equal("B", screenstring(1, 2)) 76 call assert_equal("C\u0308", screenstring(1, 3)) 77 78 " 2-cells, with composing characters 79 let text = "\u3042\u3044\u3046\u3099" 80 call setline(1, text) 81 redraw 82 call assert_equal([0x3042], screenchars(1, 1)) 83 call assert_equal([0], screenchars(1, 2)) 84 call assert_equal([0x3044], screenchars(1, 3)) 85 call assert_equal([0], screenchars(1, 4)) 86 call assert_equal([0x3046, 0x3099], screenchars(1, 5)) 87 88 call assert_equal("\u3042", screenstring(1, 1)) 89 call assert_equal("", screenstring(1, 2)) 90 call assert_equal("\u3044", screenstring(1, 3)) 91 call assert_equal("", screenstring(1, 4)) 92 call assert_equal("\u3046\u3099", screenstring(1, 5)) 93 94 call assert_equal([text . ' '], ScreenLines(1, 8)) 95 96 bwipe! 97endfunc 98