Repository navigation
Expand file tree
/
Copy pathgitmeta_test.go
More file actions
117 lines (102 loc) · 2.94 KB
/
Copy pathgitmeta_test.go
File metadata and controls
117 lines (102 loc) · 2.94 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
package main
import (
"testing"
)
func TestBranchNameToSuggestionsFeat(t *testing.T) {
ct, scope, _ := branchNameToSuggestions("feat/api-pagination")
if ct != "feat" {
t.Errorf("expected type=feat, got %s", ct)
}
if scope != "api-pagination" {
t.Errorf("expected scope=api-pagination, got %s", scope)
}
}
func TestBranchNameToSuggestionsFeatureAlias(t *testing.T) {
ct, _, _ := branchNameToSuggestions("feature/add-oauth")
if ct != "feat" {
t.Errorf("expected type=feat for 'feature/', got %s", ct)
}
}
func TestBranchNameToSuggestionsHotfixAlias(t *testing.T) {
ct, _, _ := branchNameToSuggestions("hotfix/urgent-crash")
if ct != "fix" {
t.Errorf("expected type=fix for 'hotfix/', got %s", ct)
}
}
func TestBranchNameToSuggestionsIssueNumber(t *testing.T) {
_, _, issue := branchNameToSuggestions("fix/123-login-bug")
if issue != "123" {
t.Errorf("expected issue=123, got %s", issue)
}
}
func TestBranchNameToSuggestionsHashPrefix(t *testing.T) {
_, _, issue := branchNameToSuggestions("feature/#456-add-thing")
if issue != "456" {
t.Errorf("expected issue=456, got %s", issue)
}
}
func TestBranchNameToSuggestionsRemotePrefix(t *testing.T) {
ct, scope, _ := branchNameToSuggestions("origin/feat/test")
if ct != "feat" {
t.Errorf("expected type=feat, got %s", ct)
}
if scope != "test" {
t.Errorf("expected scope=test, got %s", scope)
}
}
func TestBranchNameToSuggestionsNoPrefix(t *testing.T) {
ct, _, issue := branchNameToSuggestions("123-just-a-branch")
if ct != "" {
t.Errorf("expected empty type, got %s", ct)
}
_ = issue // issue may or may not be set depending on parsing
}
func TestBranchNameToSuggestionsEmpty(t *testing.T) {
ct, scope, issue := branchNameToSuggestions("")
if ct != "" || scope != "" || issue != "" {
t.Errorf("expected all empty for empty branch")
}
}
func TestBranchNameToSuggestionsHEAD(t *testing.T) {
ct, _, _ := branchNameToSuggestions("HEAD")
if ct != "" {
t.Errorf("expected empty type for HEAD")
}
}
func TestExtractIssueNumberDirect(t *testing.T) {
if n := extractIssueNumber("#42"); n != "42" {
t.Errorf("expected 42, got %s", n)
}
}
func TestExtractIssueNumberInBranch(t *testing.T) {
if n := extractIssueNumber("feature/add-thing-789"); n != "789" {
t.Errorf("expected 789, got %s", n)
}
}
func TestExtractIssueNumberNone(t *testing.T) {
if n := extractIssueNumber("no-numbers-here"); n != "" {
t.Errorf("expected empty, got %s", n)
}
}
func TestIsAllDigits(t *testing.T) {
if !isAllDigits("123") {
t.Error("expected true for '123'")
}
if isAllDigits("12a") {
t.Error("expected false for '12a'")
}
if isAllDigits("") {
t.Error("expected false for empty string")
}
}
func TestCommitTypeAliases(t *testing.T) {
if len(commitTypeAliases("feat")) == 0 {
t.Error("expected aliases for feat")
}
if len(commitTypeAliases("fix")) == 0 {
t.Error("expected aliases for fix")
}
if len(commitTypeAliases("unknown")) != 0 {
t.Error("expected no aliases for unknown type")
}
}