-
Notifications
You must be signed in to change notification settings - Fork 12
/
list_test.go
87 lines (66 loc) · 1.82 KB
/
list_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
package main
import (
"testing"
cv "github.com/glycerine/goconvey/convey"
)
func Test005SliceOfStringToListOfText(t *testing.T) {
cv.Convey("Given a struct that contains a slice of string", t, func() {
cv.Convey("then the capnp schema should contain a list of string and list translating code should be generated", func() {
ex0 := `
type s1 struct {
Names []string
}`
expected0 := `
struct S1Capn { names @0: List(Text); }
func (s *s1) Save(w io.Writer) error {
seg := capn.NewBuffer(nil)
s1GoToCapn(seg, s)
_, err := seg.WriteTo(w)
return err
}
func (s *s1) Load(r io.Reader) error {
capMsg, err := capn.ReadFromStream(r, nil)
if err != nil {
//panic(fmt.Errorf("capn.ReadFromStream error: %s", err))
return err
}
z := ReadRootS1Capn(capMsg)
S1CapnToGo(z, s)
return nil
}
func S1CapnToGo(src S1Capn, dest *s1) *s1 {
if dest == nil {
dest = &s1{}
}
dest.Names = src.Names().ToArray()
return dest
}
func s1GoToCapn(seg *capn.Segment, src *s1) S1Capn {
dest := AutoNewS1Capn(seg)
mylist1 := seg.NewTextList(len(src.Names))
for i := range src.Names {
mylist1.Set(i, string(src.Names[i]))
}
dest.SetNames(mylist1)
return dest
}
func SliceStringToTextList(seg *capn.Segment, m []string) capn.TextList {
lst := seg.NewTextList(len(m))
for i := range m {
lst.Set(i, string(m[i]))
}
return lst
}
func TextListToSliceString(p capn.TextList) []string {
v := make([]string, p.Len())
for i := range v {
v[i] = string(p.At(i))
}
return v
}
`
cv.So(ExtractString2String(ex0), ShouldMatchModuloWhiteSpace, expected0)
//cv.So(expected0, ShouldStartWithModuloWhiteSpace, ExtractString2String(ex0))
})
})
}