github.com/msales/pkg/v3@v3.24.0/utils/strings_test.go (about)

     1  package utils_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/msales/pkg/v3/utils"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestSplitMap(t *testing.T) {
    11  	tests := []struct {
    12  		in     []string
    13  		sep    string
    14  		expect map[string]string
    15  	}{
    16  		{
    17  			in:     []string{"foo=bar", "bar=baz", "test=test=test"},
    18  			sep:    "=",
    19  			expect: map[string]string{"foo": "bar", "bar": "baz", "test": "test=test"},
    20  		},
    21  		{
    22  			in:     []string{},
    23  			sep:    "=",
    24  			expect: nil,
    25  		},
    26  		{
    27  			in:     nil,
    28  			sep:    "=",
    29  			expect: nil,
    30  		},
    31  		{
    32  			in:     []string{"foo=bar", "bar=baz"},
    33  			sep:    "",
    34  			expect: nil,
    35  		},
    36  		{
    37  			in:     []string{"foo", "bar"},
    38  			sep:    "=",
    39  			expect: map[string]string{"foo": "", "bar": ""},
    40  		},
    41  	}
    42  
    43  	for _, test := range tests {
    44  		out := utils.SplitMap(test.in, test.sep)
    45  		assert.Equal(t, test.expect, out)
    46  	}
    47  }