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

     1  package main
     2  
     3  import (
     4  	"testing"
     5  
     6  	cv "github.com/glycerine/goconvey/convey"
     7  )
     8  
     9  func TestCommentAnnotationWorks(t *testing.T) {
    10  
    11  	cv.Convey(`Given a golang struct named Data with an attached comment: // capname:"MyData"`, t, func() {
    12  		cv.Convey("then we should use the capname MyData for the struct.", func() {
    13  			ex0 := `
    14  // capname:"MyData"
    15  type Data struct {
    16  }`
    17  			cv.So(ExtractString2String(ex0), ShouldStartWithModuloWhiteSpace, `struct MyData { } `)
    18  
    19  			ex1 := `
    20  // capname: "MyData"
    21  type Data struct {
    22  }`
    23  			cv.So(ExtractString2String(ex1), ShouldStartWithModuloWhiteSpace, `struct MyData { } `)
    24  
    25  		})
    26  
    27  	})
    28  }
    29  
    30  func TestTagAnnotationWorks(t *testing.T) {
    31  
    32  	cv.Convey("Given a golang struct with an invalid capnp field name 'Union', but with a field tag: `capname:\"MyNewFieldName\"`", t, func() {
    33  		cv.Convey("then we should use the capname MyNewFieldName for the field, and not stop the run.", func() {
    34  			ex0 := "type S struct { Union string `capname:\"MyNewFieldName\"` \n}"
    35  			cv.So(ExtractString2String(ex0), ShouldStartWithModuloWhiteSpace, `struct SCapn { MyNewFieldName  @0:   Text; } `)
    36  			ex1 := "type S struct { Union string `capname: \t \t \"MyNewFieldName\"` \n}"
    37  			cv.So(ExtractString2String(ex1), ShouldStartWithModuloWhiteSpace, `struct SCapn { MyNewFieldName  @0:   Text; } `)
    38  		})
    39  
    40  	})
    41  }
    42  
    43  func TestTagZidWorks(t *testing.T) {
    44  
    45  	cv.Convey("Given the desire to preserve the field numbering in the generated Capnproto schema,", t, func() {
    46  		cv.Convey("when we add the tag: zid:\"1\", then the field should be numbered @1.", func() {
    47  			cv.Convey("and if there are fewer than 2 (numbered 0, 1) fields then we error out.", func() {
    48  				ex0 := "type S struct { A string `zid:\"1\"`; B string \n}"
    49  				cv.So(ExtractString2String(ex0), ShouldStartWithModuloWhiteSpace, `struct SCapn { b  @0:   Text; a  @1:   Text; } `)
    50  			})
    51  		})
    52  
    53  	})
    54  }
    55  
    56  func TestLowercaseGoFieldsIgnoredByDefault(t *testing.T) {
    57  
    58  	cv.Convey("Given the traditional golang std lib behvaior of not serializing lowercase fields,", t, func() {
    59  		cv.Convey("then by default we should ignore lower case fields in writing the capnproto schema.", func() {
    60  			ex0 := "type S struct { a string; B string \n}"
    61  			cv.So(ExtractString2String(ex0), ShouldStartWithModuloWhiteSpace, `struct SCapn { b @0: Text; } `)
    62  		})
    63  	})
    64  
    65  }