27 lines
620 B
Go
27 lines
620 B
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestMatchRecentLocations(t *testing.T) {
|
|
recent := []Location{
|
|
{City: "Boston", State: "MA"},
|
|
{City: "Somerville", State: "MA"},
|
|
{City: "Somerville", State: "NJ"},
|
|
}
|
|
|
|
matches := matchRecentLocations(recent, "somer")
|
|
if len(matches) != 2 {
|
|
t.Fatalf("expected 2 matches, got %d", len(matches))
|
|
}
|
|
|
|
matches = matchRecentLocations(recent, "boston")
|
|
if len(matches) != 1 {
|
|
t.Fatalf("expected 1 match, got %d", len(matches))
|
|
}
|
|
|
|
matches = matchRecentLocations(recent, "")
|
|
if len(matches) != 0 {
|
|
t.Fatalf("expected 0 matches for empty query, got %d", len(matches))
|
|
}
|
|
}
|