@@ -9,18 +9,6 @@ import (
99 "github.com/stretchr/testify/require"
1010)
1111
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-
2412func createRawCommit (sha , message string ) * semrel.RawCommit {
2513 return & semrel.RawCommit {
2614 SHA : sha ,
@@ -77,13 +65,13 @@ func TestDefaultAnalyzer(t *testing.T) {
7765 createRawCommit ("e" , "feat!: modified login endpoint" ),
7866 "feat" ,
7967 "" ,
80- & semrel.Change {Major : true , Minor : false , Patch : false },
68+ & semrel.Change {Major : true , Minor : true , Patch : false },
8169 },
8270 {
8371 createRawCommit ("f" , "fix!: fixed a typo" ),
8472 "fix" ,
8573 "" ,
86- & semrel.Change {Major : true , Minor : false , Patch : false },
74+ & semrel.Change {Major : true , Minor : false , Patch : true },
8775 },
8876 {
8977 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) {
10391 "" ,
10492 & semrel.Change {Major : false , Minor : false , Patch : false },
10593 },
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+ },
106100 }
107101
108102 defaultAnalyzer := & DefaultCommitAnalyzer {}
109103 for _ , tc := range testCases {
110104 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" )
112111 })
113112 }
114113}
115114
116115func TestCommitPattern (t * testing.T ) {
117116 testCases := []struct {
118- rawMessage string
119- wanted []string
117+ message string
118+ wanted []string
120119 }{
121120 {
122- rawMessage : "feat: new feature" ,
123- wanted : []string {"feat" , "" , "" , "new feature" },
121+ message : "feat: new feature" ,
122+ wanted : []string {"feat" , "" , "" , "new feature" },
124123 },
125124 {
126- rawMessage : "feat!: new feature" ,
127- wanted : []string {"feat" , "" , "!" , "new feature" },
125+ message : "feat!: new feature" ,
126+ wanted : []string {"feat" , "" , "!" , "new feature" },
128127 },
129128 {
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" },
132131 },
133132 {
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:" },
136135 },
137136 {
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" },
140139 },
141140 {
142- rawMessage : "feat(π
): cool" ,
143- wanted : []string {"feat" , "π
" , "" , "cool" },
141+ message : "feat(π
): cool" ,
142+ wanted : []string {"feat" , "π
" , "" , "cool" },
144143 },
145144 {
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" },
148147 },
149148 {
150- rawMessage : "π(π¦): emojis!" ,
151- wanted : []string {"π" , "π¦" , "" , "emojis!" },
149+ message : "π(π¦): emojis!" ,
150+ wanted : []string {"π" , "π¦" , "" , "emojis!" },
152151 },
153152 // invalid messages
154153 {
155- rawMessage : "feat (new api): feature" ,
156- wanted : nil ,
154+ message : "feat (new api): feature" ,
155+ wanted : nil ,
157156 },
158157 {
159- rawMessage : "feat((x)): test" ,
160- wanted : nil ,
158+ message : "feat((x)): test" ,
159+ wanted : nil ,
161160 },
162161 {
163- rawMessage : "feat:test" ,
164- wanted : nil ,
162+ message : "feat:test" ,
163+ wanted : nil ,
165164 },
166165 }
167166 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 )
171169 if len (tc .wanted ) == 0 {
172170 require .Len (t , found , 0 )
173171 return
0 commit comments