MCPcopy Create free account
hub / github.com/github/gh-aw / TestMapKeys

Function TestMapKeys

pkg/sliceutil/sliceutil_test.go:151–175  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

149}
150
151func TestMapKeys(t *testing.T) {
152 t.Run("nil map returns empty slice", func(t *testing.T) {
153 result := MapKeys[string, int](nil)
154 assert.Empty(t, result, "MapKeys should return empty slice for nil map")
155 })
156
157 t.Run("empty map returns empty slice", func(t *testing.T) {
158 result := MapKeys(map[string]int{})
159 assert.Empty(t, result, "MapKeys should return empty slice for empty map")
160 })
161
162 t.Run("returns all keys in any order", func(t *testing.T) {
163 m := map[string]int{"apple": 1, "banana": 2, "cherry": 3}
164 result := MapKeys(m)
165 assert.ElementsMatch(t, []string{"apple", "banana", "cherry"}, result,
166 "MapKeys should return all keys from map")
167 })
168
169 t.Run("single entry map", func(t *testing.T) {
170 m := map[string]struct{}{"only": {}}
171 result := MapKeys(m)
172 assert.Equal(t, []string{"only"}, result,
173 "MapKeys should return the single key from a one-entry map")
174 })
175}
176
177func TestFilterMapKeys(t *testing.T) {
178 t.Run("nil map returns empty slice", func(t *testing.T) {

Callers

nothing calls this directly

Calls 2

MapKeysFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected