ja_test.go 20 KB

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