-
Notifications
You must be signed in to change notification settings - Fork 0
/
types_test.go
124 lines (117 loc) · 2.27 KB
/
types_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package toast
import (
"fmt"
"testing"
"github.com/fatih/structtag"
)
var file = File{
pkgName: "mock",
Imports: map[string]Import{
"fmt": {Path: "fmt"},
"loader": {Path: "github.com/bcm820/envoy-cue/pkg/loader"},
"m": {Name: "m", Path: "github.com/bcm820/envoy-cue/pkg/toast/mock"},
},
Code: []Type{
&PlainType{
Name: "myint",
Type: "int",
},
&PlainType{
Docs: "// a string\n",
Name: "mystr",
Type: "string",
},
&PlainType{
Docs: "// multi-line\n// comment\n",
Name: "myinterface",
Type: "interface{}",
},
&PlainType{
Docs: "/* another multi-line\n comment */\n",
Name: "mystr",
Type: "string",
},
&ArrayType{
Docs: "// a slice\n",
Name: "myslice",
Type: "int",
},
&ArrayType{
Docs: "// a fixed-length array\n",
Name: "myarr",
Type: "int",
Length: 5,
},
&MapType{
Docs: "// a string map\n",
Name: "mymap",
KeyType: "string",
ValueType: "int64",
},
&StructType{
Docs: "// a struct\n",
Name: "mystruct",
Fields: []*Field{
{
Type: &PlainType{
Docs: "// field1\n",
Name: "Field1",
Type: "int32",
},
Tags: tagsMustParse(`json:"field1"`),
},
{
Type: &ArrayType{
Docs: "// field2\n",
Name: "Field2",
Type: "bool",
},
Tags: tagsMustParse(`json:"field2"`),
},
{
Type: &MapType{
Docs: "// field3\n",
Name: "Field3",
KeyType: "int",
ValueType: "struct{}",
},
Tags: tagsMustParse(`json:"field3"`),
},
{
Type: &StructType{
Docs: "// field4\n",
Name: "Field4",
Fields: []*Field{
{
Type: &PlainType{
Docs: "nestedfield",
Name: "NestedField",
Type: "int64",
},
Tags: tagsMustParse(`json:"nestedField"`),
},
},
},
Tags: tagsMustParse(`json:"field4"`),
},
},
},
&EnumType{
Name: "MyEnum",
Values: []string{"MyEnum_A", "MyEnum_B", "MyEnum_C"},
},
},
}
func tagsMustParse(tag string) *structtag.Tags {
tags, _ := structtag.Parse(tag)
return tags
}
func TestReflect(t *testing.T) {
printJSON(file.Reflect())
}
func TestGo(t *testing.T) {
fmt.Println(file.Go())
}
func TestCUE(t *testing.T) {
fmt.Println(file.CUE())
}