(t *testing.T)
| 65 | } |
| 66 | |
| 67 | func TestFormatLine_LeftAlignAndError(t *testing.T) { |
| 68 | // Happy path: left-aligned content, no title |
| 69 | b := &Box{vertical: "|"} |
| 70 | b.contentAlign = Left |
| 71 | |
| 72 | lines := []expandedLine{{line: "hi", len: 2}} |
| 73 | sideMargin := " " |
| 74 | texts, err := b.formatLine(lines, 2, 0, sideMargin, "", nil) |
| 75 | if err != nil { |
| 76 | t.Fatalf("formatLine unexpected error: %v", err) |
| 77 | } |
| 78 | if len(texts) != 1 { |
| 79 | t.Fatalf("expected 1 formatted line, got %d", len(texts)) |
| 80 | } |
| 81 | |
| 82 | // With left alignment and no additional padding the layout is: |
| 83 | // sep + sideMargin + line + spacing + sideMargin + sep |
| 84 | // where spacing == sideMargin and sep == "|". |
| 85 | want := "| hi |" |
| 86 | if texts[0] != want { |
| 87 | t.Errorf("formatted line mismatch: want %q, got %q", want, texts[0]) |
| 88 | } |
| 89 | |
| 90 | // Title line with Inside position should not call findAlign (even if contentAlign is invalid). |
| 91 | b = &Box{vertical: "|"} |
| 92 | b.titlePos = Inside |
| 93 | b.contentAlign = AlignType("InvalidAlign") |
| 94 | lines = []expandedLine{{line: "Title", len: len("Title")}} |
| 95 | texts, err = b.formatLine(lines, len("Title"), 1, sideMargin, "Title", nil) |
| 96 | if err != nil { |
| 97 | t.Fatalf("formatLine for title line should not error, got: %v", err) |
| 98 | } |
| 99 | if len(texts) != 1 || !strings.Contains(texts[0], "Title") { |
| 100 | t.Errorf("expected formatted title line containing 'Title', got %q", texts[0]) |
| 101 | } |
| 102 | |
| 103 | // Error path: invalid alignment when not formatting a title line. |
| 104 | b = &Box{vertical: "|"} |
| 105 | b.contentAlign = AlignType("InvalidAlign") |
| 106 | lines = []expandedLine{{line: "hi", len: 2}} |
| 107 | _, err = b.formatLine(lines, 2, 0, sideMargin, "", nil) |
| 108 | if err == nil { |
| 109 | t.Fatalf("expected error for invalid content alignment, got nil") |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | func TestFindAlign(t *testing.T) { |
| 114 | cases := []struct { |
nothing calls this directly
no test coverage detected