-
Notifications
You must be signed in to change notification settings - Fork 6
/
struct2interface_test.go
99 lines (84 loc) · 1.9 KB
/
struct2interface_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
94
95
96
97
98
99
package struct2interface
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
const (
testDirCompared = `// Code generated by struct2interface; DO NOT EDIT.
package case_single_file
// MethodInterface ...
//
// Method describes the code and documentation
// tied into a method
type MethodInterface interface {
// Lines return a []string consisting of
// the documentation and code appended
// in chronological order
Lines() []string
}
// Method1Interface ...
//
// Method1 describes the code and documentation
// tied into a method
type Method1Interface interface {
// Lines return a []string consisting of
// the documentation and code appended
// in chronological order
Lines() []string
}
`
testPackageCompared = `// Code generated by struct2interface; DO NOT EDIT.
package testdata
// PackageMethodInterface ...
type PackageMethodInterface interface {
// the //-style comment test
Method1() string
Method2() string
}
// PackageMethod2Interface ...
type PackageMethod2Interface interface {
/*
the /*-style comment test
*/
Method1() string
}
`
)
func TestDir(t *testing.T) {
err := MakeDir("./testdata/case_single_file")
if err != nil {
t.Fatal(err)
}
output, err := os.ReadFile("./testdata/case_single_file/interface_case_single_file.go")
if err != nil {
t.Fatal(err)
}
if string(output) != testDirCompared {
t.Fail()
}
}
func TestPackage(t *testing.T) {
err := MakeDir("./testdata/case_package")
if err != nil {
t.Fatal(err)
}
output, err := os.ReadFile("./testdata/case_package/interface_testdata.go")
if err != nil {
t.Fatal(err)
}
if string(output) != testPackageCompared {
t.Fail()
}
}
func TestNil(t *testing.T) {
t.Run("空路径", func(t *testing.T) {
err := MakeDir("./notfind")
assert.EqualError(t, err, "lstat ./notfind: no such file or directory")
})
}
func Benchmark_TestDir(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = MakeDir("./testdata")
}
}