v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/util/maps/keys_test.go (about)

     1  package maps
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestKeys(t *testing.T) {
     9  	type args struct {
    10  		m map[string]string
    11  	}
    12  	tests := []struct {
    13  		name string
    14  		args args
    15  		want []string
    16  	}{
    17  		{
    18  			name: "empty",
    19  			args: args{
    20  				m: map[string]string{},
    21  			},
    22  			want: []string{},
    23  		},
    24  		{
    25  			name: "nil",
    26  			args: args{
    27  				m: nil,
    28  			},
    29  			want: nil,
    30  		},
    31  		{
    32  			name: "one",
    33  			args: args{
    34  				m: map[string]string{
    35  					"a": "b",
    36  				},
    37  			},
    38  			want: []string{"a"},
    39  		},
    40  		{
    41  			name: "two",
    42  			args: args{
    43  				m: map[string]string{
    44  					"a": "b",
    45  					"c": "d",
    46  				},
    47  			},
    48  			want: []string{"a", "c"},
    49  		},
    50  		{
    51  			name: "three",
    52  			args: args{
    53  				m: map[string]string{
    54  					"a": "b",
    55  					"c": "d",
    56  					"e": "f",
    57  				},
    58  			},
    59  			want: []string{"a", "c", "e"},
    60  		},
    61  	}
    62  	for _, tt := range tests {
    63  		t.Run(tt.name, func(t *testing.T) {
    64  			if got := Keys(tt.args.m); !reflect.DeepEqual(got, tt.want) {
    65  				t.Errorf("Keys() = %v, want %v", got, tt.want)
    66  			}
    67  		})
    68  	}
    69  }