MCPcopy Create free account
hub / github.com/box-cli-maker/box-cli-maker / TestRenderTitlePositions

Function TestRenderTitlePositions

box_render_test.go:226–279  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

224}
225
226func TestRenderTitlePositions(t *testing.T) {
227 title := "My Title"
228 content := "Some content"
229
230 cases := []struct {
231 name string
232 pos TitlePosition
233 }{
234 {"inside", Inside},
235 {"top", Top},
236 {"bottom", Bottom},
237 }
238
239 for _, tc := range cases {
240 t.Run(tc.name, func(t *testing.T) {
241 b := NewBox().Padding(2, 1).Style(Single).TitlePosition(tc.pos)
242 out, err := b.Render(title, content)
243 if err != nil {
244 t.Fatalf("Render returned error for position %v: %v", tc.pos, err)
245 }
246
247 lines := strings.Split(out, "\n")
248 if len(lines) < 3 {
249 t.Fatalf("expected at least 3 lines, got %d", len(lines))
250 }
251 top := lines[0]
252 bottom := lines[len(lines)-2]
253 interior := lines[1 : len(lines)-2]
254
255 hasTitleInside := false
256 for _, l := range interior {
257 if strings.Contains(l, title) {
258 hasTitleInside = true
259 break
260 }
261 }
262
263 switch tc.pos {
264 case Inside:
265 if !hasTitleInside {
266 t.Errorf("expected title to appear inside box for Inside position; output: %q", out)
267 }
268 case Top:
269 if !strings.Contains(top, title) {
270 t.Errorf("expected title to appear in top bar for Top position; top: %q", top)
271 }
272 case Bottom:
273 if !strings.Contains(bottom, title) {
274 t.Errorf("expected title to appear in bottom bar for Bottom position; bottom: %q", bottom)
275 }
276 }
277 })
278 }
279}
280
281func TestRenderInvalidBoxStyle(t *testing.T) {
282 b := NewBox().Padding(2, 1).Style(BoxStyle("InvalidStyle"))

Callers

nothing calls this directly

Calls 5

NewBoxFunction · 0.85
TitlePositionMethod · 0.80
StyleMethod · 0.80
PaddingMethod · 0.80
RenderMethod · 0.80

Tested by

no test coverage detected