-
Notifications
You must be signed in to change notification settings - Fork 0
/
aster_test.go
93 lines (83 loc) · 2.21 KB
/
aster_test.go
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Package aster_test contains all the tests for the `aster` module.
package aster_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/yardbirdsax/aster"
)
func TestGetPackageComment(t *testing.T) {
tests := []struct {
name string
directory string
packages []string
expectedPackageComment string
}{
{
name: "one package",
directory: ".",
packages: []string{"aster"},
expectedPackageComment: "Package aster provides a high level interface for parsing Go code using the stdlib's\n" +
"[`go/ast`](https://pkg.go.dev/go/ast) module.\n",
},
{
name: "multi package",
directory: ".",
packages: []string{"aster", "aster_test"},
expectedPackageComment: "aster:\nPackage aster provides a high level interface for parsing Go code using the stdlib's\n" +
"[`go/ast`](https://pkg.go.dev/go/ast) module.\n" +
"aster_test:\nPackage aster_test contains all the tests for the `aster` module.\n",
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
actualPackageComment := aster.FromDirectory(tc.directory).Packages(tc.packages).PackageComment()
assert.Equal(t, tc.expectedPackageComment, actualPackageComment)
})
}
}
func TestMatchComment(t *testing.T) {
tests := []struct {
name string
directory string
comment string
expectedResults []aster.Result
}{
{
name: "with comment",
directory: "sample",
comment: "aster:",
expectedResults: []aster.Result{
{
Name: "Sample",
Type: "struct",
Comments: "aster: hello\n",
Fields: []aster.Field{
{
Name: "Text",
Type: "string",
Comments: "Text is some sample text\n",
},
},
},
{
Name: "Sampler",
Type: "func",
Comments: "aster: hello again\n",
},
},
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
a := aster.FromDirectory(tc.directory)
actualResults, err := a.MatchComment("aster:")
assert.Equal(t, tc.expectedResults, actualResults)
assert.NoError(t, a.Error)
assert.NoError(t, err)
})
}
}