1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
" Tests for popup windows
if !has('textprop')
finish
endif
source screendump.vim
func Test_simple_popup()
if !CanRunVimInTerminal()
return
endif
call writefile([
\ "call setline(1, range(1, 100))",
\ "hi PopupColor1 ctermbg=lightblue",
\ "hi PopupColor2 ctermbg=lightcyan",
\ "hi Comment ctermfg=red",
\ "call prop_type_add('comment', {'highlight': 'Comment'})",
\ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'minwidth': 20, 'highlight': 'PopupColor1'})",
\ "let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25, 'minwidth': 20})",
\ "call setwinvar(winid2, '&wincolor', 'PopupColor2')",
\], 'XtestPopup')
let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
call VerifyScreenDump(buf, 'Test_popupwin_01', {})
" Add a tabpage
call term_sendkeys(buf, ":tabnew\<CR>")
call term_sendkeys(buf, ":let popupwin = popup_create(["
\ .. "{'text': 'other tab'},"
\ .. "{'text': 'a comment line', 'props': [{"
\ .. "'col': 3, 'length': 7, 'minwidth': 20, 'type': 'comment'"
\ .. "}]},"
\ .. "], {'line': 4, 'col': 9, 'minwidth': 20})\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_02', {})
" switch back to first tabpage
call term_sendkeys(buf, "gt")
call VerifyScreenDump(buf, 'Test_popupwin_03', {})
" close that tabpage
call term_sendkeys(buf, ":quit!\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_04', {})
" resize popup, show empty line at bottom
call term_sendkeys(buf, ":call popup_move(popupwin, {'minwidth': 15, 'maxwidth': 25, 'minheight': 3, 'maxheight': 5})\<CR>")
call term_sendkeys(buf, ":redraw\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_05', {})
" show not fitting line at bottom
call term_sendkeys(buf, ":call setbufline(winbufnr(popupwin), 3, 'this line will not fit here')\<CR>")
call term_sendkeys(buf, ":redraw\<CR>")
call VerifyScreenDump(buf, 'Test_popupwin_06', {})
" clean up
call StopVimInTerminal(buf)
call delete('XtestPopup')
endfunc
func Test_popup_time()
if !has('timers')
return
endif
topleft vnew
call setline(1, 'hello')
call popup_create('world', {
\ 'line': 1,
\ 'col': 1,
\ 'minwidth': 20,
\ 'time': 500,
\})
redraw
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
call assert_equal('world', line)
sleep 700m
redraw
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
call assert_equal('hello', line)
call popup_create('on the command line', {
\ 'line': &lines,
\ 'col': 10,
\ 'minwidth': 20,
\ 'time': 500,
\})
redraw
let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
call assert_match('.*on the command line.*', line)
sleep 700m
redraw
let line = join(map(range(1, 30), 'screenstring(&lines, v:val)'), '')
call assert_notmatch('.*on the command line.*', line)
bwipe!
endfunc
func Test_popup_hide()
topleft vnew
call setline(1, 'hello')
let winid = popup_create('world', {
\ 'line': 1,
\ 'col': 1,
\ 'minwidth': 20,
\})
redraw
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
call assert_equal('world', line)
call popup_hide(winid)
redraw
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
call assert_equal('hello', line)
call popup_show(winid)
redraw
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
call assert_equal('world', line)
call popup_close(winid)
redraw
let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
call assert_equal('hello', line)
" error is given for existing non-popup window
call assert_fails('call popup_hide(win_getid())', 'E993:')
" no error non-existing window
call popup_hide(1234234)
call popup_show(41234234)
bwipe!
endfunc
func Test_popup_move()
topleft vnew
call setline(1, 'hello')
let winid = popup_create('world', {
\ 'line': 1,
\ 'col': 1,
\ 'minwidth': 20,
\})
redraw
let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
call assert_equal('world ', line)
call popup_move(winid, {'line': 2, 'col': 2})
redraw
let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
call assert_equal('hello ', line)
let line = join(map(range(1, 6), 'screenstring(2, v:val)'), '')
call assert_equal('~world', line)
call popup_move(winid, {'line': 1})
redraw
let line = join(map(range(1, 6), 'screenstring(1, v:val)'), '')
call assert_equal('hworld', line)
call popup_close(winid)
bwipe!
endfunc
func Test_popup_getposition()
let winid = popup_create('hello', {
\ 'line': 2,
\ 'col': 3,
\ 'minwidth': 10,
\ 'minheight': 11,
\})
redraw
let res = popup_getposition(winid)
call assert_equal(2, res.line)
call assert_equal(3, res.col)
call assert_equal(10, res.width)
call assert_equal(11, res.height)
call popup_close(winid)
endfunc
func Test_popup_width_longest()
let tests = [
\ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
\ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
\ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
\ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
\ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
\ ]
for test in tests
let winid = popup_create(test[0], {'line': 2, 'col': 3})
redraw
let position = popup_getposition(winid)
call assert_equal(test[1], position.width)
call popup_close(winid)
endfor
endfunc
func Test_popup_wraps()
let tests = [
\ ['nowrap', 6, 1],
\ ['a line that wraps once', 12, 2],
\ ['a line that wraps two times', 12, 3],
\ ]
for test in tests
let winid = popup_create(test[0],
\ {'line': 2, 'col': 3, 'maxwidth': 12})
redraw
let position = popup_getposition(winid)
call assert_equal(test[1], position.width)
call assert_equal(test[2], position.height)
call popup_close(winid)
endfor
endfunc
|