Bram Moolenaar | 0c0590d | 2017-01-28 13:48:10 +0100 | [diff] [blame] | 1 | " Tests for Unicode manipulations |
Bram Moolenaar | 0c0590d | 2017-01-28 13:48:10 +0100 | [diff] [blame] | 2 | |
Bram Moolenaar | 2912abb | 2019-03-29 14:16:42 +0100 | [diff] [blame] | 3 | source view_util.vim |
Bram Moolenaar | 0c0590d | 2017-01-28 13:48:10 +0100 | [diff] [blame] | 4 | |
| 5 | " Visual block Insert adjusts for multi-byte char |
| 6 | func 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! |
| 12 | endfunc |
| 13 | |
| 14 | " Test for built-in function strchars() |
| 15 | func 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 |
| 23 | endfunc |
| 24 | |
| 25 | " Test for customlist completion |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 26 | func CustomComplete1(lead, line, pos) |
Bram Moolenaar | 0c0590d | 2017-01-28 13:48:10 +0100 | [diff] [blame] | 27 | return ['あ', 'い'] |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 28 | endfunc |
Bram Moolenaar | 0c0590d | 2017-01-28 13:48:10 +0100 | [diff] [blame] | 29 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 30 | func CustomComplete2(lead, line, pos) |
Bram Moolenaar | 0c0590d | 2017-01-28 13:48:10 +0100 | [diff] [blame] | 31 | return ['あたし', 'あたま', 'あたりめ'] |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 32 | endfunc |
Bram Moolenaar | 0c0590d | 2017-01-28 13:48:10 +0100 | [diff] [blame] | 33 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 34 | func CustomComplete3(lead, line, pos) |
Bram Moolenaar | 0c0590d | 2017-01-28 13:48:10 +0100 | [diff] [blame] | 35 | return ['Nこ', 'Nん', 'Nぶ'] |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 36 | endfunc |
Bram Moolenaar | 0c0590d | 2017-01-28 13:48:10 +0100 | [diff] [blame] | 37 | |
| 38 | func 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) |
| 52 | endfunc |
| 53 | |
| 54 | " Yank one 3 byte character and check the mark columns. |
| 55 | func 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("']")) |
| 63 | endfunc |
Bram Moolenaar | 2912abb | 2019-03-29 14:16:42 +0100 | [diff] [blame] | 64 | |
| 65 | func 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 . ' '], ScreenLinesUtf8(1, 8)) |
| 95 | |
| 96 | bwipe! |
| 97 | endfunc |