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

Function TestCommitHelpers

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

Source from the content-addressed store, hash-verified

90}
91
92func TestCommitHelpers(t *testing.T) {
93 parsed, err := commit.NewParser().Parse("feat!: drop v1\n\nBody text.\n\nBREAKING CHANGE: gone\nRefs #9")
94 if err != nil {
95 t.Fatal(err)
96 }
97 if !parsed.HasHeaderBang() || !parsed.HasBreakingFooter() || parsed.BodyBlankLines() != 1 || parsed.FooterBlankLines() != 1 {
98 t.Fatal("syntax-backed Commit methods reported incorrect facts on valid breaking commit")
99 }
100 if parsed.NoteCount() != 2 || parsed.NoteAt(0).Token() != "BREAKING CHANGE" || parsed.NoteAt(1).Token() != "Refs" {
101 t.Fatalf("unexpected notes: count=%d", parsed.NoteCount())
102 }
103 if got := commit.FirstLine("Initial commit\r\nignored"); got != "Initial commit" {
104 t.Fatalf("FirstLine = %q", got)
105 }
106 var lines []string
107 commit.ForEachLine("a\r\nb\nc", func(line string) bool {
108 lines = append(lines, line)
109 return len(lines) < 2
110 })
111 if len(lines) != 2 || lines[0] != "a" || lines[1] != "b" {
112 t.Fatalf("ForEachLine = %q", lines)
113 }
114 _, diags := commit.Inspect("feat: ok\n\nRefs #9\nEmpty: ")
115 if line, col, ok := commit.DiagnosticPosition("feat: ok\n\nRefs #9\nEmpty: ", diags[0]); !ok || line != 4 || col != 8 {
116 t.Fatalf("DiagnosticPosition = (%d, %d, %v)", line, col, ok)
117 }
118 if _, _, ok := commit.DiagnosticPosition("feat: ok", errors.New("custom error")); ok {
119 t.Fatal("expected false for non-syntax error")
120 }
121}
122
123var parsed commit.Commit
124var parseErr error

Callers

nothing calls this directly

Calls 13

NewParserFunction · 0.92
FirstLineFunction · 0.92
ForEachLineFunction · 0.92
InspectFunction · 0.92
DiagnosticPositionFunction · 0.92
ParseMethod · 0.65
HasHeaderBangMethod · 0.65
HasBreakingFooterMethod · 0.65
BodyBlankLinesMethod · 0.65
FooterBlankLinesMethod · 0.65
NoteCountMethod · 0.65
TokenMethod · 0.65

Tested by

no test coverage detected