blob: abf7d6944e6dad96a435f16e70e314cdac7c98bf [file] [log] [blame]
Bram Moolenaar2f106582019-05-08 21:59:25 +02001" Tests for 'balloonevalterm'.
2
Bram Moolenaar9c0cec62019-06-06 13:38:15 +02003if !has('balloon_eval_term')
4 throw 'Skipped: balloon_eval_term feature missing'
5endif
6
7" A few tests only work in the terminal.
8if !has('gui_running')
Bram Moolenaar2f106582019-05-08 21:59:25 +02009
10source screendump.vim
11if !CanRunVimInTerminal()
Bram Moolenaar5d30ff12019-06-06 16:12:12 +020012 throw 'Skipped: cannot make screendumps'
Bram Moolenaar2f106582019-05-08 21:59:25 +020013endif
14
Bram Moolenaarc79745a2019-05-20 22:12:34 +020015let s:common_script =<< [CODE]
16 call setline(1, ["one one one", "two tXo two", "three three three"])
17 set balloonevalterm balloonexpr=MyBalloonExpr() balloondelay=100
18 func MyBalloonExpr()
19 return "line " .. v:beval_lnum .. " column " .. v:beval_col .. ": " .. v:beval_text
20 endfun
21 redraw
22[CODE]
Bram Moolenaar06bd8242019-05-08 22:55:16 +020023
24func Test_balloon_eval_term()
25 " Use <Ignore> after <MouseMove> to return from vgetc() without removing
26 " the balloon.
27 call writefile(s:common_script + [
Bram Moolenaar2f106582019-05-08 21:59:25 +020028 \ 'call test_setmouse(2, 6)',
29 \ 'call feedkeys("\<MouseMove>\<Ignore>", "xt")',
30 \ ], 'XTest_beval')
31
Bram Moolenaar06bd8242019-05-08 22:55:16 +020032 " Check that the balloon shows up after a mouse move
Bram Moolenaar2f106582019-05-08 21:59:25 +020033 let buf = RunVimInTerminal('-S XTest_beval', {'rows': 10, 'cols': 50})
34 call term_wait(buf, 100)
35 call VerifyScreenDump(buf, 'Test_balloon_eval_term_01', {})
36
37 " clean up
38 call StopVimInTerminal(buf)
39 call delete('XTest_beval')
40endfunc
Bram Moolenaar06bd8242019-05-08 22:55:16 +020041
42func Test_balloon_eval_term_visual()
43 " Use <Ignore> after <MouseMove> to return from vgetc() without removing
44 " the balloon.
45 call writefile(s:common_script + [
46 \ 'call test_setmouse(3, 6)',
47 \ 'call feedkeys("3Gevfr\<MouseMove>\<Ignore>", "xt")',
48 \ ], 'XTest_beval_visual')
49
50 " Check that the balloon shows up after a mouse move
51 let buf = RunVimInTerminal('-S XTest_beval_visual', {'rows': 10, 'cols': 50})
52 call term_wait(buf, 100)
53 call VerifyScreenDump(buf, 'Test_balloon_eval_term_02', {})
54
55 " clean up
56 call StopVimInTerminal(buf)
57 call delete('XTest_beval_visual')
58endfunc
Bram Moolenaarbe0a2592019-05-09 13:50:16 +020059
60endif
61
62" Tests that only work in the GUI
63if has('gui_running')
64
65func Test_balloon_show_gui()
66 let msg = 'this this this this'
67 call balloon_show(msg)
68 call assert_equal(msg, balloon_gettext())
69 sleep 10m
70 call balloon_show('')
71
72 let msg = 'that that'
73 call balloon_show(msg)
74 call assert_equal(msg, balloon_gettext())
75 sleep 10m
76 call balloon_show('')
77endfunc
78
79endif