@@ -9,18 +9,6 @@ import (
9
9
"github.com/stretchr/testify/require"
10
10
)
11
11
12
- func compareCommit (c * semrel.Commit , t , s string , change * semrel.Change ) bool {
13
- if c .Type != t || c .Scope != s {
14
- return false
15
- }
16
- if c .Change .Major != change .Major ||
17
- c .Change .Minor != change .Minor ||
18
- c .Change .Patch != change .Patch {
19
- return false
20
- }
21
- return true
22
- }
23
-
24
12
func createRawCommit (sha , message string ) * semrel.RawCommit {
25
13
return & semrel.RawCommit {
26
14
SHA : sha ,
@@ -77,13 +65,13 @@ func TestDefaultAnalyzer(t *testing.T) {
77
65
createRawCommit ("e" , "feat!: modified login endpoint" ),
78
66
"feat" ,
79
67
"" ,
80
- & semrel.Change {Major : true , Minor : false , Patch : false },
68
+ & semrel.Change {Major : true , Minor : true , Patch : false },
81
69
},
82
70
{
83
71
createRawCommit ("f" , "fix!: fixed a typo" ),
84
72
"fix" ,
85
73
"" ,
86
- & semrel.Change {Major : true , Minor : false , Patch : false },
74
+ & semrel.Change {Major : true , Minor : false , Patch : true },
87
75
},
88
76
{
89
77
createRawCommit ("g" , "refactor(parser)!: drop support for Node 6\n \n BREAKING CHANGE: refactor to use JavaScript features not available in Node 6." ),
@@ -103,71 +91,81 @@ func TestDefaultAnalyzer(t *testing.T) {
103
91
"" ,
104
92
& semrel.Change {Major : false , Minor : false , Patch : false },
105
93
},
94
+ {
95
+ createRawCommit ("i" , "feat(deps): update deps\n \n BREAKING CHANGE: update to new version of dep" ),
96
+ "feat" ,
97
+ "deps" ,
98
+ & semrel.Change {Major : true , Minor : true , Patch : false },
99
+ },
106
100
}
107
101
108
102
defaultAnalyzer := & DefaultCommitAnalyzer {}
109
103
for _ , tc := range testCases {
110
104
t .Run (fmt .Sprintf ("AnalyzeCommitMessage: %s" , tc .RawCommit .RawMessage ), func (t * testing.T ) {
111
- require .True (t , compareCommit (defaultAnalyzer .analyzeSingleCommit (tc .RawCommit ), tc .Type , tc .Scope , tc .Change ))
105
+ analyzedCommit := defaultAnalyzer .analyzeSingleCommit (tc .RawCommit )
106
+ require .Equal (t , tc .Type , analyzedCommit .Type , "Type" )
107
+ require .Equal (t , tc .Scope , analyzedCommit .Scope , "Scope" )
108
+ require .Equal (t , tc .Change .Major , analyzedCommit .Change .Major , "Major" )
109
+ require .Equal (t , tc .Change .Minor , analyzedCommit .Change .Minor , "Minor" )
110
+ require .Equal (t , tc .Change .Patch , analyzedCommit .Change .Patch , "Patch" )
112
111
})
113
112
}
114
113
}
115
114
116
115
func TestCommitPattern (t * testing.T ) {
117
116
testCases := []struct {
118
- rawMessage string
119
- wanted []string
117
+ message string
118
+ wanted []string
120
119
}{
121
120
{
122
- rawMessage : "feat: new feature" ,
123
- wanted : []string {"feat" , "" , "" , "new feature" },
121
+ message : "feat: new feature" ,
122
+ wanted : []string {"feat" , "" , "" , "new feature" },
124
123
},
125
124
{
126
- rawMessage : "feat!: new feature" ,
127
- wanted : []string {"feat" , "" , "!" , "new feature" },
125
+ message : "feat!: new feature" ,
126
+ wanted : []string {"feat" , "" , "!" , "new feature" },
128
127
},
129
128
{
130
- rawMessage : "feat(api): new feature" ,
131
- wanted : []string {"feat" , "api" , "" , "new feature" },
129
+ message : "feat(api): new feature" ,
130
+ wanted : []string {"feat" , "api" , "" , "new feature" },
132
131
},
133
132
{
134
- rawMessage : "feat(api): a(b): c:" ,
135
- wanted : []string {"feat" , "api" , "" , "a(b): c:" },
133
+ message : "feat(api): a(b): c:" ,
134
+ wanted : []string {"feat" , "api" , "" , "a(b): c:" },
136
135
},
137
136
{
138
- rawMessage : "feat(new cool-api): feature" ,
139
- wanted : []string {"feat" , "new cool-api" , "" , "feature" },
137
+ message : "feat(new cool-api): feature" ,
138
+ wanted : []string {"feat" , "new cool-api" , "" , "feature" },
140
139
},
141
140
{
142
- rawMessage : "feat(π
): cool" ,
143
- wanted : []string {"feat" , "π
" , "" , "cool" },
141
+ message : "feat(π
): cool" ,
142
+ wanted : []string {"feat" , "π
" , "" , "cool" },
144
143
},
145
144
{
146
- rawMessage : "this-is-also(valid): cool" ,
147
- wanted : []string {"this-is-also" , "valid" , "" , "cool" },
145
+ message : "this-is-also(valid): cool" ,
146
+ wanted : []string {"this-is-also" , "valid" , "" , "cool" },
148
147
},
149
148
{
150
- rawMessage : "π(π¦): emojis!" ,
151
- wanted : []string {"π" , "π¦" , "" , "emojis!" },
149
+ message : "π(π¦): emojis!" ,
150
+ wanted : []string {"π" , "π¦" , "" , "emojis!" },
152
151
},
153
152
// invalid messages
154
153
{
155
- rawMessage : "feat (new api): feature" ,
156
- wanted : nil ,
154
+ message : "feat (new api): feature" ,
155
+ wanted : nil ,
157
156
},
158
157
{
159
- rawMessage : "feat((x)): test" ,
160
- wanted : nil ,
158
+ message : "feat((x)): test" ,
159
+ wanted : nil ,
161
160
},
162
161
{
163
- rawMessage : "feat:test" ,
164
- wanted : nil ,
162
+ message : "feat:test" ,
163
+ wanted : nil ,
165
164
},
166
165
}
167
166
for _ , tc := range testCases {
168
- t .Run (fmt .Sprintf ("CommitPattern: %s" , tc .rawMessage ), func (t * testing.T ) {
169
- rawMessageLines := strings .Split (tc .rawMessage , "\n " )
170
- found := commitPattern .FindAllStringSubmatch (rawMessageLines [0 ], - 1 )
167
+ t .Run (fmt .Sprintf ("CommitPattern: %s" , tc .message ), func (t * testing.T ) {
168
+ found := commitPattern .FindAllStringSubmatch (tc .message , - 1 )
171
169
if len (tc .wanted ) == 0 {
172
170
require .Len (t , found , 0 )
173
171
return
0 commit comments