@@ -42,6 +42,11 @@ func TestBasicTranslation(t *testing.T) {
4242 trans : "Welcome {0}" ,
4343 expected : nil ,
4444 },
45+ {
46+ key : - 1 ,
47+ trans : "Welcome {0}" ,
48+ expected : nil ,
49+ },
4550 {
4651 key : "test_trans2" ,
4752 trans : "{0} to the {1}." ,
@@ -60,7 +65,13 @@ func TestBasicTranslation(t *testing.T) {
6065 {
6166 key : "test_trans" ,
6267 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}" },
6475 expectedError : true ,
6576 },
6677 {
@@ -75,8 +86,12 @@ func TestBasicTranslation(t *testing.T) {
7586
7687 err := en .Add (tt .key , tt .trans , tt .override )
7788 if err != tt .expected {
78- if ! tt .expectedError && err . Error () != tt . expected . Error () {
89+ if ! tt .expectedError {
7990 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+ }
8095 }
8196 }
8297 }
@@ -704,6 +719,32 @@ func TestVerifyTranslations(t *testing.T) {
704719 }
705720}
706721
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+
707748func TestGetFallback (t * testing.T ) {
708749
709750 // dutch
0 commit comments