github.com/angenalZZZ/gofunc@v0.0.0-20210507121333-48ff1be3917b/g/tags_test.go (about)

     1  package g_test
     2  
     3  import (
     4  	"github.com/angenalZZZ/gofunc/g"
     5  	"testing"
     6  )
     7  
     8  func TestParseTag_Name(t *testing.T) {
     9  	tags := []struct {
    10  		tag string
    11  		has bool
    12  	}{
    13  		{"", false},
    14  		{"name", true},
    15  		{"name,opt", true},
    16  		{"name , opt, opt2", false}, // has a single whitespace
    17  		{", opt, opt2", false},
    18  	}
    19  
    20  	for _, tag := range tags {
    21  		name, _ := g.ParseTag(tag.tag)
    22  
    23  		if (name != "name") && tag.has {
    24  			t.Errorf("Parse tag should return name: %#v", tag)
    25  		}
    26  	}
    27  }
    28  
    29  func TestParseTag_Opts(t *testing.T) {
    30  	tags := []struct {
    31  		opts string
    32  		has  bool
    33  	}{
    34  		{"name", false},
    35  		{"name,opt", true},
    36  		{"name , opt, opt2", false}, // has a single whitespace
    37  		{",opt, opt2", true},
    38  		{", opt3, opt4", false},
    39  	}
    40  
    41  	// search for "opt"
    42  	for _, tag := range tags {
    43  		_, opts := g.ParseTag(tag.opts)
    44  
    45  		if opts.Has("opt") != tag.has {
    46  			t.Errorf("Tag opts should have opt: %#v", tag)
    47  		}
    48  	}
    49  }