github.com/chrislusf/greenpack@v3.7.1-0.20170911073826-ad5bd10b7c47+incompatible/cmd/addzid/old_bambam_tests/listlist_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  
     6  	cv "github.com/glycerine/goconvey/convey"
     7  )
     8  
     9  func Test010ListListStruct(t *testing.T) {
    10  
    11  	cv.Convey("Given a go [][]struct that maps to List(List(Struct)) in capnproto", t, func() {
    12  		cv.Convey("then out list of list of struct serialization code should work", func() {
    13  
    14  			ex0 := `
    15  type Nester1 struct {
    16    Strs []string
    17  }
    18  type RWTest struct {
    19      NestMatrix [][]Nester1
    20  }
    21  `
    22  			cv.So(ExtractString2String(ex0), ShouldContainModuloWhiteSpace, `
    23  
    24  func RWTestGoToCapn(seg *capn.Segment, src *RWTest) RWTestCapn {
    25  	dest := AutoNewRWTestCapn(seg)
    26  
    27  	// NestMatrix -> Nester1Capn (go slice to capn list)
    28  	if len(src.NestMatrix) > 0 {
    29  		plist := seg.NewPointerList(len(src.NestMatrix))
    30  		i := 0
    31  		for _, ele := range src.NestMatrix {
    32  			plist.Set(i, capn.Object(SliceNester1ToNester1CapnList(seg, ele)))
    33  			i++
    34  		}
    35  		dest.SetNestMatrix(plist)
    36  	}
    37  
    38  	return dest
    39  }
    40  `)
    41  
    42  		})
    43  	})
    44  }