(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestSyntaxAdapter(t *testing.T) { |
| 13 | p := commit.NewParser() |
| 14 | for _, newline := range []string{"\n", "\r\n"} { |
| 15 | input := strings.ReplaceAll("feat(store)!: replace index \n\nRetain records.\n\nTrace: #91\n continuation\nRefs #92\nRefs #93\nBREAKING-CHANGE: remove legacy keys\n", "\n", newline) |
| 16 | c, err := p.Parse(input) |
| 17 | if err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | if c.Message() != input || c.Header() != "feat(store)!: replace index " || c.Type() != "feat" || c.Scope() != "store" || c.Description() != "replace index " || c.Body() != "Retain records." || !c.IsBreakingChange() { |
| 21 | t.Fatalf("unexpected fields: %#v", c) |
| 22 | } |
| 23 | want := [][2]string{{"Trace", "#91" + newline + " continuation"}, {"Refs", "92"}, {"Refs", "93"}, {"BREAKING-CHANGE", "remove legacy keys"}} |
| 24 | notes := c.Notes() |
| 25 | if len(notes) != len(want) { |
| 26 | t.Fatalf("notes = %d", len(notes)) |
| 27 | } |
| 28 | for i, entry := range want { |
| 29 | if notes[i].Token() != entry[0] || notes[i].Value() != entry[1] { |
| 30 | t.Fatalf("note %d = %q: %q", i, notes[i].Token(), notes[i].Value()) |
| 31 | } |
| 32 | } |
| 33 | notes[0] = nil |
| 34 | if c.Notes()[0].Token() != "Trace" { |
| 35 | t.Fatal("returned slice changed the result") |
| 36 | } |
| 37 | if !strings.HasPrefix(c.Footer(), "Trace: #91"+newline) { |
| 38 | t.Fatalf("footer = %q", c.Footer()) |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func TestSyntaxAdapterErrors(t *testing.T) { |
| 44 | p := commit.NewParser() |
nothing calls this directly
no test coverage detected