Bram Moolenaar | 6315a9a | 2017-11-25 15:20:02 +0100 | [diff] [blame] | 1 | source view_util.vim |
| 2 | |
| 3 | let s:imactivatefunc_called = 0 |
| 4 | let s:imstatusfunc_called = 0 |
Bram Moolenaar | a3a1246 | 2019-09-07 15:08:38 +0200 | [diff] [blame] | 5 | let s:imstatus_active = 0 |
Bram Moolenaar | 6315a9a | 2017-11-25 15:20:02 +0100 | [diff] [blame] | 6 | |
| 7 | func IM_activatefunc(active) |
| 8 | let s:imactivatefunc_called = 1 |
Bram Moolenaar | a3a1246 | 2019-09-07 15:08:38 +0200 | [diff] [blame] | 9 | let s:imstatus_active = a:active |
Bram Moolenaar | 6315a9a | 2017-11-25 15:20:02 +0100 | [diff] [blame] | 10 | endfunc |
| 11 | |
| 12 | func IM_statusfunc() |
| 13 | let s:imstatusfunc_called = 1 |
Bram Moolenaar | a3a1246 | 2019-09-07 15:08:38 +0200 | [diff] [blame] | 14 | return s:imstatus_active |
Bram Moolenaar | 6315a9a | 2017-11-25 15:20:02 +0100 | [diff] [blame] | 15 | endfunc |
| 16 | |
| 17 | func Test_iminsert2() |
Bram Moolenaar | a3a1246 | 2019-09-07 15:08:38 +0200 | [diff] [blame] | 18 | let s:imactivatefunc_called = 0 |
| 19 | let s:imstatusfunc_called = 0 |
| 20 | |
Bram Moolenaar | 6315a9a | 2017-11-25 15:20:02 +0100 | [diff] [blame] | 21 | set imactivatefunc=IM_activatefunc |
| 22 | set imstatusfunc=IM_statusfunc |
| 23 | set iminsert=2 |
| 24 | normal! i |
| 25 | set iminsert=0 |
| 26 | set imactivatefunc= |
| 27 | set imstatusfunc= |
Bram Moolenaar | 2877d33 | 2017-11-26 14:56:16 +0100 | [diff] [blame] | 28 | |
| 29 | let expected = has('gui_running') ? 0 : 1 |
| 30 | call assert_equal(expected, s:imactivatefunc_called) |
| 31 | call assert_equal(expected, s:imstatusfunc_called) |
Bram Moolenaar | 6315a9a | 2017-11-25 15:20:02 +0100 | [diff] [blame] | 32 | endfunc |
Bram Moolenaar | a3a1246 | 2019-09-07 15:08:38 +0200 | [diff] [blame] | 33 | |
| 34 | func Test_imgetstatus() |
| 35 | if has('gui_running') |
| 36 | if !has('win32') |
| 37 | throw 'Skipped: running in the GUI, only works on MS-Windows' |
| 38 | endif |
| 39 | set imactivatefunc= |
| 40 | set imstatusfunc= |
| 41 | else |
| 42 | set imactivatefunc=IM_activatefunc |
| 43 | set imstatusfunc=IM_statusfunc |
| 44 | let s:imstatus_active = 0 |
| 45 | endif |
| 46 | |
| 47 | new |
| 48 | set iminsert=2 |
| 49 | call feedkeys("i\<C-R>=getimstatus()\<CR>\<ESC>", 'nx') |
| 50 | call assert_equal('1', getline(1)) |
| 51 | set iminsert=0 |
| 52 | call feedkeys("o\<C-R>=getimstatus()\<CR>\<ESC>", 'nx') |
| 53 | call assert_equal('0', getline(2)) |
| 54 | bw! |
| 55 | |
| 56 | set imactivatefunc= |
| 57 | set imstatusfunc= |
| 58 | endfunc |