github.com/sandwich-go/boost@v1.3.29/misc/annotation/parser_test.go (about)

     1  package annotation
     2  
     3  import (
     4  	. "github.com/smartystreets/goconvey/convey"
     5  	"testing"
     6  )
     7  
     8  func TestParser(t *testing.T) {
     9  	Convey("parser", t, func() {
    10  		for _, test := range []struct {
    11  			line     string
    12  			validate func(Annotation)
    13  			lowKey   bool
    14  		}{
    15  			{`@X( a = "A" }`, nil, true},
    16  			{`@ X( a = "A" )`, func(ann Annotation) {
    17  				So(ann.Name(), ShouldEqual, "X")
    18  				So(ann.String("a"), ShouldEqual, "A")
    19  			}, true},
    20  			{`@X( a = "A" )`, func(ann Annotation) {
    21  				So(ann.Name(), ShouldEqual, "X")
    22  				So(ann.String("a"), ShouldEqual, "A")
    23  			}, true},
    24  			{`@X( A = "A" )`, func(ann Annotation) {
    25  				So(ann.Name(), ShouldEqual, "X")
    26  				So(ann.String("a"), ShouldEqual, "A")
    27  			}, true},
    28  			{`//aaaaa@X( A = "A" )`, func(ann Annotation) {
    29  				So(ann.Name(), ShouldEqual, "X")
    30  				So(ann.String("a"), ShouldEqual, "A")
    31  			}, true},
    32  			{`@ X ( A = "A" , b = "B", c= "c" )`, func(ann Annotation) {
    33  				So(ann.Name(), ShouldEqual, "X")
    34  				So(ann.String("a"), ShouldEqual, "A")
    35  				So(ann.String("b"), ShouldEqual, "B")
    36  				So(ann.String("c"), ShouldEqual, "c")
    37  			}, true},
    38  			{`@ X ( A = "A" , b = "B", c= "c" )`, func(ann Annotation) {
    39  				So(ann.Name(), ShouldEqual, "X")
    40  				So(ann.String("A"), ShouldEqual, "A")
    41  				So(ann.String("b"), ShouldEqual, "B")
    42  				So(ann.String("c"), ShouldEqual, "c")
    43  			}, false},
    44  		} {
    45  			ann, err := parser(test.line, test.lowKey)
    46  			if test.validate != nil {
    47  				So(err, ShouldBeNil)
    48  				test.validate(ann)
    49  			} else {
    50  				So(err, ShouldNotBeNil)
    51  			}
    52  		}
    53  	})
    54  }