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

Function TestSyntaxLineLengthBoundaries

test/syntax_length_test.go:12–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestSyntaxLineLengthBoundaries(t *testing.T) {
13 for _, tt := range []struct {
14 name, rule, prefix string
15 limit int
16 }{
17 {"body", "body-max-line-length", "", 72},
18 {"footer", "footer-max-line-length", "Trace: ", 100},
19 } {
20 conf := config.NewDefault()
21 conf.Rules = []string{tt.rule}
22 conf.Settings[tt.rule] = lint.RuleSetting{Argument: tt.limit}
23 linter, err := config.NewLinter(conf)
24 if err != nil {
25 t.Fatal(err)
26 }
27 for _, newline := range []string{"\n", "\r\n"} {
28 for _, extra := range []int{0, 1} {
29 t.Run(fmt.Sprintf("%s/%q/%d", tt.name, newline, extra), func(t *testing.T) {
30 line := tt.prefix + strings.Repeat("x", tt.limit+extra-len(tt.prefix))
31 next := "continuation"
32 if tt.prefix != "" {
33 next = "Refs #9"
34 }
35 input := "feat: expose records" + newline + newline + line + newline + next
36 result, err := linter.ParseAndLint(input)
37 if err != nil {
38 t.Fatal(err)
39 }
40 if len(result.Issues()) != extra {
41 t.Fatalf("issues=%v, want %d", result.Issues(), extra)
42 }
43 if extra == 1 {
44 issue := result.Issues()[0]
45 want := fmt.Sprintf("in line 1, length is %d", tt.limit+1)
46 if issue.RuleName() != tt.rule || len(issue.Infos()) != 1 || issue.Infos()[0] != want {
47 t.Fatalf("unexpected length issue: %s %v", issue.RuleName(), issue.Infos())
48 }
49 }
50 })
51 }
52 }
53 }
54}

Callers

nothing calls this directly

Calls 6

ParseAndLintMethod · 0.95
NewDefaultFunction · 0.92
NewLinterFunction · 0.92
IssuesMethod · 0.80
RuleNameMethod · 0.80
InfosMethod · 0.80

Tested by

no test coverage detected