| 71 | } |
| 72 | |
| 73 | func TestSyntaxInspectionAdapter(t *testing.T) { |
| 74 | p := commit.NewParser() |
| 75 | input := "feat:expose records\nBody text." |
| 76 | c, diagnostics := commit.Inspect(input) |
| 77 | if c == nil || len(diagnostics) != 2 || c.Type() != "feat" || c.Body() != "Body text." { |
| 78 | t.Fatalf("result=%v diagnostics=%v", c, diagnostics) |
| 79 | } |
| 80 | var pe *syntax.ParseError |
| 81 | if !errors.As(diagnostics[0], &pe) || pe.Code != syntax.InvalidSeparator { |
| 82 | t.Fatal("typed diagnostic lost") |
| 83 | } |
| 84 | if strict, err := p.Parse(input); strict != nil || err == nil { |
| 85 | t.Fatal("strict parsing recovered invalid input") |
| 86 | } |
| 87 | if c, diagnostics := commit.Inspect("invalid header"); c != nil || len(diagnostics) != 1 { |
| 88 | t.Fatal("ambiguous header recovered") |
| 89 | } |
| 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") |