MCPcopy Index your code
hub / github.com/box-cli-maker/box-cli-maker / TestFormatLine_LeftAlignAndError

Function TestFormatLine_LeftAlignAndError

util_test.go:67–111  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

65}
66
67func 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
113func TestFindAlign(t *testing.T) {
114 cases := []struct {

Callers

nothing calls this directly

Calls 2

formatLineMethod · 0.95
AlignTypeTypeAlias · 0.85

Tested by

no test coverage detected