Skip to content

Commit 68b6a03

Browse files
committed
feat(set): Add set.Values() method
1 parent 9d69345 commit 68b6a03

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

dbus/set.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ func (s *set) Length() (int) {
2121
return len(s.data)
2222
}
2323

24+
func (s *set) Values() (values []string) {
25+
for val, _ := range s.data {
26+
values = append(values, val)
27+
}
28+
return
29+
}
30+
2431
func newSet() (*set) {
2532
return &set{make(map[string] bool)}
2633
}

dbus/set_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,22 @@ func TestBasicSetActions(t *testing.T) {
1818
t.Fatal("set should contain 'foo'")
1919
}
2020

21+
v := s.Values()
22+
if len(v) != 1 {
23+
t.Fatal("set.Values did not report correct number of values")
24+
}
25+
if v[0] != "foo" {
26+
t.Fatal("set.Values did not report value")
27+
}
28+
2129
s.Remove("foo")
2230

2331
if s.Contains("foo") {
2432
t.Fatal("set should not contain 'foo'")
2533
}
34+
35+
v = s.Values()
36+
if len(v) != 0 {
37+
t.Fatal("set.Values did not report correct number of values")
38+
}
2639
}

0 commit comments

Comments
 (0)