blob: b1127557cab9dba5fc085494d99f7c7cede53c6c [file] [log] [blame]
Bram Moolenaar8e956362019-08-25 23:08:17 +02001" Tests for popup windows for text properties
2
3source check.vim
4CheckFeature textprop
5
6source screendump.vim
7CheckScreendump
8
9func Test_textprop_popup()
10 let lines =<< trim END
11 call setline(1, range(1, 100))
12 call setline(50, 'some text to work with')
13 50
14 normal zz
15 set scrolloff=0
Bram Moolenaara37cb552019-11-16 20:03:31 +010016 call prop_type_add('popupMarker', #{highlight: 'DiffAdd', bufnr: bufnr('%')})
Bram Moolenaar8e956362019-08-25 23:08:17 +020017 call prop_add(50, 11, #{
18 \ length: 7,
19 \ type: 'popupMarker',
Bram Moolenaara37cb552019-11-16 20:03:31 +010020 \ bufnr: bufnr('%'),
Bram Moolenaar8e956362019-08-25 23:08:17 +020021 \ })
22 let winid = popup_create('the text', #{
23 \ pos: 'botleft',
24 \ textprop: 'popupMarker',
25 \ border: [],
26 \ padding: [0,1,0,1],
27 \ close: 'click',
28 \ })
29 END
30 call writefile(lines, 'XtestTextpropPopup')
31 let buf = RunVimInTerminal('-S XtestTextpropPopup', #{rows: 10})
32 call VerifyScreenDump(buf, 'Test_popup_textprop_01', {})
33
34 call term_sendkeys(buf, "zt")
35 call VerifyScreenDump(buf, 'Test_popup_textprop_02', {})
36
37 call term_sendkeys(buf, "zzIawe\<Esc>")
38 call VerifyScreenDump(buf, 'Test_popup_textprop_03', {})
39
40 call term_sendkeys(buf, "0dw")
41 call VerifyScreenDump(buf, 'Test_popup_textprop_04', {})
42
43 call term_sendkeys(buf, "Oinserted\<Esc>")
44 call VerifyScreenDump(buf, 'Test_popup_textprop_05', {})
45
46 call term_sendkeys(buf, "k2dd")
47 call VerifyScreenDump(buf, 'Test_popup_textprop_06', {})
48
Bram Moolenaar1fb08312019-08-29 20:02:11 +020049 call term_sendkeys(buf, "4\<C-E>")
50 call VerifyScreenDump(buf, 'Test_popup_textprop_07', {})
51
Bram Moolenaar8e956362019-08-25 23:08:17 +020052 " clean up
53 call StopVimInTerminal(buf)
54 call delete('XtestTextpropPopup')
55endfunc
56
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020057func Test_textprop_popup_corners()
58 let lines =<< trim END
59 call setline(1, range(1, 100))
60 call setline(50, 'now working with some longer text here')
61 50
62 normal zz
63 set scrolloff=0
64 call prop_type_add('popupMarker', #{highlight: 'DiffAdd'})
65 call prop_add(50, 23, #{
66 \ length: 6,
67 \ type: 'popupMarker',
68 \ })
69 let winid = popup_create('bottom left', #{
70 \ pos: 'botleft',
71 \ textprop: 'popupMarker',
Bram Moolenaara37cb552019-11-16 20:03:31 +010072 \ textpropwin: win_getid(),
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +020073 \ padding: [0,1,0,1],
74 \ })
75 let winid = popup_create('bottom right', #{
76 \ pos: 'botright',
77 \ textprop: 'popupMarker',
78 \ border: [],
79 \ padding: [0,1,0,1],
80 \ })
81 let winid = popup_create('top left', #{
82 \ pos: 'topleft',
83 \ textprop: 'popupMarker',
84 \ border: [],
85 \ padding: [0,1,0,1],
86 \ })
87 let winid = popup_create('top right', #{
88 \ pos: 'topright',
89 \ textprop: 'popupMarker',
90 \ padding: [0,1,0,1],
91 \ })
92 END
93 call writefile(lines, 'XtestTextpropPopupCorners')
94 let buf = RunVimInTerminal('-S XtestTextpropPopupCorners', #{rows: 12})
95 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_1', {})
96
97 call term_sendkeys(buf, "0dw")
98 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_2', {})
99
100 call term_sendkeys(buf, "46Goextra\<Esc>")
101 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_3', {})
102
103 call term_sendkeys(buf, "u")
Bram Moolenaar57441d62019-08-28 22:38:07 +0200104 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +0200105 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_4', {})
106
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200107 call term_sendkeys(buf, ":vsplit foo\<CR>")
108 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_5', {})
109
110 call term_sendkeys(buf, ":only!\<CR>")
111 call VerifyScreenDump(buf, 'Test_popup_textprop_corn_6', {})
112
Bram Moolenaarbc2d4c12019-08-28 22:18:30 +0200113 " clean up
114 call StopVimInTerminal(buf)
115 call delete('XtestTextpropPopupCorners')
116endfunc
117
Bram Moolenaar1fb08312019-08-29 20:02:11 +0200118func Test_textprop_popup_offsets()
119 let lines =<< trim END
120 call setline(1, range(1, 100))
121 call setline(50, 'now working with some longer text here')
122 50
123 normal zz
124 set scrolloff=0
125 call prop_type_add('popupMarker', #{highlight: 'DiffAdd'})
126 call prop_add(50, 23, #{
127 \ length: 6,
128 \ type: 'popupMarker',
129 \ })
130 let winid = popup_create('bottom left', #{
131 \ pos: 'botleft',
132 \ line: -1,
133 \ col: 2,
134 \ textprop: 'popupMarker',
135 \ padding: [0,1,0,1],
136 \ })
137 let winid = popup_create('bottom right', #{
138 \ pos: 'botright',
139 \ line: -1,
140 \ col: -2,
141 \ textprop: 'popupMarker',
142 \ border: [],
143 \ padding: [0,1,0,1],
144 \ })
145 let winid = popup_create('top left', #{
146 \ pos: 'topleft',
147 \ line: 1,
148 \ col: 2,
149 \ textprop: 'popupMarker',
150 \ border: [],
151 \ padding: [0,1,0,1],
152 \ })
153 let winid = popup_create('top right', #{
154 \ pos: 'topright',
155 \ line: 1,
156 \ col: -2,
157 \ textprop: 'popupMarker',
158 \ padding: [0,1,0,1],
159 \ })
160 END
161 call writefile(lines, 'XtestTextpropPopupOffset')
162 let buf = RunVimInTerminal('-S XtestTextpropPopupOffset', #{rows: 12})
163 call VerifyScreenDump(buf, 'Test_popup_textprop_off_1', {})
164
165 " test that removing the text property closes the popups
166 call term_sendkeys(buf, ":call prop_clear(50)\<CR>")
167 call VerifyScreenDump(buf, 'Test_popup_textprop_off_2', {})
168
169 " clean up
170 call StopVimInTerminal(buf)
171 call delete('XtestTextpropPopupOffset')
172endfunc
173
Bram Moolenaar8e956362019-08-25 23:08:17 +0200174
175" vim: shiftwidth=2 sts=2