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