blob: 73efe0a738ebc15b1cb56de384dd8be154a96850 [file] [log] [blame]
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001" Tests for popup windows
2
3if !has('textprop')
4 finish
5endif
6
7source screendump.vim
8
9func Test_simple_popup()
10 if !CanRunVimInTerminal()
11 return
12 endif
13 call writefile([
14 \ "call setline(1, range(1, 100))",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020015 \ "hi PopupColor1 ctermbg=lightblue",
16 \ "hi PopupColor2 ctermbg=lightcyan",
17 \ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'highlight': 'PopupColor1'})",
Bram Moolenaar4d784b22019-05-25 19:51:39 +020018 \ "let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25})",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020019 \ "call setwinvar(winid2, '&wincolor', 'PopupColor2')",
Bram Moolenaar4d784b22019-05-25 19:51:39 +020020 \], 'XtestPopup')
21 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
22 call VerifyScreenDump(buf, 'Test_popupwin_01', {})
23
Bram Moolenaarec583842019-05-26 14:11:23 +020024 " Add a tabpage
25 call term_sendkeys(buf, ":tabnew\<CR>")
26 call term_sendkeys(buf, ":call popup_create('other tab', {'line': 4, 'col': 9})\<CR>")
27 call VerifyScreenDump(buf, 'Test_popupwin_02', {})
28
29 " switch back to first tabpage
30 call term_sendkeys(buf, "gt")
31 call VerifyScreenDump(buf, 'Test_popupwin_03', {})
32
33 " close that tabpage
34 call term_sendkeys(buf, ":quit!\<CR>")
35 call VerifyScreenDump(buf, 'Test_popupwin_04', {})
36
Bram Moolenaar4d784b22019-05-25 19:51:39 +020037 " clean up
38 call StopVimInTerminal(buf)
39 call delete('XtestPopup')
40endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020041
42func Test_popup_time()
Bram Moolenaar35d5af62019-05-26 20:44:10 +020043 if !has('timers')
44 return
45 endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020046 topleft vnew
47 call setline(1, 'hello')
48
49 call popup_create('world', {
50 \ 'line': 1,
51 \ 'col': 1,
52 \ 'time': 500,
53 \})
54 redraw
55 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
56 call assert_equal('world', line)
57
58 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +020059 redraw
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020060 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
61 call assert_equal('hello', line)
62
63 call popup_create('on the command line', {
64 \ 'line': &lines,
65 \ 'col': 10,
66 \ 'time': 500,
67 \})
68 redraw
69 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
70 call assert_match('.*on the command line.*', line)
71
72 sleep 700m
73 redraw
74 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
75 call assert_notmatch('.*on the command line.*', line)
76
77 bwipe!
78endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +020079
80func Test_popup_hide()
81 topleft vnew
82 call setline(1, 'hello')
83
84 let winid = popup_create('world', {
85 \ 'line': 1,
86 \ 'col': 1,
87 \})
88 redraw
89 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
90 call assert_equal('world', line)
91
92 call popup_hide(winid)
93 redraw
94 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
95 call assert_equal('hello', line)
96
97 call popup_show(winid)
98 redraw
99 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
100 call assert_equal('world', line)
101
102
103 call popup_close(winid)
104 redraw
105 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
106 call assert_equal('hello', line)
107
108 " error is given for existing non-popup window
109 call assert_fails('call popup_hide(win_getid())', 'E993:')
110
111 " no error non-existing window
112 call popup_hide(1234234)
113 call popup_show(41234234)
114
115 bwipe!
116endfunc