(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestSyntaxDiagnosticsAndInput(t *testing.T) { |
| 16 | conf := config.NewDefault() |
| 17 | conf.Rules = []string{"header-trim"} |
| 18 | conf.Severity.Default = lint.SeverityWarn |
| 19 | linter, err := config.NewLinter(conf) |
| 20 | if err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | for _, tt := range []struct { |
| 24 | name, input string |
| 25 | wantRules []string |
| 26 | }{ |
| 27 | {"terminal newline", "feat: expose records\n", nil}, |
| 28 | {"crlf body", "feat: expose records\r\n\r\nBody text.\r\n", nil}, |
| 29 | {"trailing header spaces", "feat: expose records \n", []string{"header-trim"}}, |
| 30 | {"leading space", " feat: expose records", []string{"parser", "header-trim"}}, |
| 31 | {"leading blank", "\nfeat: expose records", []string{"parser"}}, |
| 32 | {"missing section separator", "feat: expose records\nBody text.", []string{"parser"}}, |
| 33 | {"empty footer value", "feat: expose records\n\nRefs #9\nEmpty: ", []string{"parser"}}, |
| 34 | {"blank description", "feat: \t", []string{"parser", "header-trim"}}, |
| 35 | } { |
| 36 | t.Run(tt.name, func(t *testing.T) { |
| 37 | result, err := linter.ParseAndLint(tt.input) |
| 38 | if err != nil { |
| 39 | t.Fatal(err) |
| 40 | } |
| 41 | if result.Input() != tt.input { |
| 42 | t.Fatal("result changed input bytes") |
| 43 | } |
| 44 | if len(result.Issues()) != len(tt.wantRules) { |
| 45 | t.Fatalf("issues=%v, want %v", result.Issues(), tt.wantRules) |
| 46 | } |
| 47 | for i, wantRule := range tt.wantRules { |
| 48 | issue := result.Issues()[i] |
| 49 | severity := lint.SeverityWarn |
| 50 | if wantRule == "parser" { |
| 51 | severity = lint.SeverityError |
| 52 | } |
| 53 | if issue.RuleName() != wantRule || issue.Severity() != severity { |
| 54 | t.Fatalf("issue=%s %s", issue.RuleName(), issue.Severity()) |
| 55 | } |
| 56 | } |
| 57 | text, err := (&formatter.JSONFormatter{}).Format(result) |
| 58 | if err != nil { |
| 59 | t.Fatal(err) |
| 60 | } |
| 61 | var output struct { |
| 62 | Input string `json:"input"` |
| 63 | } |
| 64 | if err := json.Unmarshal([]byte(text), &output); err != nil { |
| 65 | t.Fatal(err) |
| 66 | } |
| 67 | if output.Input != tt.input { |
| 68 | t.Fatal("formatter changed input bytes") |
| 69 | } |
| 70 | }) |
| 71 | } |
| 72 | } |
nothing calls this directly
no test coverage detected