-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader_test.go
127 lines (124 loc) · 2.83 KB
/
header_test.go
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
package conventionalcommitparser
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseHeader(t *testing.T) {
type args struct {
txt string
}
tests := []struct {
name string
args args
want Header
}{
{
name: "commom header",
args: args{txt: "commom header"},
want: Header{Subject: "commom header"},
},
{
name: "feat: valid header",
args: args{txt: "feat: valid header"},
want: Header{
Type: "feat",
Subject: "valid header",
},
},
{
name: "feat: valid header with multiple spaces",
args: args{txt: "feat: valid header"},
want: Header{
Type: "feat",
Subject: "valid header",
},
},
{
name: "feat-with-dash: valid header with multiple spaces",
args: args{txt: "feat-with-dash: valid header"},
want: Header{
Type: "feat-with-dash",
Subject: "valid header",
},
},
{
name: "feat with space: valid header with multiple spaces",
args: args{txt: "feat with space: valid header"},
want: Header{
Type: "feat with space",
Subject: "valid header",
},
},
{
name: " feat with space prefix and suffix: valid header with multiple spaces",
args: args{txt: " feat with space prefix and suffix : valid header"},
want: Header{
Type: "feat with space prefix and suffix",
Subject: "valid header",
},
},
{
name: "feat(scope): valid header",
args: args{txt: "feat(scope): valid header"},
want: Header{
Type: "feat",
Scope: "scope",
Subject: "valid header",
},
},
{
name: "feat(scope-1): valid header",
args: args{txt: "feat(scope-1): valid header"},
want: Header{
Type: "feat",
Scope: "scope-1",
Subject: "valid header",
},
},
{
name: "feat(scope with space): valid header",
args: args{txt: "feat(scope with space): valid header"},
want: Header{
Type: "feat",
Scope: "scope with space",
Subject: "valid header",
},
},
{
name: "feat( scope with space prefix and suffix ): valid header",
args: args{txt: "feat( scope with space prefix and suffix ): valid header"},
want: Header{
Type: "feat",
Scope: "scope with space prefix and suffix",
Subject: "valid header",
},
},
{
name: "feat(scope-with-dash): valid header",
args: args{txt: "feat(scope-with-dash): valid header"},
want: Header{
Type: "feat",
Scope: "scope-with-dash",
Subject: "valid header",
},
},
{
name: "feat(scope)!: valid header",
args: args{txt: "feat(scope)!: valid header"},
want: Header{
Type: "feat",
Scope: "scope",
Subject: "valid header",
Important: true,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parseHeader(tt.args.txt); !reflect.DeepEqual(got, tt.want) {
assert.Equal(t, tt.want, got)
}
})
}
}