blob: 9e648a9617cf9a05fb89ebb5e180341d4b7e5040 [file] [log] [blame]
Bram Moolenaarb5e83772017-02-27 21:48:26 +01001" Simplistic testing of Arabic mode.
2
Bram Moolenaar5342f002017-02-28 22:51:12 +01003if !has('arabic') || !has('multi_byte')
Bram Moolenaarb5e83772017-02-27 21:48:26 +01004 finish
5endif
6
Bram Moolenaar5342f002017-02-28 22:51:12 +01007source view_util.vim
Bram Moolenaarb5e83772017-02-27 21:48:26 +01008
Bram Moolenaar5342f002017-02-28 22:51:12 +01009" Return list of Unicode characters at line lnum.
Bram Moolenaarb5e83772017-02-27 21:48:26 +010010" Combining characters are treated as a single item.
Bram Moolenaar5342f002017-02-28 22:51:12 +010011func s:get_chars(lnum)
Bram Moolenaarb5e83772017-02-27 21:48:26 +010012 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 Moolenaar5342f002017-02-28 22:51:12 +010017 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 Moolenaarb5e83772017-02-27 21:48:26 +010021 endfor
22 return chars
23endfunc
24
25func 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&
42endfunc
43
44func Test_arabic_input()
45 new
46 set arabic
47 " Typing sghl in Arabic insert mode should show the
Bram Moolenaar5342f002017-02-28 22:51:12 +010048 " 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 Moolenaarb5e83772017-02-27 21:48:26 +010053 call assert_equal([
Bram Moolenaar5342f002017-02-28 22:51:12 +010054 \ 'U+0633',
55 \ 'U+0644 U+0627',
56 \ 'U+0645',
57 \ 'U+21'], s:get_chars(1))
Bram Moolenaarb5e83772017-02-27 21:48:26 +010058
59 " Without shaping, it should give individual Arabic letters.
60 set noarabicshape
Bram Moolenaar5342f002017-02-28 22:51:12 +010061 call assert_match("^ *!\u0645\u0627\u0644\u0633$", ScreenLines(1, &columns)[0])
Bram Moolenaarb5e83772017-02-27 21:48:26 +010062 call assert_equal([
Bram Moolenaar5342f002017-02-28 22:51:12 +010063 \ 'U+0633',
64 \ 'U+0644',
65 \ 'U+0627',
66 \ 'U+0645',
67 \ 'U+21'], s:get_chars(1))
Bram Moolenaarb5e83772017-02-27 21:48:26 +010068
Bram Moolenaar5342f002017-02-28 22:51:12 +010069 set arabic& arabicshape&
Bram Moolenaarb5e83772017-02-27 21:48:26 +010070 bwipe!
71endfunc
72
73func Test_arabic_toggle_keymap()
74 new
75 set arabic
76 call feedkeys("i12\<C-^>12\<C-^>12", 'tx')
Bram Moolenaar5342f002017-02-28 22:51:12 +010077 call assert_match("^ *٢١21٢١$", ScreenLines(1, &columns)[0])
Bram Moolenaarb5e83772017-02-27 21:48:26 +010078 call assert_equal('١٢12١٢', getline('.'))
79 set arabic&
80 bwipe!
81endfunc
82
83func Test_delcombine()
84 new
85 set arabic
86 call feedkeys("isghl\<BS>\<BS>", 'tx')
Bram Moolenaar5342f002017-02-28 22:51:12 +010087 call assert_match("^ *\uFEDE\uFEB3$", ScreenLines(1, &columns)[0])
88 call assert_equal(['U+0633', 'U+0644'], s:get_chars(1))
Bram Moolenaarb5e83772017-02-27 21:48:26 +010089
Bram Moolenaar5342f002017-02-28 22:51:12 +010090 " Now the same with 'nodelcombine'
Bram Moolenaarb5e83772017-02-27 21:48:26 +010091 set nodelcombine
92 %d
93 call feedkeys("isghl\<BS>\<BS>", 'tx')
Bram Moolenaar5342f002017-02-28 22:51:12 +010094 call assert_match("^ *\uFEB1$", ScreenLines(1, &columns)[0])
95 call assert_equal(['U+0633'], s:get_chars(1))
Bram Moolenaarb5e83772017-02-27 21:48:26 +010096 set arabic&
97 bwipe!
98endfunc
Bram Moolenaar5342f002017-02-28 22:51:12 +010099
100let s:a_YEH_HAMZA = "\u0626"
101let s:a_i_YEH_HAMZA = "\ufe8b"
102
103let s:a_HAMZA = "\u0621"
104let s:a_s_HAMZA = "\ufe80"
105
106let s:a_ALEF_MADDA = "\u0622"
107let s:a_s_ALEF_MADDA = "\ufe81"
108
109let s:a_ALEF_HAMZA_ABOVE = "\u0623"
110let s:a_s_ALEF_HAMZA_ABOVE = "\ufe83"
111
112let s:a_GHAIN = "\u063a"
113let s:a_f_GHAIN = "\ufece"
114let s:a_s_GHAIN = "\ufecd"
115
116func 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!
133endfunc