blob: b9e033462e4dc629af62334c9e1aa2d02a183c1f [file] [log] [blame]
Bram Moolenaarb5e83772017-02-27 21:48:26 +01001" Simplistic testing of Arabic mode.
2
3if !has('arabic')
4 finish
5endif
6
7set encoding=utf-8
8scriptencoding utf-8
9
10" Return list of utf8 sequences of each character at line lnum.
11" Combining characters are treated as a single item.
12func GetCharsUtf8(lnum)
13 call cursor(a:lnum, 1)
14 let chars = []
15 let numchars = strchars(getline('.'), 1)
16 for i in range(1, numchars)
17 exe 'norm ' i . '|'
18 call add(chars, execute('norm g8'))
19 endfor
20 return chars
21endfunc
22
23func Test_arabic_toggle()
24 set arabic
25 call assert_equal(1, &rightleft)
26 call assert_equal(1, &arabicshape)
27 call assert_equal('arabic', &keymap)
28 call assert_equal(1, &delcombine)
29
30 set iminsert=1 imsearch=1
31 set arabic&
32 call assert_equal(0, &rightleft)
33 call assert_equal(1, &arabicshape)
34 call assert_equal('arabic', &keymap)
35 call assert_equal(1, &delcombine)
36 call assert_equal(0, &iminsert)
37 call assert_equal(-1, &imsearch)
38
39 set arabicshape& keymap= delcombine&
40endfunc
41
42func Test_arabic_input()
43 new
44 set arabic
45 " Typing sghl in Arabic insert mode should show the
46 " Arabic word 'Salaam' i.e. 'peace'.
47 call feedkeys('isghl', 'tx')
48 redraw
49 call assert_equal([
50 \ "\nd8 b3 ",
51 \ "\nd9 84 + d8 a7 ",
52 \ "\nd9 85 "], GetCharsUtf8(1))
53
54 " Without shaping, it should give individual Arabic letters.
55 set noarabicshape
56 redraw
57 call assert_equal([
58 \ "\nd8 b3 ",
59 \ "\nd9 84 ",
60 \ "\nd8 a7 ",
61 \ "\nd9 85 "], GetCharsUtf8(1))
62
63 set arabicshape&
64 set arabic&
65 bwipe!
66endfunc
67
68func Test_arabic_toggle_keymap()
69 new
70 set arabic
71 call feedkeys("i12\<C-^>12\<C-^>12", 'tx')
72 redraw
73 call assert_equal('١٢12١٢', getline('.'))
74 set arabic&
75 bwipe!
76endfunc
77
78func Test_delcombine()
79 new
80 set arabic
81 call feedkeys("isghl\<BS>\<BS>", 'tx')
82 redraw
83 call assert_equal(["\nd8 b3 ", "\nd9 84 "], GetCharsUtf8(1))
84
85 " Now the same with nodelcombine
86 set nodelcombine
87 %d
88 call feedkeys("isghl\<BS>\<BS>", 'tx')
89 call assert_equal(["\nd8 b3 "], GetCharsUtf8(1))
90 set arabic&
91 bwipe!
92endfunc