-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmatrix_test.go
More file actions
109 lines (97 loc) · 2.2 KB
/
Copy pathmatrix_test.go
File metadata and controls
109 lines (97 loc) · 2.2 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
package main
import (
"strings"
"testing"
)
func TestBuildMatrixCards_TitleCard(t *testing.T) {
info := repoInfo{
name: "testproject",
totalCommits: 50,
contributors: []contributor{
{name: "Alice", commits: 50},
},
}
cards := buildMatrixCards(info, 80, 24)
if len(cards) == 0 {
t.Fatal("buildMatrixCards returned no cards")
}
// first card should have title
found := false
for _, l := range cards[0].lines {
if strings.Contains(l, "██") {
found = true
break
}
}
if !found {
t.Error("first card should contain ASCII art title")
}
}
func TestBuildMatrixCards_HeroCards(t *testing.T) {
info := repoInfo{
name: "test",
totalCommits: 30,
contributors: []contributor{
{name: "Alice", commits: 20},
{name: "Bob", commits: 10},
},
}
cards := buildMatrixCards(info, 80, 24)
// should have: title + 2 hero cards + stats + will return = 5 minimum
if len(cards) < 4 {
t.Errorf("expected at least 4 cards, got %d", len(cards))
}
}
func TestBuildMatrixCards_WillReturn(t *testing.T) {
info := repoInfo{
name: "test",
totalCommits: 1,
contributors: []contributor{
{name: "Alice", commits: 1},
},
}
cards := buildMatrixCards(info, 80, 24)
lastCard := cards[len(cards)-1]
found := false
for _, l := range lastCard.lines {
if strings.Contains(l, "THE CONTRIBUTORS WILL RETURN") {
found = true
break
}
}
if !found {
t.Error("last card should contain 'THE CONTRIBUTORS WILL RETURN'")
}
}
func TestMatrixHeroTitle(t *testing.T) {
tests := []struct {
rank int
commits int
want string
}{
{0, 200, "THE ARCHITECT"},
{0, 50, "THE FOUNDER"},
{1, 10, "THE GUARDIAN"},
}
for _, tt := range tests {
got := matrixHeroTitle(tt.rank, tt.commits)
if got != tt.want {
t.Errorf("matrixHeroTitle(%d, %d) = %q, want %q", tt.rank, tt.commits, got, tt.want)
}
}
}
func TestBuildMatrixCards_CardHeight(t *testing.T) {
info := repoInfo{
name: "test",
totalCommits: 1,
contributors: []contributor{
{name: "Alice", commits: 1},
},
}
cards := buildMatrixCards(info, 80, 24)
for i, card := range cards {
if len(card.lines) != 24 {
t.Errorf("card %d has %d lines, want 24", i, len(card.lines))
}
}
}