github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xmap/maps_test.go (about)

     1  package xmap
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestMap(t *testing.T) {
    10  	t.Run("keys", func(t *testing.T) {
    11  		x := Keys(map[string]int{"1": 2})
    12  		require.EqualValues(t, []interface{}{"1"}, x, "")
    13  		y := Keys(struct{ Key int }{Key: 11})
    14  		require.EqualValues(t, []interface{}{"Key"}, y, "")
    15  	})
    16  	t.Run("values", func(t *testing.T) {
    17  		x := Values(map[string]int{"1": 2})
    18  		t.Logf("%+v\n", x)
    19  		y := Values(struct{ Key int }{Key: 11})
    20  		t.Logf("%+v\n", y)
    21  	})
    22  	t.Run("contains", func(t *testing.T) {
    23  		require.Equal(t, true, Contains(map[string]struct{}{"1": {}, "2": {}}, "1"))
    24  		require.Equal(t, false, Contains(map[string]struct{}{"1": {}, "2": {}}, "3"))
    25  		require.Equal(t, true, Contains(map[byte]struct{}{'a': {}, 'c': {}}, uint8('c')))
    26  		require.Equal(t, false, Contains(map[byte]struct{}{'a': {}, 'c': {}}, uint8('b')))
    27  	})
    28  }