MCPcopy Create free account
hub / github.com/conventionalcommit/commitlint / TestSyntaxAdapter

Function TestSyntaxAdapter

commit/parser_test.go:12–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func 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
43func TestSyntaxAdapterErrors(t *testing.T) {
44 p := commit.NewParser()

Callers

nothing calls this directly

Calls 13

ParseMethod · 0.95
NewParserFunction · 0.92
MessageMethod · 0.65
HeaderMethod · 0.65
TypeMethod · 0.65
ScopeMethod · 0.65
DescriptionMethod · 0.65
BodyMethod · 0.65
IsBreakingChangeMethod · 0.65
NotesMethod · 0.65
TokenMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected