This repository has been archived by the owner on Jul 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constant_test.go
94 lines (76 loc) · 1.96 KB
/
constant_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
package humanize
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
var cr = `
package test
const (
i = iota
j
)
const s float64 = 10
const i1 = 10
const i2 = 10.6
const i3 = "test"
const i4 = 'C'
const i6 = 10i
`
func TestConstant(t *testing.T) {
Convey("constant test", t, func() {
f, err := ParseFile(cr, &Package{})
So(err, ShouldBeNil)
var p = &Package{}
p.Files = append(p.Files, f)
Convey("Normal define", func() {
i, err := p.FindConstant("i")
So(err, ShouldBeNil)
So(i.Name, ShouldEqual, "i")
So(i.Type.(*IdentType).Ident, ShouldEqual, "iota")
i, err = p.FindConstant("j")
So(err, ShouldBeNil)
So(i.Name, ShouldEqual, "j")
So(i.Type.(*IdentType).Ident, ShouldEqual, "iota")
})
Convey("by value s", func() {
i, err := p.FindConstant("s")
So(err, ShouldBeNil)
So(i.Name, ShouldEqual, "s")
So(i.Type.(*IdentType).Ident, ShouldEqual, "float64")
})
Convey("by value i1", func() {
i, err := p.FindConstant("i1")
So(err, ShouldBeNil)
So(i.Name, ShouldEqual, "i1")
So(i.Type.(*IdentType).Ident, ShouldEqual, "int")
})
Convey("by value i2", func() {
i, err := p.FindConstant("i2")
So(err, ShouldBeNil)
So(i.Name, ShouldEqual, "i2")
So(i.Name, ShouldEqual, "i2")
So(i.Type.(*IdentType).Ident, ShouldEqual, "float64")
})
Convey("by value i3", func() {
i, err := p.FindConstant("i3")
So(err, ShouldBeNil)
So(i.Name, ShouldEqual, "i3")
So(i.Name, ShouldEqual, "i3")
So(i.Type.(*IdentType).Ident, ShouldEqual, "string")
})
Convey("by value i4", func() {
i, err := p.FindConstant("i4")
So(err, ShouldBeNil)
So(i.Name, ShouldEqual, "i4")
So(i.Name, ShouldEqual, "i4")
So(i.Type.(*IdentType).Ident, ShouldEqual, "char")
})
Convey("by value i6", func() {
i, err := p.FindConstant("i6")
So(err, ShouldBeNil)
So(i.Name, ShouldEqual, "i6")
So(i.Name, ShouldEqual, "i6")
So(i.Type.(*IdentType).Ident, ShouldEqual, "complex64")
})
})
}