| 41 | } |
| 42 | } |
| 43 | func TestRenderInbuiltStylesPorts(t *testing.T) { |
| 44 | tests := []BoxStyle{ |
| 45 | Single, |
| 46 | SingleDouble, |
| 47 | Double, |
| 48 | DoubleSingle, |
| 49 | Bold, |
| 50 | Round, |
| 51 | Hidden, |
| 52 | Classic, |
| 53 | Block, |
| 54 | } |
| 55 | |
| 56 | for _, style := range tests { |
| 57 | preset, ok := boxes[style] |
| 58 | if !ok { |
| 59 | t.Fatalf("no preset found for style %q", style) |
| 60 | } |
| 61 | |
| 62 | b := NewBox().Padding(2, 5).Style(style) |
| 63 | out, err := b.Render("Box CLI Maker", "Highly Customized Terminal Box Maker") |
| 64 | if err != nil { |
| 65 | t.Fatalf("Render returned error for style %q: %v", style, err) |
| 66 | } |
| 67 | |
| 68 | lines := strings.Split(out, "\n") |
| 69 | if len(lines) < 3 { |
| 70 | t.Fatalf("style %q: expected at least 3 lines, got %d", style, len(lines)) |
| 71 | } |
| 72 | |
| 73 | // Last element is empty due to trailing newline; bottom bar is at len-2. |
| 74 | top := lines[0] |
| 75 | bottom := lines[len(lines)-2] |
| 76 | |
| 77 | if !strings.HasPrefix(top, preset.topLeft) || !strings.HasSuffix(top, preset.topRight) { |
| 78 | t.Errorf("style %q: unexpected top corners: %q", style, top) |
| 79 | } |
| 80 | if !strings.HasPrefix(bottom, preset.bottomLeft) || !strings.HasSuffix(bottom, preset.bottomRight) { |
| 81 | t.Errorf("style %q: unexpected bottom corners: %q", style, bottom) |
| 82 | } |
| 83 | |
| 84 | // Check that interior lines use the expected vertical glyphs (including |
| 85 | // the Hidden style, where vertical is a space). |
| 86 | if len(lines) > 3 { |
| 87 | interior := lines[1 : len(lines)-2] |
| 88 | mid := interior[len(interior)/2] |
| 89 | if len(mid) == 0 { |
| 90 | t.Errorf("style %q: mid interior line unexpectedly empty", style) |
| 91 | } else { |
| 92 | if !strings.HasPrefix(mid, preset.vertical) || !strings.HasSuffix(mid, preset.vertical) { |
| 93 | t.Errorf("style %q: unexpected vertical borders in interior line: %q", style, mid) |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | func TestRenderDefaultStyleWithoutExplicitStyle(t *testing.T) { |