|
| 1 | +package lint |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/errata-ai/vale/v3/internal/core" |
| 7 | +) |
| 8 | + |
| 9 | +// Both readers of a source file consult skipsComment, so a scope excluded from |
| 10 | +// one is excluded from the other. Mapping a markup format onto a file switches |
| 11 | +// which reader runs, and used to switch this off with it. See #858. |
| 12 | +func TestSkipsComment(t *testing.T) { |
| 13 | + tests := []struct { |
| 14 | + name string |
| 15 | + ignored []string |
| 16 | + scope string |
| 17 | + want bool |
| 18 | + }{ |
| 19 | + {"nothing ignored", nil, "text.comment.block", false}, |
| 20 | + {"the scope itself", []string{"text.comment.block"}, "text.comment.block", true}, |
| 21 | + {"every comment", []string{"comment"}, "text.comment.block", true}, |
| 22 | + {"a different scope", []string{"text.comment.line"}, "text.comment.block", false}, |
| 23 | + {"alongside the defaults", []string{"code", "tt", "text.comment.block"}, |
| 24 | + "text.comment.block", true}, |
| 25 | + } |
| 26 | + |
| 27 | + cfg, err := core.NewConfig(&core.CLIFlags{}) |
| 28 | + if err != nil { |
| 29 | + t.Fatal(err) |
| 30 | + } |
| 31 | + linter, err := NewLinter(cfg) |
| 32 | + if err != nil { |
| 33 | + t.Fatal(err) |
| 34 | + } |
| 35 | + |
| 36 | + for _, tt := range tests { |
| 37 | + t.Run(tt.name, func(t *testing.T) { |
| 38 | + linter.Manager.Config.IgnoredScopes = tt.ignored |
| 39 | + if got := linter.skipsComment(tt.scope); got != tt.want { |
| 40 | + t.Errorf("skipsComment(%q) = %v with %v, want %v", |
| 41 | + tt.scope, got, tt.ignored, tt.want) |
| 42 | + } |
| 43 | + }) |
| 44 | + } |
| 45 | +} |
0 commit comments