@ -11126,154 +11126,154 @@ func TestBCP47LanguageTagValidation(t *testing.T) {
}
}
func TestBicIsoFormatValidation ( t * testing . T ) {
func TestBicIsoFormatValidation ( t * testing . T ) {
tests := [ ] struct {
tests := [ ] struct {
value string ` validate:"bic" `
value string ` validate:"bic" `
tag string
tag string
expected bool
expected bool
} {
} {
{ "SBICKEN1345" , "bic" , true } ,
{ "SBICKEN1345" , "bic" , true } ,
{ "SBICKEN1" , "bic" , true } ,
{ "SBICKEN1" , "bic" , true } ,
{ "SBICKENY" , "bic" , true } ,
{ "SBICKENY" , "bic" , true } ,
{ "SBICKEN1YYP" , "bic" , true } ,
{ "SBICKEN1YYP" , "bic" , true } ,
{ "SBIC23NXXX" , "bic" , false } ,
{ "SBIC23NXXX" , "bic" , false } ,
{ "S23CKENXXXX" , "bic" , false } ,
{ "S23CKENXXXX" , "bic" , false } ,
{ "SBICKENXX" , "bic" , false } ,
{ "SBICKENXX" , "bic" , false } ,
{ "SBICKENXX9" , "bic" , false } ,
{ "SBICKENXX9" , "bic" , false } ,
{ "SBICKEN13458" , "bic" , false } ,
{ "SBICKEN13458" , "bic" , false } ,
{ "SBICKEN" , "bic" , false } ,
{ "SBICKEN" , "bic" , false } ,
}
}
validate := New ( )
validate := New ( )
for i , test := range tests {
for i , test := range tests {
errs := validate . Var ( test . value , test . tag )
errs := validate . Var ( test . value , test . tag )
if test . expected {
if test . expected {
if ! IsEqual ( errs , nil ) {
if ! IsEqual ( errs , nil ) {
t . Fatalf ( "Index: %d bic failed Error: %s" , i , errs )
t . Fatalf ( "Index: %d bic failed Error: %s" , i , errs )
}
}
} else {
} else {
if IsEqual ( errs , nil ) {
if IsEqual ( errs , nil ) {
t . Fatalf ( "Index: %d bic failed Error: %s" , i , errs )
t . Fatalf ( "Index: %d bic failed Error: %s" , i , errs )
} else {
} else {
val := getError ( errs , "" , "" )
val := getError ( errs , "" , "" )
if val . Tag ( ) != "bic" {
if val . Tag ( ) != "bic" {
t . Fatalf ( "Index: %d bic failed Error: %s" , i , errs )
t . Fatalf ( "Index: %d bic failed Error: %s" , i , errs )
}
}
}
}
}
}
}
}
}
}
func TestPostCodeByIso3166Alpha2 ( t * testing . T ) {
func TestPostCodeByIso3166Alpha2 ( t * testing . T ) {
tests := map [ string ] [ ] struct {
tests := map [ string ] [ ] struct {
value string
value string
expected bool
expected bool
} {
} {
"VN" : {
"VN" : {
{ "ABC" , false } ,
{ "ABC" , false } ,
{ "700000" , true } ,
{ "700000" , true } ,
{ "A1" , false } ,
{ "A1" , false } ,
} ,
} ,
"GB" : {
"GB" : {
{ "EC1A 1BB" , true } ,
{ "EC1A 1BB" , true } ,
{ "CF10 1B1H" , false } ,
{ "CF10 1B1H" , false } ,
} ,
} ,
"VI" : {
"VI" : {
{ "00803" , true } ,
{ "00803" , true } ,
{ "1234567" , false } ,
{ "1234567" , false } ,
} ,
} ,
"LC" : { // not support regexp for post code
"LC" : { // not support regexp for post code
{ "123456" , false } ,
{ "123456" , false } ,
} ,
} ,
"XX" : { // not support country
"XX" : { // not support country
{ "123456" , false } ,
{ "123456" , false } ,
} ,
} ,
}
}
validate := New ( )
validate := New ( )
for cc , ccTests := range tests {
for cc , ccTests := range tests {
for i , test := range ccTests {
for i , test := range ccTests {
errs := validate . Var ( test . value , fmt . Sprintf ( "postcode_iso3166_alpha2=%s" , cc ) )
errs := validate . Var ( test . value , fmt . Sprintf ( "postcode_iso3166_alpha2=%s" , cc ) )
if test . expected {
if test . expected {
if ! IsEqual ( errs , nil ) {
if ! IsEqual ( errs , nil ) {
t . Fatalf ( "Index: %d postcode_iso3166_alpha2=%s failed Error: %s" , i , cc , errs )
t . Fatalf ( "Index: %d postcode_iso3166_alpha2=%s failed Error: %s" , i , cc , errs )
}
}
} else {
} else {
if IsEqual ( errs , nil ) {
if IsEqual ( errs , nil ) {
t . Fatalf ( "Index: %d postcode_iso3166_alpha2=%s failed Error: %s" , i , cc , errs )
t . Fatalf ( "Index: %d postcode_iso3166_alpha2=%s failed Error: %s" , i , cc , errs )
}
}
}
}
}
}
}
}
}
}
func TestPostCodeByIso3166Alpha2Field ( t * testing . T ) {
func TestPostCodeByIso3166Alpha2Field ( t * testing . T ) {
tests := [ ] struct {
tests := [ ] struct {
Value string ` validate:"postcode_iso3166_alpha2_field=CountryCode" `
Value string ` validate:"postcode_iso3166_alpha2_field=CountryCode" `
CountryCode interface { }
CountryCode interface { }
expected bool
expected bool
} {
} {
{ "ABC" , "VN" , false } ,
{ "ABC" , "VN" , false } ,
{ "700000" , "VN" , true } ,
{ "700000" , "VN" , true } ,
{ "A1" , "VN" , false } ,
{ "A1" , "VN" , false } ,
{ "EC1A 1BB" , "GB" , true } ,
{ "EC1A 1BB" , "GB" , true } ,
{ "CF10 1B1H" , "GB" , false } ,
{ "CF10 1B1H" , "GB" , false } ,
{ "00803" , "VI" , true } ,
{ "00803" , "VI" , true } ,
{ "1234567" , "VI" , false } ,
{ "1234567" , "VI" , false } ,
{ "123456" , "LC" , false } , // not support regexp for post code
{ "123456" , "LC" , false } , // not support regexp for post code
{ "123456" , "XX" , false } , // not support country
{ "123456" , "XX" , false } , // not support country
}
}
validate := New ( )
validate := New ( )
for i , test := range tests {
for i , test := range tests {
errs := validate . Struct ( test )
errs := validate . Struct ( test )
if test . expected {
if test . expected {
if ! IsEqual ( errs , nil ) {
if ! IsEqual ( errs , nil ) {
t . Fatalf ( "Index: %d postcode_iso3166_alpha2_field=CountryCode failed Error: %s" , i , errs )
t . Fatalf ( "Index: %d postcode_iso3166_alpha2_field=CountryCode failed Error: %s" , i , errs )
}
}
} else {
} else {
if IsEqual ( errs , nil ) {
if IsEqual ( errs , nil ) {
t . Fatalf ( "Index: %d postcode_iso3166_alpha2_field=CountryCode failed Error: %s" , i , errs )
t . Fatalf ( "Index: %d postcode_iso3166_alpha2_field=CountryCode failed Error: %s" , i , errs )
}
}
}
}
}
}
}
}
func TestPostCodeByIso3166Alpha2Field_WrongField ( t * testing . T ) {
func TestPostCodeByIso3166Alpha2Field_WrongField ( t * testing . T ) {
type test struct {
type test struct {
Value string ` validate:"postcode_iso3166_alpha2_field=CountryCode" `
Value string ` validate:"postcode_iso3166_alpha2_field=CountryCode" `
CountryCode1 interface { }
CountryCode1 interface { }
expected bool
expected bool
}
}
errs := New ( ) . Struct ( test { "ABC" , "VN" , false } )
errs := New ( ) . Struct ( test { "ABC" , "VN" , false } )
assert . NotEqual ( t , nil , errs )
assert . NotEqual ( t , nil , errs )
}
}
func TestPostCodeByIso3166Alpha2Field_MissingParam ( t * testing . T ) {
func TestPostCodeByIso3166Alpha2Field_MissingParam ( t * testing . T ) {
type test struct {
type test struct {
Value string ` validate:"postcode_iso3166_alpha2_field=" `
Value string ` validate:"postcode_iso3166_alpha2_field=" `
CountryCode1 interface { }
CountryCode1 interface { }
expected bool
expected bool
}
}
errs := New ( ) . Struct ( test { "ABC" , "VN" , false } )
errs := New ( ) . Struct ( test { "ABC" , "VN" , false } )
assert . NotEqual ( t , nil , errs )
assert . NotEqual ( t , nil , errs )
}
}
func TestPostCodeByIso3166Alpha2Field_InvalidKind ( t * testing . T ) {
func TestPostCodeByIso3166Alpha2Field_InvalidKind ( t * testing . T ) {
type test struct {
type test struct {
Value string ` validate:"postcode_iso3166_alpha2_field=CountryCode" `
Value string ` validate:"postcode_iso3166_alpha2_field=CountryCode" `
CountryCode interface { }
CountryCode interface { }
expected bool
expected bool
}
}
defer func ( ) { recover ( ) } ( )
defer func ( ) { _ = recover ( ) } ( )
_ = New ( ) . Struct ( test { "ABC" , 123 , false } )
_ = New ( ) . Struct ( test { "ABC" , 123 , false } )
t . Errorf ( "Didn't panic as expected" )
t . Errorf ( "Didn't panic as expected" )
}
}