forked from jmckaskill/go-capnproto
-
Notifications
You must be signed in to change notification settings - Fork 21
/
print_test.go
43 lines (36 loc) · 1.31 KB
/
print_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
package capn_test
import (
"testing"
"github.com/glycerine/go-capnproto"
air "github.com/glycerine/go-capnproto/aircraftlib"
cv "github.com/glycerine/goconvey/convey"
)
func TestPrint(t *testing.T) {
seg := capn.NewBuffer(nil)
z := air.NewRootZ(seg)
airc := air.AutoNewAircraft(seg)
b737 := air.AutoNewB737(seg)
base := air.AutoNewPlaneBase(seg)
base.SetName("helen")
base.SetMaxSpeed(0.5)
homes := air.NewAirportList(seg, 2)
homes.Set(0, air.AIRPORT_JFK)
homes.Set(1, air.AIRPORT_SFO)
base.SetHomes(homes)
b737.SetBase(base)
airc.SetB737(b737)
z.SetAircraft(airc)
lit, err := z.MarshalCapLit()
panicOn(err)
json, err := z.MarshalJSON()
panicOn(err)
cv.Convey("Given the aircraftlib schema (and an Aircraft value), we should generate a MarshalCapLit() function that returns a literal representation in bytes for the given Aircraft value. And the MarshalJSON() should return the expected format too.", t, func() {
cv.So(string(lit), cv.ShouldEqual, `(aircraft = (b737 = (base = (name = "helen", homes = [jfk, sfo], rating = 0, canFly = false, capacity = 0, maxSpeed = 0.5))))`)
cv.So(string(json), cv.ShouldEqual, `{"aircraft":{"b737":{"base":{"name":"helen","homes":["jfk", "sfo"],"rating":0,"canFly":false,"capacity":0,"maxSpeed":0.5}}}}`)
})
}
func panicOn(err error) {
if err != nil {
panic(err)
}
}