Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 1 | " Simplistic testing of Arabic mode. |
| 2 | |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 3 | if !has('arabic') || !has('multi_byte') |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 4 | finish |
| 5 | endif |
| 6 | |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 7 | source view_util.vim |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 8 | |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 9 | " Return list of Unicode characters at line lnum. |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 10 | " Combining characters are treated as a single item. |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 11 | func s:get_chars(lnum) |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 12 | call cursor(a:lnum, 1) |
| 13 | let chars = [] |
| 14 | let numchars = strchars(getline('.'), 1) |
| 15 | for i in range(1, numchars) |
| 16 | exe 'norm ' i . '|' |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 17 | let c=execute('ascii') |
| 18 | let c=substitute(c, '\n\?<.\{-}Hex\s*', 'U+', 'g') |
| 19 | let c=substitute(c, ',\s*Octal\s*\d*', '', 'g') |
| 20 | call add(chars, c) |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 21 | endfor |
| 22 | return chars |
| 23 | endfunc |
| 24 | |
| 25 | func Test_arabic_toggle() |
| 26 | set arabic |
| 27 | call assert_equal(1, &rightleft) |
| 28 | call assert_equal(1, &arabicshape) |
| 29 | call assert_equal('arabic', &keymap) |
| 30 | call assert_equal(1, &delcombine) |
| 31 | |
| 32 | set iminsert=1 imsearch=1 |
| 33 | set arabic& |
| 34 | call assert_equal(0, &rightleft) |
| 35 | call assert_equal(1, &arabicshape) |
| 36 | call assert_equal('arabic', &keymap) |
| 37 | call assert_equal(1, &delcombine) |
| 38 | call assert_equal(0, &iminsert) |
| 39 | call assert_equal(-1, &imsearch) |
| 40 | |
| 41 | set arabicshape& keymap= delcombine& |
| 42 | endfunc |
| 43 | |
| 44 | func Test_arabic_input() |
| 45 | new |
| 46 | set arabic |
| 47 | " Typing sghl in Arabic insert mode should show the |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 48 | " Arabic word 'Salaam' i.e. 'peace', spelled: |
| 49 | " SEEN, LAM, ALEF, MEEM. |
| 50 | " See: https://www.mediawiki.org/wiki/VisualEditor/Typing/Right-to-left |
| 51 | call feedkeys('isghl!', 'tx') |
| 52 | call assert_match("^ *!\uFEE1\uFEFC\uFEB3$", ScreenLines(1, &columns)[0]) |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 53 | call assert_equal([ |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 54 | \ 'U+0633', |
| 55 | \ 'U+0644 U+0627', |
| 56 | \ 'U+0645', |
| 57 | \ 'U+21'], s:get_chars(1)) |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 58 | |
| 59 | " Without shaping, it should give individual Arabic letters. |
| 60 | set noarabicshape |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 61 | call assert_match("^ *!\u0645\u0627\u0644\u0633$", ScreenLines(1, &columns)[0]) |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 62 | call assert_equal([ |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 63 | \ 'U+0633', |
| 64 | \ 'U+0644', |
| 65 | \ 'U+0627', |
| 66 | \ 'U+0645', |
| 67 | \ 'U+21'], s:get_chars(1)) |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 68 | |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 69 | set arabic& arabicshape& |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 70 | bwipe! |
| 71 | endfunc |
| 72 | |
| 73 | func Test_arabic_toggle_keymap() |
| 74 | new |
| 75 | set arabic |
| 76 | call feedkeys("i12\<C-^>12\<C-^>12", 'tx') |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 77 | call assert_match("^ *٢١21٢١$", ScreenLines(1, &columns)[0]) |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 78 | call assert_equal('١٢12١٢', getline('.')) |
| 79 | set arabic& |
| 80 | bwipe! |
| 81 | endfunc |
| 82 | |
| 83 | func Test_delcombine() |
| 84 | new |
| 85 | set arabic |
| 86 | call feedkeys("isghl\<BS>\<BS>", 'tx') |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 87 | call assert_match("^ *\uFEDE\uFEB3$", ScreenLines(1, &columns)[0]) |
| 88 | call assert_equal(['U+0633', 'U+0644'], s:get_chars(1)) |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 89 | |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 90 | " Now the same with 'nodelcombine' |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 91 | set nodelcombine |
| 92 | %d |
| 93 | call feedkeys("isghl\<BS>\<BS>", 'tx') |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 94 | call assert_match("^ *\uFEB1$", ScreenLines(1, &columns)[0]) |
| 95 | call assert_equal(['U+0633'], s:get_chars(1)) |
Bram Moolenaar | b5e8377 | 2017-02-27 21:48:26 +0100 | [diff] [blame] | 96 | set arabic& |
| 97 | bwipe! |
| 98 | endfunc |
Bram Moolenaar | 5342f00 | 2017-02-28 22:51:12 +0100 | [diff] [blame^] | 99 | |
| 100 | let s:a_YEH_HAMZA = "\u0626" |
| 101 | let s:a_i_YEH_HAMZA = "\ufe8b" |
| 102 | |
| 103 | let s:a_HAMZA = "\u0621" |
| 104 | let s:a_s_HAMZA = "\ufe80" |
| 105 | |
| 106 | let s:a_ALEF_MADDA = "\u0622" |
| 107 | let s:a_s_ALEF_MADDA = "\ufe81" |
| 108 | |
| 109 | let s:a_ALEF_HAMZA_ABOVE = "\u0623" |
| 110 | let s:a_s_ALEF_HAMZA_ABOVE = "\ufe83" |
| 111 | |
| 112 | let s:a_GHAIN = "\u063a" |
| 113 | let s:a_f_GHAIN = "\ufece" |
| 114 | let s:a_s_GHAIN = "\ufecd" |
| 115 | |
| 116 | func Test_shape_initial() |
| 117 | new |
| 118 | set arabicshape |
| 119 | |
| 120 | " Shaping arabic {testchar} non-arabic Uses chg_c_a2i(). |
| 121 | " pair[0] = testchar, pair[1] = next-result, pair[2] = current-result |
| 122 | for pair in [[s:a_YEH_HAMZA, s:a_f_GHAIN, s:a_i_YEH_HAMZA], |
| 123 | \ [s:a_HAMZA, s:a_s_GHAIN, s:a_s_HAMZA], |
| 124 | \ [s:a_ALEF_MADDA, s:a_s_GHAIN, s:a_s_ALEF_MADDA], |
| 125 | \ [s:a_ALEF_HAMZA_ABOVE, s:a_s_GHAIN, s:a_s_ALEF_HAMZA_ABOVE], |
| 126 | \ ] |
| 127 | call setline(1, s:a_GHAIN . pair[0] . ' ') |
| 128 | call assert_equal([pair[1] . pair[2] . ' '], ScreenLines(1, 3)) |
| 129 | endfor |
| 130 | |
| 131 | set arabicshape& |
| 132 | bwipe! |
| 133 | endfunc |