Skip to content

Commit 4ac4860

Browse files
committed
Added Map.Keys() method
1 parent b937fa0 commit 4ac4860

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

properties.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ func (m Map) Merge(sources ...Map) Map {
287287
return m
288288
}
289289

290+
// Keys returns an array of the keys contained in the Map
291+
func (m Map) Keys() []string {
292+
keys := make([]string, len(m))
293+
i := 0
294+
for key := range m {
295+
keys[i] = key
296+
i++
297+
}
298+
return keys
299+
}
300+
290301
// Clone makes a copy of the Map
291302
func (m Map) Clone() Map {
292303
clone := make(Map)

properties_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
package properties
3131

3232
import (
33+
"fmt"
3334
"path/filepath"
3435
"runtime"
3536
"testing"
@@ -171,3 +172,12 @@ func TestGetSetBoolean(t *testing.T) {
171172
require.Equal(t, "true", m["e"])
172173
require.Equal(t, "false", m["f"])
173174
}
175+
176+
func TestKeysMethod(t *testing.T) {
177+
m := Map{
178+
"k1": "value",
179+
"k2": "othervalue",
180+
"k3.k4": "anothevalue",
181+
}
182+
require.Equal(t, "[k1 k2 k3.k4]", fmt.Sprintf("%s", m.Keys()))
183+
}

0 commit comments

Comments
 (0)