1
0
Fork 0

Add tests for data

main
Ambrose Chua 2020-11-10 19:44:58 +08:00
parent 74dd1ebfd1
commit 9cffe08a20
5 changed files with 43 additions and 5 deletions

View File

@ -38,7 +38,7 @@ jobs:
uses: actions/checkout@v2
- name: Vet code
run: go vet
run: go vet ./...
format:
name: Format
@ -59,7 +59,7 @@ jobs:
git config --local user.name "GitHub Action"
- name: Format code
run: gofmt -l -w -s .
run: gofmt -l -w -s ./...
- name: Commit and push changes
id: commit-dockerfiles

View File

@ -21,7 +21,7 @@ datetime: *.go data/*.go
.PHONY: test
test: data
$(GO) test -cover -bench=. -v
$(GO) test -cover -bench=. -v ./...
DATASETS = \

View File

@ -205,6 +205,7 @@ d-zoneinfo {
d-zonename {
display: inline;
font-size: 0.75em;
font-weight: 600;
}

View File

@ -29,7 +29,7 @@ func extendName(names ...string) string {
// FullName returns a fully qualified human readable name
func (c City) FullName() string {
if len(c.Admin1.Name) > 0 {
return extendName(c.Name, c.Admin1.Name, c.Country.Name)
return extendName(c.Name, c.Admin1.Name, c.Country.Ref)
}
return extendName(c.Name, c.Country.Name)
return extendName(c.Name, c.Country.Ref)
}

37
data/data_test.go Normal file
View File

@ -0,0 +1,37 @@
package data
import (
"testing"
)
func TestCityFullName(t *testing.T) {
c := City{
Name: "'cit-y N'ame-",
Admin1: Admin1{
Name: "a-dmin1, Name'",
},
Country: Country{
Name: "Country Name",
Ref: "CN",
},
}
got, want := c.FullName(), "'cit-y N'ame-, a-dmin1, Name', CN"
if got != want {
t.Errorf("got %v, want %v", got, want)
}
c = City{
Name: "City Name",
Admin1: Admin1{},
Country: Country{
Name: "Name Country",
Ref: "CN",
},
}
got, want = c.FullName(), "City Name, CN"
if got != want {
t.Errorf("got %v, want %v", got, want)
}
}