This repository was archived by the owner on Jan 20, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbreak_comments_test.go
More file actions
69 lines (58 loc) · 1.31 KB
/
break_comments_test.go
File metadata and controls
69 lines (58 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package nit_test
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/MarioCarrion/nit"
)
func TestBreakComments(t *testing.T) {
type expected struct {
result []int
generatedCode bool
noLintNit bool
}
tests := [...]struct {
name string
filename string
expected expected
}{
{
"OK",
"break_comments1.go",
expected{result: []int{8, 13, 19}},
},
{
"OK: code generated",
"break_comments2.go",
expected{generatedCode: true},
},
{
"OK: nolint nit",
"break_comments3.go",
expected{noLintNit: true},
},
}
for _, tt := range tests {
t.Run(tt.name, func(ts *testing.T) {
f, fset := newParserFile(ts, tt.filename)
var actual []int
bc := nit.NewBreakComments(fset, f.Comments)
for _, v := range tt.expected.result {
bc.MoveTo(v)
v = bc.Next()
if v == -1 {
break
}
actual = append(actual, v)
}
if !cmp.Equal(tt.expected.result, actual) {
ts.Errorf("expected values do not match: %s", cmp.Diff(tt.expected, actual))
}
if tt.expected.generatedCode != bc.HasGeneratedCode() {
ts.Errorf("expected %t, got %t", tt.expected.generatedCode, bc.HasGeneratedCode())
}
if tt.expected.noLintNit != bc.HasNoLintNit() {
ts.Errorf("expected %t, got %t", tt.expected.noLintNit, bc.HasNoLintNit())
}
})
}
}