Skip to content

Commit 8502345

Browse files
test: add example for parser
1 parent 6417b38 commit 8502345

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

example_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package parser_test
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/conventionalcommit/parser"
7+
)
8+
9+
func ExampleParse() {
10+
var msg = `feat(scope): description
11+
12+
this is first line in body
13+
14+
this is second line in body
15+
16+
Ref #123
17+
Date: 01-01-2021
18+
By: John Doe`
19+
20+
commit, err := parser.Parse(msg)
21+
if err != nil {
22+
fmt.Printf("Error: %s", err.Error())
23+
}
24+
fmt.Printf("%#v", commit)
25+
26+
// Output: &parser.Commit{Header:parser.Header{Type:"feat", Scope:"scope", Description:"description", FullHeader:"feat(scope): description"}, Body:"this is first line in body\n\nthis is second line in body", Footer:parser.Footer{Notes:[]parser.FooterNote{parser.FooterNote{Token:"Ref", Value:"123"}, parser.FooterNote{Token:"Date", Value:"01-01-2021"}, parser.FooterNote{Token:"By", Value:"John Doe"}}, FullFooter:"Ref #123\nDate: 01-01-2021\nBy: John Doe"}, BreakingChange:false, FullCommit:"feat(scope): description\n\nthis is first line in body\n\nthis is second line in body\n\nRef #123\nDate: 01-01-2021\nBy: John Doe"}
27+
}

0 commit comments

Comments
 (0)