blob: fb2ef053bdeb01e4b37a6e9d2bd254dbe2a847b3 [file] [log] [blame]
Bram Moolenaar6315a9a2017-11-25 15:20:02 +01001source view_util.vim
Bram Moolenaare2a3f362019-12-07 21:40:48 +01002source check.vim
Bram Moolenaar6315a9a2017-11-25 15:20:02 +01003
4let s:imactivatefunc_called = 0
5let s:imstatusfunc_called = 0
Bram Moolenaara3a12462019-09-07 15:08:38 +02006let s:imstatus_active = 0
Bram Moolenaar6315a9a2017-11-25 15:20:02 +01007
8func IM_activatefunc(active)
9 let s:imactivatefunc_called = 1
Bram Moolenaara3a12462019-09-07 15:08:38 +020010let s:imstatus_active = a:active
Bram Moolenaar6315a9a2017-11-25 15:20:02 +010011endfunc
12
13func IM_statusfunc()
14 let s:imstatusfunc_called = 1
Bram Moolenaara3a12462019-09-07 15:08:38 +020015 return s:imstatus_active
Bram Moolenaar6315a9a2017-11-25 15:20:02 +010016endfunc
17
18func Test_iminsert2()
Bram Moolenaara3a12462019-09-07 15:08:38 +020019 let s:imactivatefunc_called = 0
20 let s:imstatusfunc_called = 0
21
Bram Moolenaar6315a9a2017-11-25 15:20:02 +010022 set imactivatefunc=IM_activatefunc
23 set imstatusfunc=IM_statusfunc
24 set iminsert=2
25 normal! i
26 set iminsert=0
27 set imactivatefunc=
28 set imstatusfunc=
Bram Moolenaar2877d332017-11-26 14:56:16 +010029
30 let expected = has('gui_running') ? 0 : 1
31 call assert_equal(expected, s:imactivatefunc_called)
32 call assert_equal(expected, s:imstatusfunc_called)
Bram Moolenaar6315a9a2017-11-25 15:20:02 +010033endfunc
Bram Moolenaara3a12462019-09-07 15:08:38 +020034
Bram Moolenaare2a3f362019-12-07 21:40:48 +010035func Test_getimstatus()
36 if has('win32')
37 CheckFeature multi_byte_ime
38 elseif !has('gui_mac')
39 CheckFeature xim
40 endif
Bram Moolenaara3a12462019-09-07 15:08:38 +020041 if has('gui_running')
42 if !has('win32')
43 throw 'Skipped: running in the GUI, only works on MS-Windows'
44 endif
45 set imactivatefunc=
46 set imstatusfunc=
47 else
48 set imactivatefunc=IM_activatefunc
49 set imstatusfunc=IM_statusfunc
50 let s:imstatus_active = 0
51 endif
52
53 new
54 set iminsert=2
55 call feedkeys("i\<C-R>=getimstatus()\<CR>\<ESC>", 'nx')
56 call assert_equal('1', getline(1))
57 set iminsert=0
58 call feedkeys("o\<C-R>=getimstatus()\<CR>\<ESC>", 'nx')
59 call assert_equal('0', getline(2))
60 bw!
61
62 set imactivatefunc=
63 set imstatusfunc=
64endfunc