(t *testing.T)
| 90 | } |
| 91 | |
| 92 | func 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 | |
| 123 | var parsed commit.Commit |
| 124 | var parseErr error |
nothing calls this directly
no test coverage detected