6 . "github.com/smartystreets/goconvey/convey"
9 type langTestInfo struct {
14 testDescription string
17 var langTests = []langTestInfo{
18 {"en", "English", "English", false, "code with ascii character set"},
19 {"EN", "", "", true, "code with uppercase ascii characters"},
20 {"iu", "Inuktitut", "ᐃᓄᒃᑎᑐᑦ", false, "code with non-ascii Unicode character set"},
21 {" en ", "", "", true, "code with leading and trailng space"},
22 {"\nen ", "", "", true, "code with leading and trailing whitespace"},
23 {"zzz", "", "", true, "code that is too long"},
24 {"z", "", "", true, "code that is too short"},
25 {"zz", "", "", true, "code that is invalid"},
26 {"*z", "", "", true, "code with invalid characters"},
27 {"73", "", "", true, "code with numbers"},
30 func TestLanguageCodeInfo(t *testing.T) {
31 for _, tt := range langTests {
32 Convey("Given a "+tt.testDescription, t, func() {
33 actualEn, actualNat, actualErr := LangCodeInfo(tt.code)
34 So(actualEn, ShouldEqual, tt.expectedEn)
35 So(actualNat, ShouldEqual, tt.expectedNat)
37 So(actualErr, ShouldBeNil)
39 So(actualErr, ShouldNotBeNil)
45 func TestIsLanguageCode(t *testing.T) {
46 for _, tt := range langTests {
47 Convey("Given a "+tt.testDescription, t, func() {
48 actualIsValid := IsValidLanguageCode(tt.code)
49 So(!actualIsValid, ShouldEqual, tt.errExpected)
54 func TestLangEnglishName(t *testing.T) {
55 for _, tt := range langTests {
56 Convey("Given a "+tt.testDescription, t, func() {
57 actualEnName, actualErr := LangEnglishName(tt.code)
58 So(actualEnName, ShouldEqual, tt.expectedEn)
60 So(actualErr, ShouldBeNil)
62 So(actualErr, ShouldNotBeNil)
68 func TestLangNativeName(t *testing.T) {
69 for _, tt := range langTests {
70 Convey("Given a "+tt.testDescription, t, func() {
71 actualNatName, actualErr := LangNativeName(tt.code)
72 So(actualNatName, ShouldEqual, tt.expectedNat)
74 So(actualErr, ShouldBeNil)
76 So(actualErr, ShouldNotBeNil)
82 func BenchmarkLangCodeInfo(b *testing.B) {
83 for n := 0; n < b.N; n++ {
84 _, _, err := LangCodeInfo("zu")
91 func BenchmarkIsValidLanguageCode(b *testing.B) {
92 for n := 0; n < b.N; n++ {
93 isValid := IsValidLanguageCode("zu")
95 b.Error("invalid language code")
100 func BenchmarkLangEnglishName(b *testing.B) {
101 for n := 0; n < b.N; n++ {
102 _, err := LangEnglishName("zu")
109 func BenchmarkLangNativeName(b *testing.B) {
110 for n := 0; n < b.N; n++ {
111 _, err := LangEnglishName("zu")