Add English translation for "unique" validation.

pull/419/head
Sam Wang 6 years ago
parent 1fa3c8d633
commit df107f0184
  1. 5
      translations/en/en.go
  2. 230
      translations/en/en_test.go

@ -1293,6 +1293,11 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation: "{0} must contain a valid MAC address", translation: "{0} must contain a valid MAC address",
override: false, override: false,
}, },
{
tag: "unique",
translation: "{0} must contain unique values",
override: false,
},
{ {
tag: "iscolor", tag: "iscolor",
translation: "{0} must be a valid color", translation: "{0} must be a valid color",

@ -32,112 +32,115 @@ func TestTranslations(t *testing.T) {
type Test struct { type Test struct {
Inner Inner Inner Inner
RequiredString string `validate:"required"` RequiredString string `validate:"required"`
RequiredNumber int `validate:"required"` RequiredNumber int `validate:"required"`
RequiredMultiple []string `validate:"required"` RequiredMultiple []string `validate:"required"`
LenString string `validate:"len=1"` LenString string `validate:"len=1"`
LenNumber float64 `validate:"len=1113.00"` LenNumber float64 `validate:"len=1113.00"`
LenMultiple []string `validate:"len=7"` LenMultiple []string `validate:"len=7"`
MinString string `validate:"min=1"` MinString string `validate:"min=1"`
MinNumber float64 `validate:"min=1113.00"` MinNumber float64 `validate:"min=1113.00"`
MinMultiple []string `validate:"min=7"` MinMultiple []string `validate:"min=7"`
MaxString string `validate:"max=3"` MaxString string `validate:"max=3"`
MaxNumber float64 `validate:"max=1113.00"` MaxNumber float64 `validate:"max=1113.00"`
MaxMultiple []string `validate:"max=7"` MaxMultiple []string `validate:"max=7"`
EqString string `validate:"eq=3"` EqString string `validate:"eq=3"`
EqNumber float64 `validate:"eq=2.33"` EqNumber float64 `validate:"eq=2.33"`
EqMultiple []string `validate:"eq=7"` EqMultiple []string `validate:"eq=7"`
NeString string `validate:"ne="` NeString string `validate:"ne="`
NeNumber float64 `validate:"ne=0.00"` NeNumber float64 `validate:"ne=0.00"`
NeMultiple []string `validate:"ne=0"` NeMultiple []string `validate:"ne=0"`
LtString string `validate:"lt=3"` LtString string `validate:"lt=3"`
LtNumber float64 `validate:"lt=5.56"` LtNumber float64 `validate:"lt=5.56"`
LtMultiple []string `validate:"lt=2"` LtMultiple []string `validate:"lt=2"`
LtTime time.Time `validate:"lt"` LtTime time.Time `validate:"lt"`
LteString string `validate:"lte=3"` LteString string `validate:"lte=3"`
LteNumber float64 `validate:"lte=5.56"` LteNumber float64 `validate:"lte=5.56"`
LteMultiple []string `validate:"lte=2"` LteMultiple []string `validate:"lte=2"`
LteTime time.Time `validate:"lte"` LteTime time.Time `validate:"lte"`
GtString string `validate:"gt=3"` GtString string `validate:"gt=3"`
GtNumber float64 `validate:"gt=5.56"` GtNumber float64 `validate:"gt=5.56"`
GtMultiple []string `validate:"gt=2"` GtMultiple []string `validate:"gt=2"`
GtTime time.Time `validate:"gt"` GtTime time.Time `validate:"gt"`
GteString string `validate:"gte=3"` GteString string `validate:"gte=3"`
GteNumber float64 `validate:"gte=5.56"` GteNumber float64 `validate:"gte=5.56"`
GteMultiple []string `validate:"gte=2"` GteMultiple []string `validate:"gte=2"`
GteTime time.Time `validate:"gte"` GteTime time.Time `validate:"gte"`
EqFieldString string `validate:"eqfield=MaxString"` EqFieldString string `validate:"eqfield=MaxString"`
EqCSFieldString string `validate:"eqcsfield=Inner.EqCSFieldString"` EqCSFieldString string `validate:"eqcsfield=Inner.EqCSFieldString"`
NeCSFieldString string `validate:"necsfield=Inner.NeCSFieldString"` NeCSFieldString string `validate:"necsfield=Inner.NeCSFieldString"`
GtCSFieldString string `validate:"gtcsfield=Inner.GtCSFieldString"` GtCSFieldString string `validate:"gtcsfield=Inner.GtCSFieldString"`
GteCSFieldString string `validate:"gtecsfield=Inner.GteCSFieldString"` GteCSFieldString string `validate:"gtecsfield=Inner.GteCSFieldString"`
LtCSFieldString string `validate:"ltcsfield=Inner.LtCSFieldString"` LtCSFieldString string `validate:"ltcsfield=Inner.LtCSFieldString"`
LteCSFieldString string `validate:"ltecsfield=Inner.LteCSFieldString"` LteCSFieldString string `validate:"ltecsfield=Inner.LteCSFieldString"`
NeFieldString string `validate:"nefield=EqFieldString"` NeFieldString string `validate:"nefield=EqFieldString"`
GtFieldString string `validate:"gtfield=MaxString"` GtFieldString string `validate:"gtfield=MaxString"`
GteFieldString string `validate:"gtefield=MaxString"` GteFieldString string `validate:"gtefield=MaxString"`
LtFieldString string `validate:"ltfield=MaxString"` LtFieldString string `validate:"ltfield=MaxString"`
LteFieldString string `validate:"ltefield=MaxString"` LteFieldString string `validate:"ltefield=MaxString"`
AlphaString string `validate:"alpha"` AlphaString string `validate:"alpha"`
AlphanumString string `validate:"alphanum"` AlphanumString string `validate:"alphanum"`
NumericString string `validate:"numeric"` NumericString string `validate:"numeric"`
NumberString string `validate:"number"` NumberString string `validate:"number"`
HexadecimalString string `validate:"hexadecimal"` HexadecimalString string `validate:"hexadecimal"`
HexColorString string `validate:"hexcolor"` HexColorString string `validate:"hexcolor"`
RGBColorString string `validate:"rgb"` RGBColorString string `validate:"rgb"`
RGBAColorString string `validate:"rgba"` RGBAColorString string `validate:"rgba"`
HSLColorString string `validate:"hsl"` HSLColorString string `validate:"hsl"`
HSLAColorString string `validate:"hsla"` HSLAColorString string `validate:"hsla"`
Email string `validate:"email"` Email string `validate:"email"`
URL string `validate:"url"` URL string `validate:"url"`
URI string `validate:"uri"` URI string `validate:"uri"`
Base64 string `validate:"base64"` Base64 string `validate:"base64"`
Contains string `validate:"contains=purpose"` Contains string `validate:"contains=purpose"`
ContainsAny string `validate:"containsany=!@#$"` ContainsAny string `validate:"containsany=!@#$"`
Excludes string `validate:"excludes=text"` Excludes string `validate:"excludes=text"`
ExcludesAll string `validate:"excludesall=!@#$"` ExcludesAll string `validate:"excludesall=!@#$"`
ExcludesRune string `validate:"excludesrune=☻"` ExcludesRune string `validate:"excludesrune=☻"`
ISBN string `validate:"isbn"` ISBN string `validate:"isbn"`
ISBN10 string `validate:"isbn10"` ISBN10 string `validate:"isbn10"`
ISBN13 string `validate:"isbn13"` ISBN13 string `validate:"isbn13"`
UUID string `validate:"uuid"` UUID string `validate:"uuid"`
UUID3 string `validate:"uuid3"` UUID3 string `validate:"uuid3"`
UUID4 string `validate:"uuid4"` UUID4 string `validate:"uuid4"`
UUID5 string `validate:"uuid5"` UUID5 string `validate:"uuid5"`
ASCII string `validate:"ascii"` ASCII string `validate:"ascii"`
PrintableASCII string `validate:"printascii"` PrintableASCII string `validate:"printascii"`
MultiByte string `validate:"multibyte"` MultiByte string `validate:"multibyte"`
DataURI string `validate:"datauri"` DataURI string `validate:"datauri"`
Latitude string `validate:"latitude"` Latitude string `validate:"latitude"`
Longitude string `validate:"longitude"` Longitude string `validate:"longitude"`
SSN string `validate:"ssn"` SSN string `validate:"ssn"`
IP string `validate:"ip"` IP string `validate:"ip"`
IPv4 string `validate:"ipv4"` IPv4 string `validate:"ipv4"`
IPv6 string `validate:"ipv6"` IPv6 string `validate:"ipv6"`
CIDR string `validate:"cidr"` CIDR string `validate:"cidr"`
CIDRv4 string `validate:"cidrv4"` CIDRv4 string `validate:"cidrv4"`
CIDRv6 string `validate:"cidrv6"` CIDRv6 string `validate:"cidrv6"`
TCPAddr string `validate:"tcp_addr"` TCPAddr string `validate:"tcp_addr"`
TCPAddrv4 string `validate:"tcp4_addr"` TCPAddrv4 string `validate:"tcp4_addr"`
TCPAddrv6 string `validate:"tcp6_addr"` TCPAddrv6 string `validate:"tcp6_addr"`
UDPAddr string `validate:"udp_addr"` UDPAddr string `validate:"udp_addr"`
UDPAddrv4 string `validate:"udp4_addr"` UDPAddrv4 string `validate:"udp4_addr"`
UDPAddrv6 string `validate:"udp6_addr"` UDPAddrv6 string `validate:"udp6_addr"`
IPAddr string `validate:"ip_addr"` IPAddr string `validate:"ip_addr"`
IPAddrv4 string `validate:"ip4_addr"` IPAddrv4 string `validate:"ip4_addr"`
IPAddrv6 string `validate:"ip6_addr"` IPAddrv6 string `validate:"ip6_addr"`
UinxAddr string `validate:"unix_addr"` // can't fail from within Go's net package currently, but maybe in the future UinxAddr string `validate:"unix_addr"` // can't fail from within Go's net package currently, but maybe in the future
MAC string `validate:"mac"` MAC string `validate:"mac"`
IsColor string `validate:"iscolor"` IsColor string `validate:"iscolor"`
StrPtrMinLen *string `validate:"min=10"` StrPtrMinLen *string `validate:"min=10"`
StrPtrMaxLen *string `validate:"max=1"` StrPtrMaxLen *string `validate:"max=1"`
StrPtrLen *string `validate:"len=2"` StrPtrLen *string `validate:"len=2"`
StrPtrLt *string `validate:"lt=1"` StrPtrLt *string `validate:"lt=1"`
StrPtrLte *string `validate:"lte=1"` StrPtrLte *string `validate:"lte=1"`
StrPtrGt *string `validate:"gt=10"` StrPtrGt *string `validate:"gt=10"`
StrPtrGte *string `validate:"gte=10"` StrPtrGte *string `validate:"gte=10"`
OneOfString string `validate:"oneof=red green"` OneOfString string `validate:"oneof=red green"`
OneOfInt int `validate:"oneof=5 63"` OneOfInt int `validate:"oneof=5 63"`
UniqueSlice []string `validate:"unique"`
UniqueArray [3]string `validate:"unique"`
UniqueMap map[string]string `validate:"unique"`
} }
var test Test var test Test
@ -184,6 +187,9 @@ func TestTranslations(t *testing.T) {
test.StrPtrMaxLen = &s test.StrPtrMaxLen = &s
test.StrPtrLen = &s test.StrPtrLen = &s
test.UniqueSlice = []string{"1234", "1234"}
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
err = validate.Struct(test) err = validate.Struct(test)
NotEqual(t, err, nil) NotEqual(t, err, nil)
@ -614,6 +620,18 @@ func TestTranslations(t *testing.T) {
ns: "Test.OneOfInt", ns: "Test.OneOfInt",
expected: "OneOfInt must be one of [5 63]", expected: "OneOfInt must be one of [5 63]",
}, },
{
ns: "Test.UniqueSlice",
expected: "UniqueSlice must contain unique values",
},
{
ns: "Test.UniqueArray",
expected: "UniqueArray must contain unique values",
},
{
ns: "Test.UniqueMap",
expected: "UniqueMap must contain unique values",
},
} }
for _, tt := range tests { for _, tt := range tests {

Loading…
Cancel
Save