github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/internal/examples/mapexamples/map_Keys_Values_test.go (about)

     1  package mapexamples
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/m4gshm/gollections/convert/as"
     9  	"github.com/m4gshm/gollections/map_"
    10  	"github.com/m4gshm/gollections/slice"
    11  	"github.com/m4gshm/gollections/slice/sort"
    12  )
    13  
    14  func Test_Keys(t *testing.T) {
    15  
    16  	var employers = map[string]map[string]string{
    17  		"devops": {"name": "Bob"},
    18  		"jun":    {"name": "Tom"},
    19  	}
    20  
    21  	keys := map_.Keys(employers)     //[devops jun]
    22  	values := map_.Values(employers) //[map[name:Bob] map[name:Tom]]
    23  
    24  	assert.Equal(t, slice.Of("devops", "jun"), sort.Asc(keys))
    25  
    26  	names := slice.Flat(slice.Convert(values, map_.Values), as.Is[[]string])
    27  	assert.Equal(t, slice.Of("Bob", "Tom"), sort.Asc(names))
    28  
    29  }