github.com/everdrone/grab@v0.1.7-0.20230416223925-40674b995521/internal/utils/table_test.go (about)

     1  package utils
     2  
     3  import "testing"
     4  
     5  func TestFormatMap(t *testing.T) {
     6  	tests := []struct {
     7  		Name       string
     8  		Separator  string
     9  		AlignRight bool
    10  		Map        map[string]string
    11  		Want       string
    12  	}{
    13  		{
    14  			Name:       "empty map",
    15  			Separator:  ":",
    16  			AlignRight: false,
    17  			Map:        map[string]string{},
    18  			Want:       "",
    19  		},
    20  		{
    21  			Name:       "one element",
    22  			Separator:  ":",
    23  			AlignRight: false,
    24  			Map: map[string]string{
    25  				"foo": "bar",
    26  			},
    27  			Want: "foo:bar\n",
    28  		},
    29  		{
    30  			Name:       "two elements",
    31  			Separator:  ":",
    32  			AlignRight: false,
    33  			Map: map[string]string{
    34  				"foooooooo": "bar",
    35  				"baz":       "qux",
    36  			},
    37  			Want: "baz      :qux\nfoooooooo:bar\n",
    38  		},
    39  		{
    40  			Name:       "align right",
    41  			Separator:  ":",
    42  			AlignRight: true,
    43  			Map: map[string]string{
    44  				"foooooooo": "bar",
    45  				"baz":       "qux",
    46  			},
    47  			Want: "      baz:qux\nfoooooooo:bar\n",
    48  		},
    49  	}
    50  
    51  	for _, tt := range tests {
    52  		t.Run(tt.Name, func(tc *testing.T) {
    53  			got := FormatMap(tt.Map, tt.Separator, tt.AlignRight)
    54  			if got != tt.Want {
    55  				tc.Errorf("got: %q, want %q", got, tt.Want)
    56  			}
    57  		})
    58  	}
    59  }