...

Source file src/github.com/go-playground/validator/v10/translations/zh_tw/zh_tw_test.go

Documentation: github.com/go-playground/validator/v10/translations/zh_tw

     1  package zh_tw
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	. "github.com/go-playground/assert/v2"
     8  	zhongwen "github.com/go-playground/locales/zh_Hant_TW"
     9  	ut "github.com/go-playground/universal-translator"
    10  	"github.com/go-playground/validator/v10"
    11  )
    12  
    13  func TestTranslations(t *testing.T) {
    14  
    15  	zh := zhongwen.New()
    16  	uni := ut.New(zh, zh)
    17  	trans, _ := uni.GetTranslator("zh")
    18  
    19  	validate := validator.New()
    20  
    21  	err := RegisterDefaultTranslations(validate, trans)
    22  	Equal(t, err, nil)
    23  
    24  	type Inner struct {
    25  		EqCSFieldString  string
    26  		NeCSFieldString  string
    27  		GtCSFieldString  string
    28  		GteCSFieldString string
    29  		LtCSFieldString  string
    30  		LteCSFieldString string
    31  		RequiredIf         string
    32  		RequiredUnless     string
    33  		RequiredWith       string
    34  		RequiredWithAll    string
    35  		RequiredWithout    string
    36  		RequiredWithoutAll string
    37  		ExcludedIf         string
    38  		ExcludedUnless     string
    39  		ExcludedWith       string
    40  		ExcludedWithAll    string
    41  		ExcludedWithout    string
    42  		ExcludedWithoutAll string
    43  	}
    44  
    45  	type Test struct {
    46  		Inner             Inner
    47  		RequiredString    string    `validate:"required"`
    48  		RequiredNumber    int       `validate:"required"`
    49  		RequiredMultiple  []string  `validate:"required"`
    50  		RequiredIf             string    `validate:"required_if=Inner.RequiredIf abcd"`
    51  		RequiredUnless        string    `validate:"required_unless=Inner.RequiredUnless abcd"`
    52  		RequiredWith          string    `validate:"required_with=Inner.RequiredWith"`
    53  		RequiredWithAll       string    `validate:"required_with_all=Inner.RequiredWith Inner.RequiredWithAll"`
    54  		RequiredWithout       string    `validate:"required_without=Inner.RequiredWithout"`
    55  		RequiredWithoutAll    string    `validate:"required_without_all=Inner.RequiredWithout Inner.RequiredWithoutAll"`
    56  		ExcludedIf            string    `validate:"excluded_if=Inner.ExcludedIf abcd"`
    57  		ExcludedUnless        string    `validate:"excluded_unless=Inner.ExcludedUnless abcd"`
    58  		ExcludedWith          string    `validate:"excluded_with=Inner.ExcludedWith"`
    59  		ExcludedWithout       string    `validate:"excluded_with_all=Inner.ExcludedWithAll"`
    60  		ExcludedWithAll       string    `validate:"excluded_without=Inner.ExcludedWithout"`
    61  		ExcludedWithoutAll    string    `validate:"excluded_without_all=Inner.ExcludedWithoutAll"`
    62  		IsDefault             string    `validate:"isdefault"`
    63  		LenString         string    `validate:"len=1"`
    64  		LenNumber         float64   `validate:"len=1113.00"`
    65  		LenMultiple       []string  `validate:"len=7"`
    66  		MinString         string    `validate:"min=1"`
    67  		MinNumber         float64   `validate:"min=1113.00"`
    68  		MinMultiple       []string  `validate:"min=7"`
    69  		MaxString         string    `validate:"max=3"`
    70  		MaxNumber         float64   `validate:"max=1113.00"`
    71  		MaxMultiple       []string  `validate:"max=7"`
    72  		EqString          string    `validate:"eq=3"`
    73  		EqNumber          float64   `validate:"eq=2.33"`
    74  		EqMultiple        []string  `validate:"eq=7"`
    75  		NeString          string    `validate:"ne="`
    76  		NeNumber          float64   `validate:"ne=0.00"`
    77  		NeMultiple        []string  `validate:"ne=0"`
    78  		LtString          string    `validate:"lt=3"`
    79  		LtNumber          float64   `validate:"lt=5.56"`
    80  		LtMultiple        []string  `validate:"lt=2"`
    81  		LtTime            time.Time `validate:"lt"`
    82  		LteString         string    `validate:"lte=3"`
    83  		LteNumber         float64   `validate:"lte=5.56"`
    84  		LteMultiple       []string  `validate:"lte=2"`
    85  		LteTime           time.Time `validate:"lte"`
    86  		GtString          string    `validate:"gt=3"`
    87  		GtNumber          float64   `validate:"gt=5.56"`
    88  		GtMultiple        []string  `validate:"gt=2"`
    89  		GtTime            time.Time `validate:"gt"`
    90  		GteString         string    `validate:"gte=3"`
    91  		GteNumber         float64   `validate:"gte=5.56"`
    92  		GteMultiple       []string  `validate:"gte=2"`
    93  		GteTime           time.Time `validate:"gte"`
    94  		EqFieldString     string    `validate:"eqfield=MaxString"`
    95  		EqCSFieldString   string    `validate:"eqcsfield=Inner.EqCSFieldString"`
    96  		NeCSFieldString   string    `validate:"necsfield=Inner.NeCSFieldString"`
    97  		GtCSFieldString   string    `validate:"gtcsfield=Inner.GtCSFieldString"`
    98  		GteCSFieldString  string    `validate:"gtecsfield=Inner.GteCSFieldString"`
    99  		LtCSFieldString   string    `validate:"ltcsfield=Inner.LtCSFieldString"`
   100  		LteCSFieldString  string    `validate:"ltecsfield=Inner.LteCSFieldString"`
   101  		NeFieldString     string    `validate:"nefield=EqFieldString"`
   102  		GtFieldString     string    `validate:"gtfield=MaxString"`
   103  		GteFieldString    string    `validate:"gtefield=MaxString"`
   104  		LtFieldString     string    `validate:"ltfield=MaxString"`
   105  		LteFieldString    string    `validate:"ltefield=MaxString"`
   106  		AlphaString       string    `validate:"alpha"`
   107  		AlphanumString    string    `validate:"alphanum"`
   108  		NumericString     string    `validate:"numeric"`
   109  		NumberString      string    `validate:"number"`
   110  		HexadecimalString string    `validate:"hexadecimal"`
   111  		HexColorString    string    `validate:"hexcolor"`
   112  		RGBColorString    string    `validate:"rgb"`
   113  		RGBAColorString   string    `validate:"rgba"`
   114  		HSLColorString    string    `validate:"hsl"`
   115  		HSLAColorString   string    `validate:"hsla"`
   116  		Email             string    `validate:"email"`
   117  		URL               string    `validate:"url"`
   118  		URI               string    `validate:"uri"`
   119  		Base64            string    `validate:"base64"`
   120  		Contains          string    `validate:"contains=purpose"`
   121  		ContainsAny       string    `validate:"containsany=!@#$"`
   122  		Excludes          string    `validate:"excludes=text"`
   123  		ExcludesAll       string    `validate:"excludesall=!@#$"`
   124  		ExcludesRune      string    `validate:"excludesrune=☻"`
   125  		ISBN              string    `validate:"isbn"`
   126  		ISBN10            string    `validate:"isbn10"`
   127  		ISBN13            string    `validate:"isbn13"`
   128  		ISSN              string    `validate:"issn"`
   129  		UUID              string    `validate:"uuid"`
   130  		UUID3             string    `validate:"uuid3"`
   131  		UUID4             string    `validate:"uuid4"`
   132  		UUID5             string    `validate:"uuid5"`
   133  		ULID              string    `validate:"ulid"`
   134  		ASCII             string    `validate:"ascii"`
   135  		PrintableASCII    string    `validate:"printascii"`
   136  		MultiByte         string    `validate:"multibyte"`
   137  		DataURI           string    `validate:"datauri"`
   138  		Latitude          string    `validate:"latitude"`
   139  		Longitude         string    `validate:"longitude"`
   140  		SSN               string    `validate:"ssn"`
   141  		IP                string    `validate:"ip"`
   142  		IPv4              string    `validate:"ipv4"`
   143  		IPv6              string    `validate:"ipv6"`
   144  		CIDR              string    `validate:"cidr"`
   145  		CIDRv4            string    `validate:"cidrv4"`
   146  		CIDRv6            string    `validate:"cidrv6"`
   147  		TCPAddr           string    `validate:"tcp_addr"`
   148  		TCPAddrv4         string    `validate:"tcp4_addr"`
   149  		TCPAddrv6         string    `validate:"tcp6_addr"`
   150  		UDPAddr           string    `validate:"udp_addr"`
   151  		UDPAddrv4         string    `validate:"udp4_addr"`
   152  		UDPAddrv6         string    `validate:"udp6_addr"`
   153  		IPAddr            string    `validate:"ip_addr"`
   154  		IPAddrv4          string    `validate:"ip4_addr"`
   155  		IPAddrv6          string    `validate:"ip6_addr"`
   156  		UinxAddr          string    `validate:"unix_addr"` // can't fail from within Go's net package currently, but maybe in the future
   157  		MAC               string    `validate:"mac"`
   158  		IsColor           string    `validate:"iscolor"`
   159  		StrPtrMinLen      *string   `validate:"min=10"`
   160  		StrPtrMaxLen      *string   `validate:"max=1"`
   161  		StrPtrLen         *string   `validate:"len=2"`
   162  		StrPtrLt          *string   `validate:"lt=1"`
   163  		StrPtrLte         *string   `validate:"lte=1"`
   164  		StrPtrGt          *string   `validate:"gt=10"`
   165  		StrPtrGte         *string   `validate:"gte=10"`
   166  		OneOfString       string    `validate:"oneof=red green"`
   167  		OneOfInt          int       `validate:"oneof=5 63"`
   168  		Datetime          string    `validate:"datetime=2006-01-02"`
   169  		Image			  string			`validate:"image"`
   170  	}
   171  
   172  	var test Test
   173  
   174  	test.Inner.EqCSFieldString = "1234"
   175  	test.Inner.GtCSFieldString = "1234"
   176  	test.Inner.GteCSFieldString = "1234"
   177  	test.Inner.RequiredIf = "abcd"
   178  	test.Inner.RequiredUnless = "1234"
   179  	test.Inner.RequiredWith = "1234"
   180  	test.Inner.RequiredWithAll = "1234"
   181  	test.Inner.ExcludedIf = "abcd"
   182  	test.Inner.ExcludedUnless = "1234"
   183  	test.Inner.ExcludedWith = "1234"
   184  	test.Inner.ExcludedWithAll = "1234"
   185  
   186  	test.ExcludedIf = "1234"
   187  	test.ExcludedUnless = "1234"
   188  	test.ExcludedWith = "1234"
   189  	test.ExcludedWithAll = "1234"
   190  	test.ExcludedWithout = "1234"
   191  	test.ExcludedWithoutAll = "1234"
   192  
   193  	test.MaxString = "1234"
   194  	test.MaxNumber = 2000
   195  	test.MaxMultiple = make([]string, 9)
   196  
   197  	test.LtString = "1234"
   198  	test.LtNumber = 6
   199  	test.LtMultiple = make([]string, 3)
   200  	test.LtTime = time.Now().Add(time.Hour * 24)
   201  
   202  	test.LteString = "1234"
   203  	test.LteNumber = 6
   204  	test.LteMultiple = make([]string, 3)
   205  	test.LteTime = time.Now().Add(time.Hour * 24)
   206  
   207  	test.LtFieldString = "12345"
   208  	test.LteFieldString = "12345"
   209  
   210  	test.LtCSFieldString = "1234"
   211  	test.LteCSFieldString = "1234"
   212  
   213  	test.AlphaString = "abc3"
   214  	test.AlphanumString = "abc3!"
   215  	test.NumericString = "12E.00"
   216  	test.NumberString = "12E"
   217  
   218  	test.Excludes = "this is some test text"
   219  	test.ExcludesAll = "This is Great!"
   220  	test.ExcludesRune = "Love it ☻"
   221  
   222  	test.ASCII = "カタカナ"
   223  	test.PrintableASCII = "カタカナ"
   224  
   225  	test.MultiByte = "1234feerf"
   226  
   227  	s := "toolong"
   228  	test.StrPtrMaxLen = &s
   229  	test.StrPtrLen = &s
   230  
   231  	test.Datetime = "2008-Feb-01"
   232  
   233  	err = validate.Struct(test)
   234  	NotEqual(t, err, nil)
   235  
   236  	errs, ok := err.(validator.ValidationErrors)
   237  	Equal(t, ok, true)
   238  
   239  	tests := []struct {
   240  		ns       string
   241  		expected string
   242  	}{
   243  		{
   244  			ns:       "Test.IsColor",
   245  			expected: "IsColor必須是一個有效的顏色",
   246  		},
   247  		{
   248  			ns:       "Test.MAC",
   249  			expected: "MAC必須是一個有效的MAC地址",
   250  		},
   251  		{
   252  			ns:       "Test.IPAddr",
   253  			expected: "IPAddr必須是一個有效的IP地址",
   254  		},
   255  		{
   256  			ns:       "Test.IPAddrv4",
   257  			expected: "IPAddrv4必須是一個有效的IPv4地址",
   258  		},
   259  		{
   260  			ns:       "Test.IPAddrv6",
   261  			expected: "IPAddrv6必須是一個有效的IPv6地址",
   262  		},
   263  		{
   264  			ns:       "Test.UDPAddr",
   265  			expected: "UDPAddr必須是一個有效的UDP地址",
   266  		},
   267  		{
   268  			ns:       "Test.UDPAddrv4",
   269  			expected: "UDPAddrv4必須是一個有效的IPv4 UDP地址",
   270  		},
   271  		{
   272  			ns:       "Test.UDPAddrv6",
   273  			expected: "UDPAddrv6必須是一個有效的IPv6 UDP地址",
   274  		},
   275  		{
   276  			ns:       "Test.TCPAddr",
   277  			expected: "TCPAddr必須是一個有效的TCP地址",
   278  		},
   279  		{
   280  			ns:       "Test.TCPAddrv4",
   281  			expected: "TCPAddrv4必須是一個有效的IPv4 TCP地址",
   282  		},
   283  		{
   284  			ns:       "Test.TCPAddrv6",
   285  			expected: "TCPAddrv6必須是一個有效的IPv6 TCP地址",
   286  		},
   287  		{
   288  			ns:       "Test.CIDR",
   289  			expected: "CIDR必須是一個有效的無類別域間路由(CIDR)",
   290  		},
   291  		{
   292  			ns:       "Test.CIDRv4",
   293  			expected: "CIDRv4必須是一个包含IPv4地址的有效無類別域間路由(CIDR)",
   294  		},
   295  		{
   296  			ns:       "Test.CIDRv6",
   297  			expected: "CIDRv6必須是一个包含IPv6地址的有效無類別域間路由(CIDR)",
   298  		},
   299  		{
   300  			ns:       "Test.SSN",
   301  			expected: "SSN必須是一個有效的社會安全編號(SSN)",
   302  		},
   303  		{
   304  			ns:       "Test.IP",
   305  			expected: "IP必須是一個有效的IP地址",
   306  		},
   307  		{
   308  			ns:       "Test.IPv4",
   309  			expected: "IPv4必須是一個有效的IPv4地址",
   310  		},
   311  		{
   312  			ns:       "Test.IPv6",
   313  			expected: "IPv6必須是一個有效的IPv6地址",
   314  		},
   315  		{
   316  			ns:       "Test.DataURI",
   317  			expected: "DataURI必須包含有效的數據URI",
   318  		},
   319  		{
   320  			ns:       "Test.Latitude",
   321  			expected: "Latitude必須包含有效的緯度座標",
   322  		},
   323  		{
   324  			ns:       "Test.Longitude",
   325  			expected: "Longitude必須包含有效的經度座標",
   326  		},
   327  		{
   328  			ns:       "Test.MultiByte",
   329  			expected: "MultiByte必須包含多個字元",
   330  		},
   331  		{
   332  			ns:       "Test.ASCII",
   333  			expected: "ASCII必須只包含ascii字元",
   334  		},
   335  		{
   336  			ns:       "Test.PrintableASCII",
   337  			expected: "PrintableASCII必須只包含可輸出的ascii字元",
   338  		},
   339  		{
   340  			ns:       "Test.UUID",
   341  			expected: "UUID必須是一個有效的UUID",
   342  		},
   343  		{
   344  			ns:       "Test.UUID3",
   345  			expected: "UUID3必須是一個有效的V3 UUID",
   346  		},
   347  		{
   348  			ns:       "Test.UUID4",
   349  			expected: "UUID4必須是一個有效的V4 UUID",
   350  		},
   351  		{
   352  			ns:       "Test.UUID5",
   353  			expected: "UUID5必須是一個有效的V5 UUID",
   354  		},
   355  		{
   356  			ns:       "Test.ULID",
   357  			expected: "ULID必須是一個有效的ULID",
   358  		},
   359  		{
   360  			ns:       "Test.ISBN",
   361  			expected: "ISBN必須是一個有效的ISBN編號",
   362  		},
   363  		{
   364  			ns:       "Test.ISBN10",
   365  			expected: "ISBN10必須是一個有效的ISBN-10編號",
   366  		},
   367  		{
   368  			ns:       "Test.ISBN13",
   369  			expected: "ISBN13必須是一個有效的ISBN-13編號",
   370  		},
   371  		{
   372  			ns:       "Test.ISSN",
   373  			expected: "ISSN必須是一個有效的ISSN編號",
   374  		},
   375  		{
   376  			ns:       "Test.Excludes",
   377  			expected: "Excludes不能包含文字'text'",
   378  		},
   379  		{
   380  			ns:       "Test.ExcludesAll",
   381  			expected: "ExcludesAll不能包含以下任何字元'!@#$'",
   382  		},
   383  		{
   384  			ns:       "Test.ExcludesRune",
   385  			expected: "ExcludesRune不能包含'☻'",
   386  		},
   387  		{
   388  			ns:       "Test.ContainsAny",
   389  			expected: "ContainsAny必須包含至少一個以下字元'!@#$'",
   390  		},
   391  		{
   392  			ns:       "Test.Contains",
   393  			expected: "Contains必須包含文字'purpose'",
   394  		},
   395  		{
   396  			ns:       "Test.Base64",
   397  			expected: "Base64必須是一個有效的Base64字元串",
   398  		},
   399  		{
   400  			ns:       "Test.Email",
   401  			expected: "Email必須是一個有效的信箱",
   402  		},
   403  		{
   404  			ns:       "Test.URL",
   405  			expected: "URL必須是一個有效的URL",
   406  		},
   407  		{
   408  			ns:       "Test.URI",
   409  			expected: "URI必須是一個有效的URI",
   410  		},
   411  		{
   412  			ns:       "Test.RGBColorString",
   413  			expected: "RGBColorString必須是一個有效的RGB顏色",
   414  		},
   415  		{
   416  			ns:       "Test.RGBAColorString",
   417  			expected: "RGBAColorString必須是一個有效的RGBA顏色",
   418  		},
   419  		{
   420  			ns:       "Test.HSLColorString",
   421  			expected: "HSLColorString必須是一個有效的HSL顏色",
   422  		},
   423  		{
   424  			ns:       "Test.HSLAColorString",
   425  			expected: "HSLAColorString必須是一個有效的HSLA顏色",
   426  		},
   427  		{
   428  			ns:       "Test.HexadecimalString",
   429  			expected: "HexadecimalString必須是一個有效的十六進制",
   430  		},
   431  		{
   432  			ns:       "Test.HexColorString",
   433  			expected: "HexColorString必須是一個有效的十六進制顏色",
   434  		},
   435  		{
   436  			ns:       "Test.NumberString",
   437  			expected: "NumberString必須是一個有效的數字",
   438  		},
   439  		{
   440  			ns:       "Test.NumericString",
   441  			expected: "NumericString必須是一個有效的數值",
   442  		},
   443  		{
   444  			ns:       "Test.AlphanumString",
   445  			expected: "AlphanumString只能包含字母和數字",
   446  		},
   447  		{
   448  			ns:       "Test.AlphaString",
   449  			expected: "AlphaString只能包含字母",
   450  		},
   451  		{
   452  			ns:       "Test.LtFieldString",
   453  			expected: "LtFieldString必須小於MaxString",
   454  		},
   455  		{
   456  			ns:       "Test.LteFieldString",
   457  			expected: "LteFieldString必須小於或等於MaxString",
   458  		},
   459  		{
   460  			ns:       "Test.GtFieldString",
   461  			expected: "GtFieldString必須大於MaxString",
   462  		},
   463  		{
   464  			ns:       "Test.GteFieldString",
   465  			expected: "GteFieldString必須大於或等於MaxString",
   466  		},
   467  		{
   468  			ns:       "Test.NeFieldString",
   469  			expected: "NeFieldString不能等於EqFieldString",
   470  		},
   471  		{
   472  			ns:       "Test.LtCSFieldString",
   473  			expected: "LtCSFieldString必須小於Inner.LtCSFieldString",
   474  		},
   475  		{
   476  			ns:       "Test.LteCSFieldString",
   477  			expected: "LteCSFieldString必須小於或等於Inner.LteCSFieldString",
   478  		},
   479  		{
   480  			ns:       "Test.GtCSFieldString",
   481  			expected: "GtCSFieldString必須大於Inner.GtCSFieldString",
   482  		},
   483  		{
   484  			ns:       "Test.GteCSFieldString",
   485  			expected: "GteCSFieldString必須大於或等於Inner.GteCSFieldString",
   486  		},
   487  		{
   488  			ns:       "Test.NeCSFieldString",
   489  			expected: "NeCSFieldString不能等於Inner.NeCSFieldString",
   490  		},
   491  		{
   492  			ns:       "Test.EqCSFieldString",
   493  			expected: "EqCSFieldString必須等於Inner.EqCSFieldString",
   494  		},
   495  		{
   496  			ns:       "Test.EqFieldString",
   497  			expected: "EqFieldString必須等於MaxString",
   498  		},
   499  		{
   500  			ns:       "Test.GteString",
   501  			expected: "GteString長度必須至少為3個字元",
   502  		},
   503  		{
   504  			ns:       "Test.GteNumber",
   505  			expected: "GteNumber必須大於或等於5.56",
   506  		},
   507  		{
   508  			ns:       "Test.GteMultiple",
   509  			expected: "GteMultiple必須至少包含2項",
   510  		},
   511  		{
   512  			ns:       "Test.GteTime",
   513  			expected: "GteTime必須大於或等於目前日期和時間",
   514  		},
   515  		{
   516  			ns:       "Test.GtString",
   517  			expected: "GtString長度必須大於3個字元",
   518  		},
   519  		{
   520  			ns:       "Test.GtNumber",
   521  			expected: "GtNumber必須大於5.56",
   522  		},
   523  		{
   524  			ns:       "Test.GtMultiple",
   525  			expected: "GtMultiple必須大於2項",
   526  		},
   527  		{
   528  			ns:       "Test.GtTime",
   529  			expected: "GtTime必須大於目前日期和時間",
   530  		},
   531  		{
   532  			ns:       "Test.LteString",
   533  			expected: "LteString長度不能超過3個字元",
   534  		},
   535  		{
   536  			ns:       "Test.LteNumber",
   537  			expected: "LteNumber必須小於或等於5.56",
   538  		},
   539  		{
   540  			ns:       "Test.LteMultiple",
   541  			expected: "LteMultiple最多只能包含2項",
   542  		},
   543  		{
   544  			ns:       "Test.LteTime",
   545  			expected: "LteTime必須小於或等於目前日期和時間",
   546  		},
   547  		{
   548  			ns:       "Test.LtString",
   549  			expected: "LtString長度必須小於3個字元",
   550  		},
   551  		{
   552  			ns:       "Test.LtNumber",
   553  			expected: "LtNumber必須小於5.56",
   554  		},
   555  		{
   556  			ns:       "Test.LtMultiple",
   557  			expected: "LtMultiple必須包含少於2項",
   558  		},
   559  		{
   560  			ns:       "Test.LtTime",
   561  			expected: "LtTime必須小於目前日期和時間",
   562  		},
   563  		{
   564  			ns:       "Test.NeString",
   565  			expected: "NeString不能等於",
   566  		},
   567  		{
   568  			ns:       "Test.NeNumber",
   569  			expected: "NeNumber不能等於0.00",
   570  		},
   571  		{
   572  			ns:       "Test.NeMultiple",
   573  			expected: "NeMultiple不能等於0",
   574  		},
   575  		{
   576  			ns:       "Test.EqString",
   577  			expected: "EqString不等於3",
   578  		},
   579  		{
   580  			ns:       "Test.EqNumber",
   581  			expected: "EqNumber不等於2.33",
   582  		},
   583  		{
   584  			ns:       "Test.EqMultiple",
   585  			expected: "EqMultiple不等於7",
   586  		},
   587  		{
   588  			ns:       "Test.MaxString",
   589  			expected: "MaxString長度不能超過3個字元",
   590  		},
   591  		{
   592  			ns:       "Test.MaxNumber",
   593  			expected: "MaxNumber必須小於或等於1,113.00",
   594  		},
   595  		{
   596  			ns:       "Test.MaxMultiple",
   597  			expected: "MaxMultiple最多只能包含7項",
   598  		},
   599  		{
   600  			ns:       "Test.MinString",
   601  			expected: "MinString長度必須至少為1個字元",
   602  		},
   603  		{
   604  			ns:       "Test.MinNumber",
   605  			expected: "MinNumber最小只能為1,113.00",
   606  		},
   607  		{
   608  			ns:       "Test.MinMultiple",
   609  			expected: "MinMultiple必須至少包含7項",
   610  		},
   611  		{
   612  			ns:       "Test.LenString",
   613  			expected: "LenString長度必須為1個字元",
   614  		},
   615  		{
   616  			ns:       "Test.LenNumber",
   617  			expected: "LenNumber必須等於1,113.00",
   618  		},
   619  		{
   620  			ns:       "Test.LenMultiple",
   621  			expected: "LenMultiple必須包含7項",
   622  		},
   623  		{
   624  			ns:       "Test.RequiredString",
   625  			expected: "RequiredString為必填欄位",
   626  		},
   627  		{
   628  			ns:       "Test.RequiredNumber",
   629  			expected: "RequiredNumber為必填欄位",
   630  		},
   631  		{
   632  			ns:       "Test.RequiredMultiple",
   633  			expected: "RequiredMultiple為必填欄位",
   634  		},
   635  		{
   636  			ns:       "Test.RequiredUnless",
   637  			expected: "RequiredUnless為必填欄位",
   638  		},
   639  		{
   640  			ns:       "Test.RequiredWith",
   641  			expected: "RequiredWith為必填欄位",
   642  		},
   643  		{
   644  			ns:       "Test.RequiredWithAll",
   645  			expected: "RequiredWithAll為必填欄位",
   646  		},
   647  		{
   648  			ns:       "Test.RequiredWithout",
   649  			expected: "RequiredWithout為必填欄位",
   650  		},
   651  		{
   652  			ns:       "Test.RequiredWithoutAll",
   653  			expected: "RequiredWithoutAll為必填欄位",
   654  		},
   655  		{
   656  			ns:       "Test.ExcludedIf",
   657  			expected: "ExcludedIf為禁填欄位",
   658  		},
   659  		{
   660  			ns:       "Test.ExcludedUnless",
   661  			expected: "ExcludedUnless為禁填欄位",
   662  		},
   663  		{
   664  			ns:       "Test.ExcludedWith",
   665  			expected: "ExcludedWith為禁填欄位",
   666  		},
   667  		{
   668  			ns:       "Test.ExcludedWithAll",
   669  			expected: "ExcludedWithAll為禁填欄位",
   670  		},
   671  		{
   672  			ns:       "Test.ExcludedWithout",
   673  			expected: "ExcludedWithout為禁填欄位",
   674  		},
   675  		{
   676  			ns:       "Test.ExcludedWithoutAll",
   677  			expected: "ExcludedWithoutAll為禁填欄位",
   678  		},
   679  		{
   680  			ns:       "Test.StrPtrMinLen",
   681  			expected: "StrPtrMinLen長度必須至少為10個字元",
   682  		},
   683  		{
   684  			ns:       "Test.StrPtrMaxLen",
   685  			expected: "StrPtrMaxLen長度不能超過1個字元",
   686  		},
   687  		{
   688  			ns:       "Test.StrPtrLen",
   689  			expected: "StrPtrLen長度必須為2個字元",
   690  		},
   691  		{
   692  			ns:       "Test.StrPtrLt",
   693  			expected: "StrPtrLt長度必須小於1個字元",
   694  		},
   695  		{
   696  			ns:       "Test.StrPtrLte",
   697  			expected: "StrPtrLte長度不能超過1個字元",
   698  		},
   699  		{
   700  			ns:       "Test.StrPtrGt",
   701  			expected: "StrPtrGt長度必須大於10個字元",
   702  		},
   703  		{
   704  			ns:       "Test.StrPtrGte",
   705  			expected: "StrPtrGte長度必須至少為10個字元",
   706  		},
   707  		{
   708  			ns:       "Test.OneOfString",
   709  			expected: "OneOfString必須是[red green]中的一個",
   710  		},
   711  		{
   712  			ns:       "Test.OneOfInt",
   713  			expected: "OneOfInt必須是[5 63]中的一個",
   714  		},
   715  		{
   716  			ns:       "Test.Datetime",
   717  			expected: "Datetime與2006-01-02格式不匹配",
   718  		},
   719  		{
   720  			ns: "Test.Image",
   721  			expected: "Image 必須是有效圖像",
   722  		},
   723  	}
   724  
   725  	for _, tt := range tests {
   726  
   727  		var fe validator.FieldError
   728  
   729  		for _, e := range errs {
   730  			if tt.ns == e.Namespace() {
   731  				fe = e
   732  				break
   733  			}
   734  		}
   735  
   736  		NotEqual(t, fe, nil)
   737  		Equal(t, tt.expected, fe.Translate(trans))
   738  	}
   739  
   740  }
   741  

View as plain text