package generics import ( "testing" "github.com/stretchr/testify/require" ) func TestPairsKeys(t *testing.T) { tests := map[string]struct { src Pairs[string, int] dst []string }{ "nil pairs": { src: nil, dst: []string{}, }, "empty pairs": { src: Pairs[string, int]{}, dst: []string{}, }, "filled pairs": { src: Pairs[string, int]{ { Key: "foo", Value: 1, }, { Key: "bar", Value: 2, }, { Key: "baz", Value: 3, }, }, dst: []string{ "foo", "bar", "baz", }, }, } for name, tc := range tests { name, tc := name, tc t.Run(name, func(t *testing.T) { dst := tc.src.Keys() require.ElementsMatch(t, tc.dst, dst) }) } } func TestPairsValues(t *testing.T) { tests := map[string]struct { src Pairs[string, int] dst []int }{ "nil pairs": { src: nil, dst: []int{}, }, "empty pairs": { src: Pairs[string, int]{}, dst: []int{}, }, "filled pairs": { src: Pairs[string, int]{ { Key: "foo", Value: 1, }, { Key: "bar", Value: 2, }, { Key: "baz", Value: 3, }, }, dst: []int{1, 2, 3}, }, } for name, tc := range tests { name, tc := name, tc t.Run(name, func(t *testing.T) { dst := tc.src.Values() require.ElementsMatch(t, tc.dst, dst) }) } }