-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
118 lines (112 loc) · 2.46 KB
/
main_test.go
File metadata and controls
118 lines (112 loc) · 2.46 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
package main
import (
"reflect"
"testing"
"github.com/Haugen/bcu/renderer"
)
func TestParseBranches(t *testing.T) {
tests := []struct {
name string
input string
expected []renderer.Branch
}{
{
name: "typical git branch output with current branch",
input: `* main
feature-1
feature-2
bugfix-123`,
expected: []renderer.Branch{
{Name: "feature-1", IsActive: false},
{Name: "feature-2", IsActive: false},
{Name: "bugfix-123", IsActive: false},
},
},
{
name: "output with master branch",
input: ` develop
* master
hotfix-456`,
expected: []renderer.Branch{
{Name: "develop", IsActive: false},
{Name: "hotfix-456", IsActive: false},
},
},
{
name: "output with both main and master",
input: `* main
master
feature-a
feature-b`,
expected: []renderer.Branch{
{Name: "feature-a", IsActive: false},
{Name: "feature-b", IsActive: false},
},
},
{
name: "only main branch exists",
input: "* main",
expected: []renderer.Branch{},
},
{
name: "empty output",
input: "",
expected: []renderer.Branch{},
},
{
name: "branches with special characters",
input: `* main
feature/new-ui
bugfix/JIRA-123
release-1.0.0`,
expected: []renderer.Branch{
{Name: "feature/new-ui", IsActive: false},
{Name: "bugfix/JIRA-123", IsActive: false},
{Name: "release-1.0.0", IsActive: false},
},
},
{
name: "output with worktree branches",
input: `* main
test
test1
test2
+ worktree-test1
+ worktree-test2`,
expected: []renderer.Branch{
{Name: "test", IsActive: false},
{Name: "test1", IsActive: false},
{Name: "test2", IsActive: false},
{Name: "worktree-test1", IsActive: true},
{Name: "worktree-test2", IsActive: true},
},
},
{
name: "mixed worktrees and regular branches",
input: ` develop
* main
+ worktree-feature
feature-1
+ worktree-hotfix
feature-2`,
expected: []renderer.Branch{
{Name: "develop", IsActive: false},
{Name: "worktree-feature", IsActive: true},
{Name: "feature-1", IsActive: false},
{Name: "worktree-hotfix", IsActive: true},
{Name: "feature-2", IsActive: false},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := parseBranches(tt.input)
if len(result) == 0 && len(tt.expected) == 0 {
return
}
if !reflect.DeepEqual(result, tt.expected) {
t.Errorf("parseBranches() = %v, want %v", result, tt.expected)
}
})
}
}