Skip to content

Commit

Permalink
Merge pull request #12 from aaronmcohen/master
Browse files Browse the repository at this point in the history
Official name query support
  • Loading branch information
pariz authored Jul 27, 2017
2 parents 01a8f4c + fb94097 commit dbe7aab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 20 additions & 1 deletion query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
//

Expand Down
2 changes: 2 additions & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit dbe7aab

Please sign in to comment.