-
Notifications
You must be signed in to change notification settings - Fork 1
/
snippet_decl_test.go
66 lines (55 loc) · 1012 Bytes
/
snippet_decl_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
package codegen
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestDeclConst(t *testing.T) {
tt := require.New(t)
tt.Equal(`const a = "1"`, Stringify(
DeclConst(
Assign(Id("a")).By(Val("1")),
),
))
tt.Equal(`const (
a int = iota
b
c
)`, Stringify(
DeclConst(
Assign(Var(Int, "a")).By(Iota),
Assign(Id("b")),
Assign(Id("c")),
),
))
}
func TestDeclVar(t *testing.T) {
tt := require.New(t)
tt.Equal(`var a = Fn("1")`, Stringify(
DeclVar(
Assign(Id("a")).By(Call("Fn", Val("1"))),
),
))
tt.Equal(`var a, b string = Fn("1")`, Stringify(
DeclVar(
Assign(Var(String, "a", "b")).By(Call("Fn", Val("1"))),
),
))
}
func TestDeclType(t *testing.T) {
tt := require.New(t)
tt.Equal("type N string", Stringify(
DeclType(
Var(String, "N"),
),
))
tt.Equal(`type (
// test
M = time.Time
N = time.Time
)`, Stringify(
DeclType(
Var(Type("time.Time"), "M").AsAlias().WithComments("test"),
Var(Type("time.Time"), "N").AsAlias(),
),
))
}