repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

test(cmdline): add tests for per-format corner highlights

688ab0a31f2820b3f5e6097ff67fb14956b16f0c

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Test that:
- winhighlight contains different border and corner groups
- corner is CmdlineBorderCornerCmdline for cmdline format
- corner is CmdlineBorderCornerHelp for help format
- corner highlight updates when format changes between show calls

Changed files (1)

neovim/tests/bugabinga/cmdline/render_spec.lua

Modified
135 135 local anchor = pos.get_cmdline_anchor()
136 136 assert.is_nil(anchor)
138 +end)
140 +describe('render corner highlights', function()
141 + before_each(function()
142 + package.loaded['bugabinga.cmdline.state'] = nil
143 + package.loaded['bugabinga.cmdline.format'] = nil
144 + package.loaded['bugabinga.cmdline.position'] = nil
145 + package.loaded['bugabinga.cmdline.cursor'] = nil
146 + package.loaded['bugabinga.cmdline.render'] = nil
147 + end)
149 + after_each(function()
150 + local ok, render = pcall(require, 'bugabinga.cmdline.render')
151 + if ok then
152 + render.hide()
153 + end
154 + local ok2, pos = pcall(require, 'bugabinga.cmdline.position')
155 + if ok2 then
156 + pos.set_cmdline_anchor(nil)
157 + end
158 + end)
160 + it('winhighlight contains different border and corner highlights', function()
161 + local state = require 'bugabinga.cmdline.state'
162 + local render = require 'bugabinga.cmdline.render'
163 + local cmdline_state = state.new({
164 + { {}, ':test' },
165 + }, 1, ':', '', 0, 1)
166 + render.show(cmdline_state)
167 + local pos = require('bugabinga.cmdline.position')
168 + local anchor = pos.get_cmdline_anchor()
169 + local wh = vim.wo[anchor.win].winhighlight
170 + local border_hl = wh:match 'FloatBorder:(%w+)'
171 + local corner_hl = wh:match 'FloatBorderCorner:(%w+)'
172 + assert.is_not_nil(border_hl, 'FloatBorder highlight not found in: ' .. wh)
173 + assert.is_not_nil(corner_hl, 'FloatBorderCorner highlight not found in: ' .. wh)
174 + assert.is_true(border_hl ~= corner_hl, 'border and corner should differ')
175 + render.hide()
176 + end)
178 + it('corner highlight is CmdlineBorderCornerCmdline for cmdline format', function()
179 + local state = require 'bugabinga.cmdline.state'
180 + local render = require 'bugabinga.cmdline.render'
181 + local cmdline_state = state.new({
182 + { {}, '' },
183 + }, 1, ':', '', 0, 1)
184 + render.show(cmdline_state)
185 + local pos = require('bugabinga.cmdline.position')
186 + local anchor = pos.get_cmdline_anchor()
187 + local wh = vim.wo[anchor.win].winhighlight
188 + local corner_hl = wh:match 'FloatBorderCorner:(%w+)'
189 + assert.equals('CmdlineBorderCornerCmdline', corner_hl)
190 + render.hide()
191 + end)
193 + it('corner highlight is CmdlineBorderCornerHelp for help format', function()
194 + local state = require 'bugabinga.cmdline.state'
195 + local render = require 'bugabinga.cmdline.render'
196 + local cmdline_state = state.new({
197 + { {}, 'h' },
198 + }, 2, ':', '', 0, 1)
199 + render.show(cmdline_state)
200 + local pos = require('bugabinga.cmdline.position')
201 + local anchor = pos.get_cmdline_anchor()
202 + local wh = vim.wo[anchor.win].winhighlight
203 + local corner_hl = wh:match 'FloatBorderCorner:(%w+)'
204 + assert.equals('CmdlineBorderCornerHelp', corner_hl)
205 + render.hide()
206 + end)
208 + it('corner highlight updates when format changes between show calls', function()
209 + local state = require 'bugabinga.cmdline.state'
210 + local render = require 'bugabinga.cmdline.render'
211 + local cmdline_state1 = state.new({
212 + { {}, '' },
213 + }, 1, ':', '', 0, 1)
214 + render.show(cmdline_state1)
215 + local pos = require('bugabinga.cmdline.position')
216 + local anchor1 = pos.get_cmdline_anchor()
217 + local wh1 = vim.wo[anchor1.win].winhighlight
218 + local corner1 = wh1:match 'FloatBorderCorner:(%w+)'
219 + local cmdline_state2 = state.new({
220 + { {}, 'h' },
221 + }, 2, ':', '', 0, 1)
222 + render.show(cmdline_state2)
223 + local anchor2 = pos.get_cmdline_anchor()
224 + local wh2 = vim.wo[anchor2.win].winhighlight
225 + local corner2 = wh2:match 'FloatBorderCorner:(%w+)'
226 + assert.is_true(corner1 ~= corner2, 'corner should change: ' .. corner1 .. ' vs ' .. corner2)
227 + render.hide()
228 + end)