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

     1  package mapexamples
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/m4gshm/gollections/map_"
     9  )
    10  
    11  func Test_ConvertKeys(t *testing.T) {
    12  
    13  	var employers = map[string]map[string]string{
    14  		"devops": {"name": "Bob"},
    15  		"jun":    {"name": "Tom"},
    16  	}
    17  
    18  	var keys = map_.ConvertKeys(employers, func(title string) string {
    19  		return string([]rune(title)[0])
    20  	})
    21  	//map[d:map[name:Bob] j:map[name:Tom]]
    22  
    23  	assert.Equal(t, map[string]map[string]string{"d": {"name": "Bob"}, "j": {"name": "Tom"}}, keys)
    24  
    25  }