walk: handle map test separately

This commit is contained in:
Muyao CHEN 2024-09-20 20:51:44 +02:00
parent 10a93aeb27
commit 574532f484

View File

@ -70,14 +70,6 @@ func TestWalk(t *testing.T) {
},
[]string{"London", "Paris"},
},
{
"maps",
map[string]string{
"Cow": "meuh",
"Sheep": "meh",
},
[]string{"meuh", "meh"},
},
}
for _, test := range cases {
@ -92,4 +84,32 @@ func TestWalk(t *testing.T) {
}
})
}
t.Run("with maps", func(t *testing.T) {
aMap := map[string]string{
"Cow": "meuh",
"Sheep": "meh",
}
var got []string
Walk(aMap, func(input string) {
got = append(got, input)
})
assertContains(t, got, "meuh")
assertContains(t, got, "meh")
})
}
func assertContains(t testing.TB, haystack []string, needle string) {
t.Helper()
contains := false
for _, x := range haystack {
if x == needle {
contains = true
}
}
if !contains {
t.Errorf("expected %v to contain %q but it didn't", haystack, needle)
}
}