-
Notifications
You must be signed in to change notification settings - Fork 12
/
go2cpType_test.go
45 lines (34 loc) · 1.08 KB
/
go2cpType_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
package main
import (
"fmt"
"testing"
cv "github.com/glycerine/goconvey/convey"
)
func Test001GoToCapTypeConversion(t *testing.T) {
cv.Convey("Given a go structs: type s1 struct { Ptrs []*int }", t, func() {
cv.Convey(`then the goTypeSeq should be {"[]", "*", "int"} and the capTypeSeq should be {"List", "*", "Int64"} `, func() {
src := `
type s1 struct {
Ptrs []*int
}
`
x := NewExtractor()
defer x.Cleanup()
_, err := ExtractStructs("", "package main; "+src, x)
if err != nil {
panic(err)
}
x.GenerateTranslators()
capTypeSeq := []string{}
goTypeSeq := []string{"[]", "*", "int"}
var capTypeDisplay string
capTypeSeq, capTypeDisplay = x.GoTypeToCapnpType(nil, goTypeSeq)
fmt.Printf("capTypeSeq = '%v', goTypeSeq = '%v', capTypeDispaly = '%v'\n", capTypeSeq, goTypeSeq, capTypeDisplay)
cv.So(len(capTypeSeq), cv.ShouldEqual, 3)
cv.So(capTypeSeq[0], cv.ShouldEqual, "List")
cv.So(capTypeSeq[1], cv.ShouldEqual, "*")
cv.So(capTypeSeq[2], cv.ShouldEqual, "Int64")
cv.So(capTypeDisplay, cv.ShouldEqual, "List(Int64)")
})
})
}