@@ -84,18 +84,19 @@ func Test_popup_with_syntax_setbufvar()
84
84
if ! CanRunVimInTerminal ()
85
85
return
86
86
endif
87
- call writefile ([
88
- \ " call setline(1, range(1, 100))" ,
89
- \ " hi PopupColor ctermbg=lightgrey" ,
90
- \ " let winid = popup_create([" ,
91
- \ " \\ '#include <stdio.h>'," ,
92
- \ " \\ 'int main(void)'," ,
93
- \ " \\ '{'," ,
94
- \ " \\ ' printf(567);'," ,
95
- \ " \\ '}'," ,
96
- \ " \\ ], {'line': 3, 'col': 21, 'highlight': 'PopupColor'})" ,
97
- \ " call setbufvar(winbufnr(winid), '&syntax', 'cpp')" ,
98
- \] , ' XtestPopup' )
87
+ let lines = << trim END
88
+ call setline (1 , range (1 , 100 ))
89
+ hi PopupColor ctermbg= lightgrey
90
+ let winid = popup_create ([
91
+ \ ' #include <stdio.h>' ,
92
+ \ ' int main(void)' ,
93
+ \ ' {' ,
94
+ \ ' printf(567);' ,
95
+ \ ' }' ,
96
+ \] , {' line' : 3 , ' col' : 21 , ' highlight' : ' PopupColor' })
97
+ call setbufvar (winbufnr (winid), ' &syntax' , ' cpp' )
98
+ END
99
+ call writefile (lines , ' XtestPopup' )
99
100
let buf = RunVimInTerminal (' -S XtestPopup' , {' rows' : 10 })
100
101
call VerifyScreenDump (buf , ' Test_popupwin_11' , {})
101
102
@@ -104,6 +105,44 @@ func Test_popup_with_syntax_setbufvar()
104
105
call delete (' XtestPopup' )
105
106
endfunc
106
107
108
+ func Test_popup_with_wrap ()
109
+ if ! CanRunVimInTerminal ()
110
+ return
111
+ endif
112
+ let lines = << trim END
113
+ call setline (1 , range (1 , 100 ))
114
+ let winid = popup_create (
115
+ \ ' a long line that wont fit' ,
116
+ \ {' line' : 3 , ' col' : 20 , ' maxwidth' : 10 , ' wrap' : 1 })
117
+ END
118
+ call writefile (lines , ' XtestPopup' )
119
+ let buf = RunVimInTerminal (' -S XtestPopup' , {' rows' : 10 })
120
+ call VerifyScreenDump (buf , ' Test_popupwin_wrap' , {})
121
+
122
+ " clean up
123
+ call StopVimInTerminal (buf )
124
+ call delete (' XtestPopup' )
125
+ endfunc
126
+
127
+ func Test_popup_without_wrap ()
128
+ if ! CanRunVimInTerminal ()
129
+ return
130
+ endif
131
+ let lines = << trim END
132
+ call setline (1 , range (1 , 100 ))
133
+ let winid = popup_create (
134
+ \ ' a long line that wont fit' ,
135
+ \ {' line' : 3 , ' col' : 20 , ' maxwidth' : 10 , ' wrap' : 0 })
136
+ END
137
+ call writefile (lines , ' XtestPopup' )
138
+ let buf = RunVimInTerminal (' -S XtestPopup' , {' rows' : 10 })
139
+ call VerifyScreenDump (buf , ' Test_popupwin_nowrap' , {})
140
+
141
+ " clean up
142
+ call StopVimInTerminal (buf )
143
+ call delete (' XtestPopup' )
144
+ endfunc
145
+
107
146
func Test_popup_time ()
108
147
if ! has (' timers' )
109
148
return
@@ -156,19 +195,19 @@ func Test_popup_hide()
156
195
redraw
157
196
let line = join (map (range (1 , 5 ), ' screenstring(1, v:val)' ), ' ' )
158
197
call assert_equal (' world' , line )
159
- call assert_equal (1 , popup_getposition (winid).visible)
198
+ call assert_equal (1 , popup_getpos (winid).visible)
160
199
161
200
call popup_hide (winid)
162
201
redraw
163
202
let line = join (map (range (1 , 5 ), ' screenstring(1, v:val)' ), ' ' )
164
203
call assert_equal (' hello' , line )
165
- call assert_equal (0 , popup_getposition (winid).visible)
204
+ call assert_equal (0 , popup_getpos (winid).visible)
166
205
167
206
call popup_show (winid)
168
207
redraw
169
208
let line = join (map (range (1 , 5 ), ' screenstring(1, v:val)' ), ' ' )
170
209
call assert_equal (' world' , line )
171
- call assert_equal (1 , popup_getposition (winid).visible)
210
+ call assert_equal (1 , popup_getpos (winid).visible)
172
211
173
212
174
213
call popup_close (winid)
@@ -216,15 +255,15 @@ func Test_popup_move()
216
255
bwipe!
217
256
endfunc
218
257
219
- func Test_popup_getposition ()
258
+ func Test_popup_getpos ()
220
259
let winid = popup_create (' hello' , {
221
260
\ ' line' : 2 ,
222
261
\ ' col' : 3 ,
223
262
\ ' minwidth' : 10 ,
224
263
\ ' minheight' : 11 ,
225
264
\} )
226
265
redraw
227
- let res = popup_getposition (winid)
266
+ let res = popup_getpos (winid)
228
267
call assert_equal (2 , res .line )
229
268
call assert_equal (3 , res .col )
230
269
call assert_equal (10 , res .width)
@@ -246,7 +285,7 @@ func Test_popup_width_longest()
246
285
for test in tests
247
286
let winid = popup_create (test[0 ], {' line' : 2 , ' col' : 3 })
248
287
redraw
249
- let position = popup_getposition (winid)
288
+ let position = popup_getpos (winid)
250
289
call assert_equal (test[1 ], position.width)
251
290
call popup_close (winid)
252
291
endfor
@@ -262,12 +301,12 @@ func Test_popup_wraps()
262
301
let winid = popup_create (test[0 ],
263
302
\ {' line' : 2 , ' col' : 3 , ' maxwidth' : 12 })
264
303
redraw
265
- let position = popup_getposition (winid)
304
+ let position = popup_getpos (winid)
266
305
call assert_equal (test[1 ], position.width)
267
306
call assert_equal (test[2 ], position.height)
268
307
269
308
call popup_close (winid)
270
- call assert_equal ({}, popup_getposition (winid))
309
+ call assert_equal ({}, popup_getpos (winid))
271
310
endfor
272
311
endfunc
273
312
@@ -382,5 +421,23 @@ func Test_popup_atcursor()
382
421
call assert_equal (' xvimxxxxxxxxxxxxx' , line )
383
422
call popup_close (winid)
384
423
424
+ " just enough room above
425
+ call cursor (3 , 3 )
426
+ redraw
427
+ let winid = popup_atcursor ([' vim' , ' is great' ], {})
428
+ redraw
429
+ let pos = popup_getpos (winid)
430
+ call assert_equal (1 , pos.line )
431
+ call popup_close (winid)
432
+
433
+ " not enough room above, popup goes below the cursor
434
+ call cursor (3 , 3 )
435
+ redraw
436
+ let winid = popup_atcursor ([' vim' , ' is' , ' great' ], {})
437
+ redraw
438
+ let pos = popup_getpos (winid)
439
+ call assert_equal (4 , pos.line )
440
+ call popup_close (winid)
441
+
385
442
bwipe!
386
443
endfunc
0 commit comments