OSDN Git Service

Hulk did something
[bytom/vapor.git] / vendor / github.com / johngb / langreg / region_test.go
1 package langreg
2
3 import (
4         "testing"
5
6         . "github.com/smartystreets/goconvey/convey"
7 )
8
9 type regTestInfo struct {
10         code            string
11         expectedName    string
12         errExpected     bool
13         testDescription string
14 }
15
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"},
27 }
28
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)
34                         if !tt.errExpected {
35                                 So(actualErr, ShouldBeNil)
36                         } else {
37                                 So(actualErr, ShouldNotBeNil)
38                         }
39                 })
40         }
41 }
42
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)
48                 })
49         }
50 }
51
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)
57                         if !tt.errExpected {
58                                 So(actualErr, ShouldBeNil)
59                         } else {
60                                 So(actualErr, ShouldNotBeNil)
61                         }
62                 })
63         }
64 }
65
66 func BenchmarkRegionCodeInfo(b *testing.B) {
67         for n := 0; n < b.N; n++ {
68                 _, err := RegionCodeInfo("ZW")
69                 if err != nil {
70                         b.Error(err.Error())
71                 }
72         }
73 }
74
75 func BenchmarkIsValidRegionCode(b *testing.B) {
76         for n := 0; n < b.N; n++ {
77                 isValid := IsValidRegionCode("ZW")
78                 if !isValid {
79                         b.Error("invalid region code")
80                 }
81         }
82 }
83
84 func BenchmarkRegionName(b *testing.B) {
85         for n := 0; n < b.N; n++ {
86                 _, err := RegionName("ZW")
87                 if err != nil {
88                         b.Error(err.Error())
89                 }
90         }
91 }