-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator_test.go
53 lines (48 loc) · 1.12 KB
/
generator_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
package main
import (
"fmt"
"github.com/stretchr/testify/assert"
"golang.org/x/tools/go/packages"
"strings"
"testing"
)
func TestGenerator_ParseDir(t *testing.T) {
g := &Generator{
files: make([]string, 0),
}
dir := "/Users/linqiankai/go/src/gorm-gen/examples"
g.parseDir(dir)
fmt.Println(g.files)
pkgName := dir[strings.LastIndex(dir, "/")+1:]
fmt.Println(pkgName)
assert.NotNil(t, g.files)
}
func TestParseFile(t *testing.T) {
g := &Generator{
files: make([]string, 0),
}
dir := "/Users/linqiankai/go/src/gorm-gen/examples/models/common"
g.parseDir(dir)
files, err := g.parseFile()
assert.Nil(t, err)
for _, file := range files {
t.Log(file.pkg)
t.Log(file.structs)
}
}
func TestGenerate(t *testing.T) {
g := &Generator{
output: "/Users/linqiankai/go/src/gorm-gen/examples/dao",
files: make([]string, 0),
}
g.generate("/Users/linqiankai/go/src/gorm-gen/examples/models")
}
func TestPackagePath(t *testing.T) {
load, err := packages.Load(
&packages.Config{
Dir: "/Users/linqiankai/go/src/gorm-gen/examples/models/common",
Mode: packages.NeedModule,
})
assert.Nil(t, err)
t.Log(load[0].ID)
}