diff --git a/query_test.go b/query_test.go index 5f4778b..340ca0b 100644 --- a/query_test.go +++ b/query_test.go @@ -2,10 +2,11 @@ package gountries import ( "fmt" - "github.com/stretchr/testify/assert" "math/rand" "sort" "testing" + + "github.com/stretchr/testify/assert" ) func TestFindCountryByName(t *testing.T) { @@ -24,6 +25,24 @@ func TestFindCountryByName(t *testing.T) { assert.Equal(t, result.Alpha2, "SE", "Lowercase country names should match") + // Test for common name + result, err = query.FindCountryByName("United States") + + if err != nil { + t.Fail() + } + + assert.Equal(t, result.Alpha2, "US", "Lowercase country names should match") + + // Test for official name + result, err = query.FindCountryByName("United States of America") + + if err != nil { + t.Fail() + } + + assert.Equal(t, result.Alpha2, "US", "Lowercase country names should match") + // Test for uppercase // diff --git a/setup.go b/setup.go index 9c26cdb..1253333 100644 --- a/setup.go +++ b/setup.go @@ -38,7 +38,9 @@ func populateNameIndex(countries map[string]Country) map[string]string { index := make(map[string]string) for alpha2, country := range countries { name := strings.ToLower(country.Name.Common) + officialName := strings.ToLower(country.Name.Official) index[name] = alpha2 + index[officialName] = alpha2 } return index }