-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathannot_test.go
65 lines (49 loc) · 2.25 KB
/
annot_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
package main
import (
"testing"
cv "github.com/glycerine/goconvey/convey"
)
func TestCommentAnnotationWorks(t *testing.T) {
cv.Convey(`Given a golang struct named Data with an attached comment: // capname:"MyData"`, t, func() {
cv.Convey("then we should use the capname MyData for the struct.", func() {
ex0 := `
// capname:"MyData"
type Data struct {
}`
cv.So(ExtractString2String(ex0), ShouldStartWithModuloWhiteSpace, `struct MyData { } `)
ex1 := `
// capname: "MyData"
type Data struct {
}`
cv.So(ExtractString2String(ex1), ShouldStartWithModuloWhiteSpace, `struct MyData { } `)
})
})
}
func TestTagAnnotationWorks(t *testing.T) {
cv.Convey("Given a golang struct with an invalid capnp field name 'Union', but with a field tag: `capname:\"MyNewFieldName\"`", t, func() {
cv.Convey("then we should use the capname MyNewFieldName for the field, and not stop the run.", func() {
ex0 := "type S struct { Union string `capname:\"MyNewFieldName\"` \n}"
cv.So(ExtractString2String(ex0), ShouldStartWithModuloWhiteSpace, `struct SCapn { MyNewFieldName @0: Text; } `)
ex1 := "type S struct { Union string `capname: \t \t \"MyNewFieldName\"` \n}"
cv.So(ExtractString2String(ex1), ShouldStartWithModuloWhiteSpace, `struct SCapn { MyNewFieldName @0: Text; } `)
})
})
}
func TestTagCapidWorks(t *testing.T) {
cv.Convey("Given the desire to preserve the field numbering in the generated Capnproto schema,", t, func() {
cv.Convey("when we add the tag: capid:\"1\", then the field should be numbered @1.", func() {
cv.Convey("and if there are fewer than 2 (numbered 0, 1) fields then we error out.", func() {
ex0 := "type S struct { A string `capid:\"1\"`; B string \n}"
cv.So(ExtractString2String(ex0), ShouldStartWithModuloWhiteSpace, `struct SCapn { b @0: Text; a @1: Text; } `)
})
})
})
}
func TestLowercaseGoFieldsIgnoredByDefault(t *testing.T) {
cv.Convey("Given the traditional golang std lib behvaior of not serializing lowercase fields,", t, func() {
cv.Convey("then by default we should ignore lower case fields in writing the capnproto schema.", func() {
ex0 := "type S struct { a string; B string \n}"
cv.So(ExtractString2String(ex0), ShouldStartWithModuloWhiteSpace, `struct SCapn { b @0: Text; } `)
})
})
}