github.com/glycerine/zebrapack@v4.1.1-0.20181107023619-e955d028f9bf+incompatible/cmd/addzid/old_bambam_tests/types_test.go (about)

     1  package main
     2  
     3  import (
     4  	"testing"
     5  
     6  	cv "github.com/glycerine/goconvey/convey"
     7  )
     8  
     9  func TestBasicTypesInStruct(t *testing.T) {
    10  
    11  	cv.Convey("Given a parsable golang source file with a simple struct", t, func() {
    12  		cv.Convey("then we can extract the struct and convert the basic types to capnp", func() {
    13  
    14  			in1 := `
    15  type In1 struct {
    16  	Str string
    17  	N   int
    18      D   float64
    19  }`
    20  			expect1 := `struct In1Capn { str @0: Text; n @1: Int64; d @2: Float64; } `
    21  			// List(Float64) next
    22  
    23  			cv.So(ExtractString2String(in1), ShouldStartWithModuloWhiteSpace, expect1)
    24  		})
    25  	})
    26  }
    27  
    28  func TestCaseConversion(t *testing.T) {
    29  
    30  	cv.Convey("Given a parsable golang source file with a simple struct", t, func() {
    31  		cv.Convey("then the capnp generated struct has uppercase struct name and lowercase field name, as per capnp requirements.", func() {
    32  
    33  			in1 := `
    34  type in1 struct {
    35  	Str string
    36  	N   int
    37      D   float64
    38  }`
    39  			expect1 := `struct In1Capn { str @0: Text; n @1: Int64; d @2: Float64;}`
    40  			// List(Float64) next
    41  
    42  			cv.So(ExtractString2String(in1), ShouldStartWithModuloWhiteSpace, expect1)
    43  		})
    44  	})
    45  }
    46  
    47  /* unclear if we really want this or not
    48  func TestNonStructTypeDefsAreIgnored(t *testing.T) {
    49  
    50  	cv.Convey("Given a go type definition 'type SyncMsg int32' that isn't a struct definition,", t, func() {
    51  		cv.Convey("then bambam should not define a new SyncMsgCapn for it, but should generate a capnp Int32 field in the capnp struct", func() {
    52  
    53  			in1 := `
    54  type S struct {
    55    A SyncMsg
    56  }
    57  type SyncMsg int32
    58  `
    59  			expect1 := `struct SCapn { a @0: Int32; } `
    60  
    61  			cv.So(ExtractString2String(in1), ShouldStartWithModuloWhiteSpace, expect1)
    62  		})
    63  	})
    64  }
    65  */