-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbanner_test.go
More file actions
78 lines (72 loc) · 2.25 KB
/
Copy pathbanner_test.go
File metadata and controls
78 lines (72 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package gofiglet
import (
"image/color"
"strings"
"testing"
)
func TestNewCmdBanner_DefaultPadding(t *testing.T) {
b, err := NewCmdBanner([]string{"Test"}, WithColors([]color.Color{ColorCyan}))
if err != nil {
t.Fatalf("NewCmdBanner() error = %v", err)
}
if b.TopPadding != 1 {
t.Errorf("default TopPadding = %d, want 1", b.TopPadding)
}
if b.BottomPadding != 0 {
t.Errorf("default BottomPadding = %d, want 0", b.BottomPadding)
}
}
func TestWithPadding(t *testing.T) {
b, err := NewCmdBanner([]string{"Test"}, WithPadding(3, 2), WithColors([]color.Color{ColorCyan}))
if err != nil {
t.Fatalf("NewCmdBanner() error = %v", err)
}
if b.TopPadding != 3 {
t.Errorf("TopPadding = %d, want 3", b.TopPadding)
}
if b.BottomPadding != 2 {
t.Errorf("BottomPadding = %d, want 2", b.BottomPadding)
}
}
func TestCmdBanner_TopPadding(t *testing.T) {
b, err := NewCmdBanner([]string{"Test"}, WithPadding(2, 0), WithColors([]color.Color{ColorCyan}))
if err != nil {
t.Fatalf("NewCmdBanner() error = %v", err)
}
result, err := CmdBanner(b)
if err != nil {
t.Fatalf("CmdBanner() error = %v", err)
}
if !strings.HasPrefix(result, "\n\n") {
t.Errorf("expected 2 leading newlines from TopPadding=2, got: %q", result[:min(20, len(result))])
}
if strings.HasPrefix(result, "\n\n\n") {
t.Errorf("expected exactly 2 leading newlines from TopPadding=2, got 3")
}
}
func TestCmdBanner_BottomPadding(t *testing.T) {
b, err := NewCmdBanner([]string{"Test"}, WithPadding(0, 2), WithColors([]color.Color{ColorCyan}))
if err != nil {
t.Fatalf("NewCmdBanner() error = %v", err)
}
result, err := CmdBanner(b)
if err != nil {
t.Fatalf("CmdBanner() error = %v", err)
}
if !strings.HasSuffix(result, "\n\n\n") {
t.Errorf("expected 3 trailing newlines (renderer \\n + BottomPadding=2), got: %q", result[max(0, len(result)-20):])
}
}
func TestCmdBanner_NoPadding(t *testing.T) {
b, err := NewCmdBanner([]string{"Test"}, WithPadding(0, 0), WithColors([]color.Color{ColorCyan}))
if err != nil {
t.Fatalf("NewCmdBanner() error = %v", err)
}
result, err := CmdBanner(b)
if err != nil {
t.Fatalf("CmdBanner() error = %v", err)
}
if strings.HasPrefix(result, "\n") {
t.Errorf("expected no leading newline with TopPadding=0, got: %q", result[:min(20, len(result))])
}
}