-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerator_test.go
98 lines (86 loc) · 1.7 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
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
package main
import (
"testing"
"ariga.io/atlas/sql/schema"
"github.com/stretchr/testify/assert"
)
func Test_generate(t *testing.T) {
t.Parallel()
patterns := []struct {
name string
sc schema.Schema
in input
out string
}{
// TODO: add more pattern
{
name: "success",
sc: schema.Schema{
Tables: []*schema.Table{
schema.NewTable("users").AddColumns(
schema.NewStringColumn("id", "string"),
schema.NewIntColumn("created_at", "int"),
schema.NewIntColumn("updated_at", "int"),
),
},
},
in: input{
hclPath: "input.hcl",
outPath: "output.go",
pkg: "main",
tag: "db",
},
out: `// Code generated by github.com/ucpr/atlas-hcl-gen-go. DO NOT EDIT.
// atlas-hcl-gen-go:
// source: input.hcl
package main
type Users struct {
Id string ` + "`" + `db:"id"` + "`" + `
CreatedAt int ` + "`" + `db:"created_at"` + "`" + `
UpdatedAt int ` + "`" + `db:"updated_at"` + "`" + `
}
`,
},
}
for _, tt := range patterns {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := generate(tt.sc, tt.in)
assert.NoError(t, err)
assert.Equal(t, tt.out, string(got))
})
}
}
func Test_toCamelCase(t *testing.T) {
t.Parallel()
patterns := []struct {
name string
in string
out string
}{
{
name: "snake case",
in: "created_at",
out: "CreatedAt",
},
{
name: "camel case",
in: "CreatedAt",
out: "CreatedAt",
},
{
name: "snake case and camel case",
in: "created_At",
out: "CreatedAt",
},
}
for _, tt := range patterns {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := toCamelCase(tt.in)
assert.Equal(t, tt.out, got)
})
}
}