|
|
@@ -446,6 +446,7 @@ func (v testStructView) AsStruct() *testStruct {
|
|
|
}
|
|
|
return v.p.Clone()
|
|
|
}
|
|
|
+func (v testStructView) ValueForTest() string { return v.p.value }
|
|
|
|
|
|
func TestSliceViewRange(t *testing.T) {
|
|
|
vs := SliceOfViews([]*testStruct{{value: "foo"}, {value: "bar"}})
|
|
|
@@ -458,3 +459,45 @@ func TestSliceViewRange(t *testing.T) {
|
|
|
t.Errorf("got %q; want %q", got, want)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestMapIter(t *testing.T) {
|
|
|
+ m := MapOf(map[string]int{"foo": 1, "bar": 2})
|
|
|
+ var got []string
|
|
|
+ for k, v := range m.All() {
|
|
|
+ got = append(got, fmt.Sprintf("%s-%d", k, v))
|
|
|
+ }
|
|
|
+ slices.Sort(got)
|
|
|
+ want := []string{"bar-2", "foo-1"}
|
|
|
+ if !slices.Equal(got, want) {
|
|
|
+ t.Errorf("got %q; want %q", got, want)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestMapSliceIter(t *testing.T) {
|
|
|
+ m := MapSliceOf(map[string][]int{"foo": {3, 4}, "bar": {1, 2}})
|
|
|
+ var got []string
|
|
|
+ for k, v := range m.All() {
|
|
|
+ got = append(got, fmt.Sprintf("%s-%d", k, v))
|
|
|
+ }
|
|
|
+ slices.Sort(got)
|
|
|
+ want := []string{"bar-{[1 2]}", "foo-{[3 4]}"}
|
|
|
+ if !slices.Equal(got, want) {
|
|
|
+ t.Errorf("got %q; want %q", got, want)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestMapFnIter(t *testing.T) {
|
|
|
+ m := MapFnOf[string, *testStruct, testStructView](map[string]*testStruct{
|
|
|
+ "foo": {value: "fooVal"},
|
|
|
+ "bar": {value: "barVal"},
|
|
|
+ }, func(p *testStruct) testStructView { return testStructView{p} })
|
|
|
+ var got []string
|
|
|
+ for k, v := range m.All() {
|
|
|
+ got = append(got, fmt.Sprintf("%v-%v", k, v.ValueForTest()))
|
|
|
+ }
|
|
|
+ slices.Sort(got)
|
|
|
+ want := []string{"bar-barVal", "foo-fooVal"}
|
|
|
+ if !slices.Equal(got, want) {
|
|
|
+ t.Errorf("got %q; want %q", got, want)
|
|
|
+ }
|
|
|
+}
|