Add method "IsValidContinent".

This commit is contained in:
Joachim Bauch 2021-08-06 15:41:18 +02:00
parent 2ac58a3360
commit ffb79c747c
No known key found for this signature in database
GPG Key ID: 77C1D22D53E15F02
2 changed files with 38 additions and 0 deletions

View File

@ -239,3 +239,31 @@ func LookupContinents(country string) []string {
return continents return continents
} }
} }
func IsValidContinent(continent string) bool {
switch continent {
case "AF":
// Africa
fallthrough
case "AN":
// Antartica
fallthrough
case "AS":
// Asia
fallthrough
case "EU":
// Europe
fallthrough
case "NA":
// North America
fallthrough
case "SA":
// South America
fallthrough
case "OC":
// Oceania
return true
default:
return false
}
}

View File

@ -200,3 +200,13 @@ func TestGeoLookupFromFile(t *testing.T) {
testGeoLookupReader(t, reader) testGeoLookupReader(t, reader)
} }
func TestIsValidContinent(t *testing.T) {
for country, continents := range ContinentMap {
for _, continent := range continents {
if !IsValidContinent(continent) {
t.Errorf("Continent %s of country %s is not valid", continent, country)
}
}
}
}