11" Simplistic testing of Arabic mode.
22
3- if ! has (' arabic' )
3+ if ! has (' arabic' ) || ! has ( ' multi_byte ' )
44 finish
55endif
66
7- set encoding = utf- 8
8- scriptencoding utf- 8
7+ source view_util.vim
98
10- " Return list of utf8 sequences of each character at line lnum.
9+ " Return list of Unicode characters at line lnum.
1110" Combining characters are treated as a single item.
12- func GetCharsUtf8 (lnum)
11+ func s: get_chars (lnum)
1312 call cursor (a: lnum , 1 )
1413 let chars = []
1514 let numchars = strchars (getline (' .' ), 1 )
1615 for i in range (1 , numchars)
1716 exe ' norm ' i . ' |'
18- call add (chars, execute (' norm g8' ))
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 )
1921 endfor
2022 return chars
2123endfunc
@@ -43,33 +45,36 @@ func Test_arabic_input()
4345 new
4446 set arabic
4547 " Typing sghl in Arabic insert mode should show the
46- " Arabic word 'Salaam' i.e. 'peace'.
47- call feedkeys (' isghl' , ' tx' )
48- redraw
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 ])
4953 call assert_equal ([
50- \ " \n d8 b3 " ,
51- \ " \n d9 84 + d8 a7 " ,
52- \ " \n d9 85 " ], GetCharsUtf8 (1 ))
54+ \ ' U+0633' ,
55+ \ ' U+0644 U+0627' ,
56+ \ ' U+0645' ,
57+ \ ' U+21' ], s: get_chars (1 ))
5358
5459 " Without shaping, it should give individual Arabic letters.
5560 set noarabicshape
56- redraw
61+ call assert_match ( " ^ *! \u0645\u0627\u0644\u0633 $ " , ScreenLines ( 1 , & columns )[ 0 ])
5762 call assert_equal ([
58- \ " \n d8 b3 " ,
59- \ " \n d9 84 " ,
60- \ " \n d8 a7 " ,
61- \ " \n d9 85 " ], GetCharsUtf8 (1 ))
63+ \ ' U+0633' ,
64+ \ ' U+0644' ,
65+ \ ' U+0627' ,
66+ \ ' U+0645' ,
67+ \ ' U+21' ], s: get_chars (1 ))
6268
63- set arabicshape &
64- set arabic &
69+ set arabic & arabicshape &
6570 bwipe!
6671endfunc
6772
6873func Test_arabic_toggle_keymap ()
6974 new
7075 set arabic
7176 call feedkeys (" i12\<C-^> 12\<C-^> 12" , ' tx' )
72- redraw
77+ call assert_match ( " ^ *٢١21٢١$ " , ScreenLines ( 1 , & columns )[ 0 ])
7378 call assert_equal (' ١٢12١٢' , getline (' .' ))
7479 set arabic &
7580 bwipe!
@@ -79,14 +84,50 @@ func Test_delcombine()
7984 new
8085 set arabic
8186 call feedkeys (" isghl\<BS>\<BS> " , ' tx' )
82- redraw
83- call assert_equal ([" \n d8 b3 " , " \n d9 84 " ], GetCharsUtf8 (1 ))
87+ call assert_match ( " ^ * \uFEDE\uFEB3 $ " , ScreenLines ( 1 , & columns )[ 0 ])
88+ call assert_equal ([' U+0633 ' , ' U+0644 ' ], s: get_chars (1 ))
8489
85- " Now the same with nodelcombine
90+ " Now the same with ' nodelcombine'
8691 set nodelcombine
8792 % d
8893 call feedkeys (" isghl\<BS>\<BS> " , ' tx' )
89- call assert_equal ([" \n d8 b3 " ], GetCharsUtf8 (1 ))
94+ call assert_match (" ^ *\uFEB1 $" , ScreenLines (1 , &columns )[0 ])
95+ call assert_equal ([' U+0633' ], s: get_chars (1 ))
9096 set arabic &
9197 bwipe!
9298endfunc
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
0 commit comments