blob: f1394fbf872d8ed6341d6e14505ed309139aac1b [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",
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020017 \ "hi Comment ctermfg=red",
18 \ "call prop_type_add('comment', {'highlight': 'Comment'})",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020019 \ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'highlight': 'PopupColor1'})",
Bram Moolenaar4d784b22019-05-25 19:51:39 +020020 \ "let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25})",
Bram Moolenaar20c023a2019-05-26 21:03:24 +020021 \ "call setwinvar(winid2, '&wincolor', 'PopupColor2')",
Bram Moolenaar4d784b22019-05-25 19:51:39 +020022 \], 'XtestPopup')
23 let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
24 call VerifyScreenDump(buf, 'Test_popupwin_01', {})
25
Bram Moolenaarec583842019-05-26 14:11:23 +020026 " Add a tabpage
27 call term_sendkeys(buf, ":tabnew\<CR>")
Bram Moolenaar7a8d0272019-05-26 23:32:06 +020028 call term_sendkeys(buf, ":call popup_create(["
29 \ .. "{'text': 'other tab'},"
30 \ .. "{'text': 'a comment line', 'props': [{"
31 \ .. "'col': 3, 'length': 7, 'type': 'comment'"
32 \ .. "}]},"
33 \ .. "], {'line': 4, 'col': 9})\<CR>")
Bram Moolenaarec583842019-05-26 14:11:23 +020034 call VerifyScreenDump(buf, 'Test_popupwin_02', {})
35
36 " switch back to first tabpage
37 call term_sendkeys(buf, "gt")
38 call VerifyScreenDump(buf, 'Test_popupwin_03', {})
39
40 " close that tabpage
41 call term_sendkeys(buf, ":quit!\<CR>")
42 call VerifyScreenDump(buf, 'Test_popupwin_04', {})
43
Bram Moolenaar4d784b22019-05-25 19:51:39 +020044 " clean up
45 call StopVimInTerminal(buf)
46 call delete('XtestPopup')
47endfunc
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020048
49func Test_popup_time()
Bram Moolenaar35d5af62019-05-26 20:44:10 +020050 if !has('timers')
51 return
52 endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020053 topleft vnew
54 call setline(1, 'hello')
55
56 call popup_create('world', {
57 \ 'line': 1,
58 \ 'col': 1,
59 \ 'time': 500,
60 \})
61 redraw
62 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
63 call assert_equal('world', line)
64
65 sleep 700m
Bram Moolenaar35d5af62019-05-26 20:44:10 +020066 redraw
Bram Moolenaar51fe3b12019-05-26 20:10:06 +020067 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
68 call assert_equal('hello', line)
69
70 call popup_create('on the command line', {
71 \ 'line': &lines,
72 \ 'col': 10,
73 \ 'time': 500,
74 \})
75 redraw
76 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
77 call assert_match('.*on the command line.*', line)
78
79 sleep 700m
80 redraw
81 let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
82 call assert_notmatch('.*on the command line.*', line)
83
84 bwipe!
85endfunc
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +020086
87func Test_popup_hide()
88 topleft vnew
89 call setline(1, 'hello')
90
91 let winid = popup_create('world', {
92 \ 'line': 1,
93 \ 'col': 1,
94 \})
95 redraw
96 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
97 call assert_equal('world', line)
98
99 call popup_hide(winid)
100 redraw
101 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
102 call assert_equal('hello', line)
103
104 call popup_show(winid)
105 redraw
106 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
107 call assert_equal('world', line)
108
109
110 call popup_close(winid)
111 redraw
112 let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
113 call assert_equal('hello', line)
114
115 " error is given for existing non-popup window
116 call assert_fails('call popup_hide(win_getid())', 'E993:')
117
118 " no error non-existing window
119 call popup_hide(1234234)
120 call popup_show(41234234)
121
122 bwipe!
123endfunc