github.com/wI2L/jettison@v0.7.5-0.20230106001914-c70014c6417a/tags_test.go (about)

     1  package jettison
     2  
     3  import "testing"
     4  
     5  func TestParseTag(t *testing.T) {
     6  	testdata := []struct {
     7  		tag  string
     8  		name string
     9  		opts []string
    10  	}{
    11  		{"", "", nil},
    12  		{"foobar", "foobar", nil},
    13  		{"foo,bar", "foo", []string{"bar"}},
    14  		{"bar,", "bar", nil},
    15  		{"a,b,c,", "a", []string{"b", "c"}},
    16  		{" foo , bar ,", " foo ", []string{" bar "}},
    17  		{",bar", "", []string{"bar"}},
    18  		{", ", "", []string{" "}},
    19  		{",", "", nil},
    20  		{"bar, ,foo", "bar", []string{" ", "foo"}},
    21  	}
    22  	for _, v := range testdata {
    23  		name, opts := parseTag(v.tag)
    24  		if name != v.name {
    25  			t.Errorf("tag name: got %q, want %q", name, v.name)
    26  		}
    27  		for _, opt := range v.opts {
    28  			if !opts.Contains(opt) {
    29  				t.Errorf("missing tag option %q", opt)
    30  			}
    31  		}
    32  	}
    33  }