6 . "github.com/smartystreets/goconvey/convey"
9 type regTestInfo struct {
13 testDescription string
16 var regTests = []regTestInfo{
17 {"GB", "United Kingdom", false, "code with ascii character set"},
18 {"gb", "", true, "code with lowercase ascii characters"},
19 {"AX", "Aland Islands !Ă…land Islands", false, "code with non-ascii Unicode character set"},
20 {" GB ", "", true, "code with leading and trailng space"},
21 {"\n\tGB", "", true, "code with leading and trailing whitespace"},
22 {"RSA", "", true, "code that is too long"},
23 {"Z", "", true, "code that is too short"},
24 {"ZZ", "", true, "code that is invalid"},
25 {"*G", "", true, "code with invalid characters"},
26 {"73", "", true, "code with numbers"},
29 func TestRegionCodeInfo(t *testing.T) {
30 for _, tt := range regTests {
31 Convey("Given a "+tt.testDescription, t, func() {
32 actualName, actualErr := RegionCodeInfo(tt.code)
33 So(actualName, ShouldEqual, tt.expectedName)
35 So(actualErr, ShouldBeNil)
37 So(actualErr, ShouldNotBeNil)
43 func TestIsValidRegionCode(t *testing.T) {
44 for _, tt := range regTests {
45 Convey("Given a "+tt.testDescription, t, func() {
46 actualIsValid := IsValidRegionCode(tt.code)
47 So(!actualIsValid, ShouldEqual, tt.errExpected)
52 func TestRegionName(t *testing.T) {
53 for _, tt := range regTests {
54 Convey("Given a "+tt.testDescription, t, func() {
55 actualName, actualErr := RegionName(tt.code)
56 So(actualName, ShouldEqual, tt.expectedName)
58 So(actualErr, ShouldBeNil)
60 So(actualErr, ShouldNotBeNil)
66 func BenchmarkRegionCodeInfo(b *testing.B) {
67 for n := 0; n < b.N; n++ {
68 _, err := RegionCodeInfo("ZW")
75 func BenchmarkIsValidRegionCode(b *testing.B) {
76 for n := 0; n < b.N; n++ {
77 isValid := IsValidRegionCode("ZW")
79 b.Error("invalid region code")
84 func BenchmarkRegionName(b *testing.B) {
85 for n := 0; n < b.N; n++ {
86 _, err := RegionName("ZW")