Skip to content

Commit 67ac7be

Browse files
committed
Added Map.Values() method
1 parent 4ac4860 commit 67ac7be

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

properties.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,18 @@ func (m Map) Keys() []string {
298298
return keys
299299
}
300300

301+
// Values returns an array of the values contained in the Map. Duplicated
302+
// values are repeated in the list accordingly.
303+
func (m Map) Values() []string {
304+
values := make([]string, len(m))
305+
i := 0
306+
for _, value := range m {
307+
values[i] = value
308+
i++
309+
}
310+
return values
311+
}
312+
301313
// Clone makes a copy of the Map
302314
func (m Map) Clone() Map {
303315
clone := make(Map)

properties_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"fmt"
3434
"path/filepath"
3535
"runtime"
36+
"sort"
3637
"testing"
3738

3839
"github.com/stretchr/testify/require"
@@ -178,6 +179,14 @@ func TestKeysMethod(t *testing.T) {
178179
"k1": "value",
179180
"k2": "othervalue",
180181
"k3.k4": "anothevalue",
182+
"k5": "value",
181183
}
182-
require.Equal(t, "[k1 k2 k3.k4]", fmt.Sprintf("%s", m.Keys()))
184+
185+
k := m.Keys()
186+
sort.Strings(k)
187+
require.Equal(t, "[k1 k2 k3.k4 k5]", fmt.Sprintf("%s", k))
188+
189+
v := m.Values()
190+
sort.Strings(v)
191+
require.Equal(t, "[anothevalue othervalue value value]", fmt.Sprintf("%s", v))
183192
}

0 commit comments

Comments
 (0)