-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstruct1_test.go
93 lines (73 loc) · 1.87 KB
/
struct1_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
package main
import (
"testing"
cv "github.com/glycerine/goconvey/convey"
)
type EmptyStruct struct {
}
type OneStruct struct {
One int
}
type HalfPrivStruct struct {
One int
two int
}
type NestingStruct struct {
One int
Nester OneStruct
}
type EmbeddingStruct struct {
OneStruct
}
// An example struct with a comment
// second line of comment.
/*
C comments attached too
*/
type ExampleStruct1 struct {
Str string
N int
}
func TestSimpleStructExtraction(t *testing.T) {
cv.Convey("Given a parsable golang source file", t, func() {
cv.Convey("then we can extract an empty struct", func() {
ex0 := `
type Empty1 struct {
}`
cv.So(ExtractString2String(ex0), ShouldStartWithModuloWhiteSpace, `struct Empty1Capn { } `)
})
cv.Convey("then we can extract simple structs, without recursion or embedding", func() {
ex1 := `
type ExampleStruct1 struct {
Str string
N int
}`
cv.So(ExtractString2String(ex1), ShouldStartWithModuloWhiteSpace, `struct ExampleStruct1Capn { str @0: Text; n @1: Int64; } `)
})
cv.Convey("then we can extract structs that have other named structs inside", func() {
exNest := `
type OneStruct struct {
One int
}
type NestingStruct struct {
One int
Nester OneStruct
}`
cv.So(ExtractString2String(exNest), ShouldStartWithModuloWhiteSpace, `struct NestingStructCapn { one @0: Int64; nester @1: OneStructCapn; } struct OneStructCapn { one @0: Int64; } `)
})
})
}
func TestEmbedded(t *testing.T) {
cv.Convey("Given a parsable golang source file", t, func() {
cv.Convey("then we can extract structs with anonymous (embedded) structs inside", func() {
exEmbed := `
type OneStruct struct {
One int
}
type EmbedsOne struct {
OneStruct
}`
cv.So(ExtractString2String(exEmbed), ShouldStartWithModuloWhiteSpace, `struct EmbedsOneCapn { oneStruct @0: OneStructCapn; } struct OneStructCapn { one @0: Int64; } `)
})
})
}