-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcredits_test.go
More file actions
152 lines (138 loc) · 3.02 KB
/
Copy pathcredits_test.go
File metadata and controls
152 lines (138 loc) · 3.02 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
"strings"
"testing"
)
func TestBuildCredits_HasTitle(t *testing.T) {
info := repoInfo{
name: "testproject",
totalCommits: 42,
contributors: []contributor{
{name: "Alice", commits: 30},
{name: "Bob", commits: 12},
},
}
lines := buildCredits(info, 80)
if len(lines) == 0 {
t.Fatal("buildCredits returned empty")
}
// should contain ASCII art title
found := false
for _, l := range lines {
if strings.Contains(l, "██") {
found = true
break
}
}
if !found {
t.Error("credits should contain ASCII art title (██)")
}
}
func TestBuildCredits_HasProjectBy(t *testing.T) {
info := repoInfo{
name: "test",
totalCommits: 10,
contributors: []contributor{
{name: "Alice", commits: 10},
},
}
lines := buildCredits(info, 80)
found := false
for _, l := range lines {
if strings.Contains(l, "A P R O J E C T B Y") {
found = true
break
}
}
if !found {
t.Error("credits should contain 'A P R O J E C T B Y'")
}
}
func TestBuildCredits_HasStarring(t *testing.T) {
info := repoInfo{
name: "test",
totalCommits: 20,
contributors: []contributor{
{name: "Alice", commits: 15},
{name: "Bob", commits: 5},
},
}
lines := buildCredits(info, 80)
found := false
for _, l := range lines {
if strings.Contains(l, "S T A R R I N G") {
found = true
break
}
}
if !found {
t.Error("credits should contain 'S T A R R I N G' when multiple contributors")
}
}
func TestBuildCredits_HasTheEnd(t *testing.T) {
info := repoInfo{
name: "test",
totalCommits: 1,
contributors: []contributor{
{name: "Alice", commits: 1},
},
}
lines := buildCredits(info, 80)
found := false
for _, l := range lines {
if strings.Contains(l, "██") && (strings.Contains(l, "THE") || strings.Contains(strings.Join(lines[len(lines)-30:], "\n"), "THE END")) {
found = true
break
}
}
// just check THE END exists in big text somewhere near the end
for _, l := range lines[len(lines)-30:] {
if strings.Contains(l, "██") {
found = true
break
}
}
if !found {
t.Error("credits should end with THE END in big text")
}
}
func TestBuildCredits_CommitCount(t *testing.T) {
info := repoInfo{
name: "test",
totalCommits: 99,
contributors: []contributor{
{name: "Alice", commits: 99},
},
}
lines := buildCredits(info, 80)
found := false
for _, l := range lines {
if strings.Contains(l, "99 C O M M I T S") {
found = true
break
}
}
if !found {
t.Error("credits should contain commit count")
}
}
func TestBigText(t *testing.T) {
rows := bigText("AB")
if len(rows) != 5 {
t.Fatalf("bigText should return 5 rows, got %d", len(rows))
}
for _, r := range rows {
if len(r) == 0 {
t.Error("bigText row should not be empty")
}
}
}
func TestCenterText(t *testing.T) {
result := centerText("hi", 10)
if !strings.HasPrefix(result, " ") {
t.Errorf("expected padding, got %q", result)
}
if strings.TrimSpace(result) != "hi" {
t.Errorf("expected 'hi' centered, got %q", result)
}
}