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

     1  package main
     2  
     3  import (
     4  	"testing"
     5  
     6  	cv "github.com/glycerine/goconvey/convey"
     7  )
     8  
     9  func Test004SingleSlice(t *testing.T) {
    10  
    11  	cv.Convey("Given a parsable golang source file with type Vector struct { M []int }", t, func() {
    12  		cv.Convey("then we should generate translation utility methods for List(Int64) <-> []int in the capnp output", func() {
    13  
    14  			ex0 := `
    15  type Vector struct {
    16    M []int
    17  }`
    18  			cv.So(ExtractString2String(ex0), ShouldContainModuloWhiteSpace, `
    19  
    20  func Int64ListToSliceInt(p capn.Int64List) []int {
    21  	v := make([]int, p.Len())
    22  	for i := range v {
    23  		v[i] = int(p.At(i))
    24  	}
    25  	return v
    26  }
    27  `)
    28  
    29  			cv.So(ExtractString2String(ex0), ShouldContainModuloWhiteSpace, `
    30  func SliceIntToInt64List(seg *capn.Segment, m []int) capn.Int64List {
    31  	lst := seg.NewInt64List(len(m))
    32  	for i := range m {
    33  		lst.Set(i, int64(m[i]))
    34  	}
    35  	return lst
    36  }
    37  
    38  `)
    39  		})
    40  	})
    41  }