@@ -42,6 +42,11 @@ func TestBasicTranslation(t *testing.T) {
42
42
trans : "Welcome {0}" ,
43
43
expected : nil ,
44
44
},
45
+ {
46
+ key : - 1 ,
47
+ trans : "Welcome {0}" ,
48
+ expected : nil ,
49
+ },
45
50
{
46
51
key : "test_trans2" ,
47
52
trans : "{0} to the {1}." ,
@@ -60,7 +65,13 @@ func TestBasicTranslation(t *testing.T) {
60
65
{
61
66
key : "test_trans" ,
62
67
trans : "{0}{1}" ,
63
- expected : & ErrConflictingTranslation {key : "bad_trans" , text : "{0}{1}" },
68
+ expected : & ErrConflictingTranslation {key : "test_trans" , text : "{0}{1}" },
69
+ expectedError : true ,
70
+ },
71
+ {
72
+ key : - 1 ,
73
+ trans : "{0}{1}" ,
74
+ expected : & ErrConflictingTranslation {key : - 1 , text : "{0}{1}" },
64
75
expectedError : true ,
65
76
},
66
77
{
@@ -75,8 +86,12 @@ func TestBasicTranslation(t *testing.T) {
75
86
76
87
err := en .Add (tt .key , tt .trans , tt .override )
77
88
if err != tt .expected {
78
- if ! tt .expectedError && err . Error () != tt . expected . Error () {
89
+ if ! tt .expectedError {
79
90
t .Errorf ("Expected '%s' Got '%s'" , tt .expected , err )
91
+ } else {
92
+ if err .Error () != tt .expected .Error () {
93
+ t .Errorf ("Expected '%s' Got '%s'" , tt .expected .Error (), err .Error ())
94
+ }
80
95
}
81
96
}
82
97
}
@@ -704,6 +719,32 @@ func TestVerifyTranslations(t *testing.T) {
704
719
}
705
720
}
706
721
722
+ func TestVerifyTranslationsWithNonStringKeys (t * testing.T ) {
723
+
724
+ n := nl .New ()
725
+ // dutch
726
+ uni := New (n , n )
727
+
728
+ loc , _ := uni .GetTranslator ("nl" )
729
+ if loc .Locale () != "nl" {
730
+ t .Errorf ("Expected '%s' Got '%s'" , "nl" , loc .Locale ())
731
+ }
732
+
733
+ // cardinal checks
734
+
735
+ err := loc .AddCardinal (- 1 , "je {0} dag hebben verlaten" , locales .PluralRuleOne , false )
736
+ if err != nil {
737
+ t .Fatalf ("Expected '<nil>' Got '%s'" , err )
738
+ }
739
+
740
+ // fail cardinal rules
741
+ expected := & ErrMissingPluralTranslation {translationType : "plural" , rule : locales .PluralRuleOther , key : - 1 }
742
+ err = loc .VerifyTranslations ()
743
+ if err == nil || err .Error () != expected .Error () {
744
+ t .Errorf ("Expected '%s' Got '%s'" , expected , err )
745
+ }
746
+ }
747
+
707
748
func TestGetFallback (t * testing.T ) {
708
749
709
750
// dutch
0 commit comments