walk: handle map test separately
This commit is contained in:
		@ -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)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user