ru_RU_test.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. package ru_RU
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/go-playground/locales"
  6. "github.com/go-playground/locales/currency"
  7. )
  8. func TestLocale(t *testing.T) {
  9. trans := New()
  10. expected := "ru_RU"
  11. if trans.Locale() != expected {
  12. t.Errorf("Expected '%s' Got '%s'", expected, trans.Locale())
  13. }
  14. }
  15. func TestPluralsRange(t *testing.T) {
  16. trans := New()
  17. tests := []struct {
  18. expected locales.PluralRule
  19. }{
  20. {
  21. expected: locales.PluralRuleOther,
  22. },
  23. }
  24. rules := trans.PluralsRange()
  25. expected := 4
  26. if len(rules) != expected {
  27. t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
  28. }
  29. for _, tt := range tests {
  30. r := locales.PluralRuleUnknown
  31. for i := 0; i < len(rules); i++ {
  32. if rules[i] == tt.expected {
  33. r = rules[i]
  34. break
  35. }
  36. }
  37. if r == locales.PluralRuleUnknown {
  38. t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
  39. }
  40. }
  41. }
  42. func TestPluralsOrdinal(t *testing.T) {
  43. trans := New()
  44. tests := []struct {
  45. expected locales.PluralRule
  46. }{
  47. {
  48. expected: locales.PluralRuleOther,
  49. },
  50. }
  51. rules := trans.PluralsOrdinal()
  52. expected := 1
  53. if len(rules) != expected {
  54. t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
  55. }
  56. for _, tt := range tests {
  57. r := locales.PluralRuleUnknown
  58. for i := 0; i < len(rules); i++ {
  59. if rules[i] == tt.expected {
  60. r = rules[i]
  61. break
  62. }
  63. }
  64. if r == locales.PluralRuleUnknown {
  65. t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
  66. }
  67. }
  68. }
  69. func TestPluralsCardinal(t *testing.T) {
  70. trans := New()
  71. tests := []struct {
  72. expected locales.PluralRule
  73. }{
  74. {
  75. expected: locales.PluralRuleOne,
  76. },
  77. {
  78. expected: locales.PluralRuleFew,
  79. },
  80. {
  81. expected: locales.PluralRuleMany,
  82. },
  83. {
  84. expected: locales.PluralRuleOther,
  85. },
  86. }
  87. rules := trans.PluralsCardinal()
  88. expected := 4
  89. if len(rules) != expected {
  90. t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
  91. }
  92. for _, tt := range tests {
  93. r := locales.PluralRuleUnknown
  94. for i := 0; i < len(rules); i++ {
  95. if rules[i] == tt.expected {
  96. r = rules[i]
  97. break
  98. }
  99. }
  100. if r == locales.PluralRuleUnknown {
  101. t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
  102. }
  103. }
  104. }
  105. func TestRangePlurals(t *testing.T) {
  106. trans := New()
  107. tests := []struct {
  108. num1 float64
  109. v1 uint64
  110. num2 float64
  111. v2 uint64
  112. expected locales.PluralRule
  113. }{
  114. {
  115. num1: 1,
  116. v1: 1,
  117. num2: 2,
  118. v2: 2,
  119. expected: locales.PluralRuleOther,
  120. },
  121. {
  122. num1: 1,
  123. v1: 0,
  124. num2: 2,
  125. v2: 0,
  126. expected: locales.PluralRuleFew,
  127. },
  128. {
  129. num1: 1,
  130. v1: 0,
  131. num2: 21,
  132. v2: 0,
  133. expected: locales.PluralRuleOne,
  134. },
  135. {
  136. num1: 1,
  137. v1: 0,
  138. num2: 5,
  139. v2: 0,
  140. expected: locales.PluralRuleMany,
  141. },
  142. {
  143. num1: 1,
  144. v1: 0,
  145. num2: 10,
  146. v2: 0,
  147. expected: locales.PluralRuleMany,
  148. },
  149. {
  150. num1: 1,
  151. v1: 0,
  152. num2: 10.0,
  153. v2: 1,
  154. expected: locales.PluralRuleOther,
  155. },
  156. {
  157. num1: 2,
  158. v1: 0,
  159. num2: 21,
  160. v2: 0,
  161. expected: locales.PluralRuleOne,
  162. },
  163. {
  164. num1: 2,
  165. v1: 0,
  166. num2: 22,
  167. v2: 0,
  168. expected: locales.PluralRuleFew,
  169. },
  170. {
  171. num1: 2,
  172. v1: 0,
  173. num2: 5,
  174. v2: 0,
  175. expected: locales.PluralRuleMany,
  176. },
  177. {
  178. num1: 2,
  179. v1: 0,
  180. num2: 10,
  181. v2: 1,
  182. expected: locales.PluralRuleOther,
  183. },
  184. {
  185. num1: 0,
  186. v1: 0,
  187. num2: 1,
  188. v2: 0,
  189. expected: locales.PluralRuleOne,
  190. },
  191. {
  192. num1: 0,
  193. v1: 0,
  194. num2: 2,
  195. v2: 0,
  196. expected: locales.PluralRuleFew,
  197. },
  198. {
  199. num1: 0,
  200. v1: 0,
  201. num2: 5,
  202. v2: 0,
  203. expected: locales.PluralRuleMany,
  204. },
  205. {
  206. num1: 0,
  207. v1: 0,
  208. num2: 10,
  209. v2: 1,
  210. expected: locales.PluralRuleOther,
  211. },
  212. {
  213. num1: 0.0,
  214. v1: 1,
  215. num2: 1,
  216. v2: 0,
  217. expected: locales.PluralRuleOne,
  218. },
  219. {
  220. num1: 0.0,
  221. v1: 1,
  222. num2: 2,
  223. v2: 0,
  224. expected: locales.PluralRuleFew,
  225. },
  226. {
  227. num1: 0.0,
  228. v1: 1,
  229. num2: 5,
  230. v2: 0,
  231. expected: locales.PluralRuleMany,
  232. },
  233. {
  234. num1: 0.0,
  235. v1: 1,
  236. num2: 10.0,
  237. v2: 1,
  238. expected: locales.PluralRuleOther,
  239. },
  240. }
  241. for _, tt := range tests {
  242. rule := trans.RangePluralRule(tt.num1, tt.v1, tt.num2, tt.v2)
  243. if rule != tt.expected {
  244. t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
  245. }
  246. }
  247. }
  248. func TestOrdinalPlurals(t *testing.T) {
  249. trans := New()
  250. tests := []struct {
  251. num float64
  252. v uint64
  253. expected locales.PluralRule
  254. }{
  255. {
  256. num: 1,
  257. v: 0,
  258. expected: locales.PluralRuleOther,
  259. },
  260. {
  261. num: 2,
  262. v: 0,
  263. expected: locales.PluralRuleOther,
  264. },
  265. {
  266. num: 3,
  267. v: 0,
  268. expected: locales.PluralRuleOther,
  269. },
  270. {
  271. num: 4,
  272. v: 0,
  273. expected: locales.PluralRuleOther,
  274. },
  275. }
  276. for _, tt := range tests {
  277. rule := trans.OrdinalPluralRule(tt.num, tt.v)
  278. if rule != tt.expected {
  279. t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
  280. }
  281. }
  282. }
  283. func TestCardinalPlurals(t *testing.T) {
  284. trans := New()
  285. tests := []struct {
  286. num float64
  287. v uint64
  288. expected locales.PluralRule
  289. }{
  290. {
  291. num: 1,
  292. v: 0,
  293. expected: locales.PluralRuleOne,
  294. },
  295. {
  296. num: 21,
  297. v: 0,
  298. expected: locales.PluralRuleOne,
  299. },
  300. {
  301. num: 31,
  302. v: 0,
  303. expected: locales.PluralRuleOne,
  304. },
  305. {
  306. num: 2,
  307. v: 0,
  308. expected: locales.PluralRuleFew,
  309. },
  310. {
  311. num: 3,
  312. v: 0,
  313. expected: locales.PluralRuleFew,
  314. },
  315. {
  316. num: 22,
  317. v: 0,
  318. expected: locales.PluralRuleFew,
  319. },
  320. {
  321. num: 23,
  322. v: 0,
  323. expected: locales.PluralRuleFew,
  324. },
  325. {
  326. num: 0,
  327. v: 0,
  328. expected: locales.PluralRuleMany,
  329. },
  330. {
  331. num: 5,
  332. v: 0,
  333. expected: locales.PluralRuleMany,
  334. },
  335. {
  336. num: 11,
  337. v: 0,
  338. expected: locales.PluralRuleMany,
  339. },
  340. {
  341. num: 100,
  342. v: 0,
  343. expected: locales.PluralRuleMany,
  344. },
  345. }
  346. for _, tt := range tests {
  347. rule := trans.CardinalPluralRule(tt.num, tt.v)
  348. if rule != tt.expected {
  349. t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
  350. }
  351. }
  352. }
  353. func TestDaysAbbreviated(t *testing.T) {
  354. trans := New()
  355. days := trans.WeekdaysAbbreviated()
  356. for i, day := range days {
  357. s := trans.WeekdayAbbreviated(time.Weekday(i))
  358. if s != day {
  359. t.Errorf("Expected '%s' Got '%s'", day, s)
  360. }
  361. }
  362. tests := []struct {
  363. idx int
  364. expected string
  365. }{
  366. {
  367. idx: 0,
  368. expected: "вс",
  369. },
  370. {
  371. idx: 1,
  372. expected: "пн",
  373. },
  374. {
  375. idx: 2,
  376. expected: "вт",
  377. },
  378. {
  379. idx: 3,
  380. expected: "ср",
  381. },
  382. {
  383. idx: 4,
  384. expected: "чт",
  385. },
  386. {
  387. idx: 5,
  388. expected: "пт",
  389. },
  390. {
  391. idx: 6,
  392. expected: "сб",
  393. },
  394. }
  395. for _, tt := range tests {
  396. s := trans.WeekdayAbbreviated(time.Weekday(tt.idx))
  397. if s != tt.expected {
  398. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  399. }
  400. }
  401. }
  402. func TestDaysNarrow(t *testing.T) {
  403. trans := New()
  404. days := trans.WeekdaysNarrow()
  405. for i, day := range days {
  406. s := trans.WeekdayNarrow(time.Weekday(i))
  407. if s != day {
  408. t.Errorf("Expected '%s' Got '%s'", string(day), s)
  409. }
  410. }
  411. tests := []struct {
  412. idx int
  413. expected string
  414. }{
  415. {
  416. idx: 0,
  417. expected: "вс",
  418. },
  419. {
  420. idx: 1,
  421. expected: "пн",
  422. },
  423. {
  424. idx: 2,
  425. expected: "вт",
  426. },
  427. {
  428. idx: 3,
  429. expected: "ср",
  430. },
  431. {
  432. idx: 4,
  433. expected: "чт",
  434. },
  435. {
  436. idx: 5,
  437. expected: "пт",
  438. },
  439. {
  440. idx: 6,
  441. expected: "сб",
  442. },
  443. }
  444. for _, tt := range tests {
  445. s := trans.WeekdayNarrow(time.Weekday(tt.idx))
  446. if s != tt.expected {
  447. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  448. }
  449. }
  450. }
  451. func TestDaysShort(t *testing.T) {
  452. trans := New()
  453. days := trans.WeekdaysShort()
  454. for i, day := range days {
  455. s := trans.WeekdayShort(time.Weekday(i))
  456. if s != day {
  457. t.Errorf("Expected '%s' Got '%s'", day, s)
  458. }
  459. }
  460. tests := []struct {
  461. idx int
  462. expected string
  463. }{
  464. {
  465. idx: 0,
  466. expected: "вс",
  467. },
  468. {
  469. idx: 1,
  470. expected: "пн",
  471. },
  472. {
  473. idx: 2,
  474. expected: "вт",
  475. },
  476. {
  477. idx: 3,
  478. expected: "ср",
  479. },
  480. {
  481. idx: 4,
  482. expected: "чт",
  483. },
  484. {
  485. idx: 5,
  486. expected: "пт",
  487. },
  488. {
  489. idx: 6,
  490. expected: "сб",
  491. },
  492. }
  493. for _, tt := range tests {
  494. s := trans.WeekdayShort(time.Weekday(tt.idx))
  495. if s != tt.expected {
  496. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  497. }
  498. }
  499. }
  500. func TestDaysWide(t *testing.T) {
  501. trans := New()
  502. days := trans.WeekdaysWide()
  503. for i, day := range days {
  504. s := trans.WeekdayWide(time.Weekday(i))
  505. if s != day {
  506. t.Errorf("Expected '%s' Got '%s'", day, s)
  507. }
  508. }
  509. tests := []struct {
  510. idx int
  511. expected string
  512. }{
  513. {
  514. idx: 0,
  515. expected: "воскресенье",
  516. },
  517. {
  518. idx: 1,
  519. expected: "понедельник",
  520. },
  521. {
  522. idx: 2,
  523. expected: "вторник",
  524. },
  525. {
  526. idx: 3,
  527. expected: "среда",
  528. },
  529. {
  530. idx: 4,
  531. expected: "четверг",
  532. },
  533. {
  534. idx: 5,
  535. expected: "пятница",
  536. },
  537. {
  538. idx: 6,
  539. expected: "суббота",
  540. },
  541. }
  542. for _, tt := range tests {
  543. s := trans.WeekdayWide(time.Weekday(tt.idx))
  544. if s != tt.expected {
  545. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  546. }
  547. }
  548. }
  549. func TestMonthsAbbreviated(t *testing.T) {
  550. trans := New()
  551. months := trans.MonthsAbbreviated()
  552. for i, month := range months {
  553. s := trans.MonthAbbreviated(time.Month(i + 1))
  554. if s != month {
  555. t.Errorf("Expected '%s' Got '%s'", month, s)
  556. }
  557. }
  558. tests := []struct {
  559. idx int
  560. expected string
  561. }{
  562. {
  563. idx: 1,
  564. expected: "янв.",
  565. },
  566. {
  567. idx: 2,
  568. expected: "февр.",
  569. },
  570. {
  571. idx: 3,
  572. expected: "мар.",
  573. },
  574. {
  575. idx: 4,
  576. expected: "апр.",
  577. },
  578. {
  579. idx: 5,
  580. expected: "мая",
  581. },
  582. {
  583. idx: 6,
  584. expected: "июн.",
  585. },
  586. {
  587. idx: 7,
  588. expected: "июл.",
  589. },
  590. {
  591. idx: 8,
  592. expected: "авг.",
  593. },
  594. {
  595. idx: 9,
  596. expected: "сент.",
  597. },
  598. {
  599. idx: 10,
  600. expected: "окт.",
  601. },
  602. {
  603. idx: 11,
  604. expected: "нояб.",
  605. },
  606. {
  607. idx: 12,
  608. expected: "дек.",
  609. },
  610. }
  611. for _, tt := range tests {
  612. s := trans.MonthAbbreviated(time.Month(tt.idx))
  613. if s != tt.expected {
  614. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  615. }
  616. }
  617. }
  618. func TestMonthsNarrow(t *testing.T) {
  619. trans := New()
  620. months := trans.MonthsNarrow()
  621. for i, month := range months {
  622. s := trans.MonthNarrow(time.Month(i + 1))
  623. if s != month {
  624. t.Errorf("Expected '%s' Got '%s'", month, s)
  625. }
  626. }
  627. tests := []struct {
  628. idx int
  629. expected string
  630. }{
  631. {
  632. idx: 1,
  633. expected: "Я",
  634. },
  635. {
  636. idx: 2,
  637. expected: "Ф",
  638. },
  639. {
  640. idx: 3,
  641. expected: "М",
  642. },
  643. {
  644. idx: 4,
  645. expected: "А",
  646. },
  647. {
  648. idx: 5,
  649. expected: "М",
  650. },
  651. {
  652. idx: 6,
  653. expected: "И",
  654. },
  655. {
  656. idx: 7,
  657. expected: "И",
  658. },
  659. {
  660. idx: 8,
  661. expected: "А",
  662. },
  663. {
  664. idx: 9,
  665. expected: "С",
  666. },
  667. {
  668. idx: 10,
  669. expected: "О",
  670. },
  671. {
  672. idx: 11,
  673. expected: "Н",
  674. },
  675. {
  676. idx: 12,
  677. expected: "Д",
  678. },
  679. }
  680. for _, tt := range tests {
  681. s := trans.MonthNarrow(time.Month(tt.idx))
  682. if s != tt.expected {
  683. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  684. }
  685. }
  686. }
  687. func TestMonthsWide(t *testing.T) {
  688. trans := New()
  689. months := trans.MonthsWide()
  690. for i, month := range months {
  691. s := trans.MonthWide(time.Month(i + 1))
  692. if s != month {
  693. t.Errorf("Expected '%s' Got '%s'", month, s)
  694. }
  695. }
  696. tests := []struct {
  697. idx int
  698. expected string
  699. }{
  700. {
  701. idx: 1,
  702. expected: "января",
  703. },
  704. {
  705. idx: 2,
  706. expected: "февраля",
  707. },
  708. {
  709. idx: 3,
  710. expected: "марта",
  711. },
  712. {
  713. idx: 4,
  714. expected: "апреля",
  715. },
  716. {
  717. idx: 5,
  718. expected: "мая",
  719. },
  720. {
  721. idx: 6,
  722. expected: "июня",
  723. },
  724. {
  725. idx: 7,
  726. expected: "июля",
  727. },
  728. {
  729. idx: 8,
  730. expected: "августа",
  731. },
  732. {
  733. idx: 9,
  734. expected: "сентября",
  735. },
  736. {
  737. idx: 10,
  738. expected: "октября",
  739. },
  740. {
  741. idx: 11,
  742. expected: "ноября",
  743. },
  744. {
  745. idx: 12,
  746. expected: "декабря",
  747. },
  748. }
  749. for _, tt := range tests {
  750. s := string(trans.MonthWide(time.Month(tt.idx)))
  751. if s != tt.expected {
  752. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  753. }
  754. }
  755. }
  756. func TestFmtTimeFull(t *testing.T) {
  757. loc, err := time.LoadLocation("America/Toronto")
  758. if err != nil {
  759. t.Errorf("Expected '<nil>' Got '%s'", err)
  760. }
  761. fixed := time.FixedZone("OTHER", -4)
  762. tests := []struct {
  763. t time.Time
  764. expected string
  765. }{
  766. {
  767. t: time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
  768. expected: "9:05:01 Восточная Америка, стандартное время",
  769. },
  770. {
  771. t: time.Date(2016, 02, 03, 20, 5, 1, 0, fixed),
  772. expected: "20:05:01 OTHER",
  773. },
  774. }
  775. trans := New()
  776. for _, tt := range tests {
  777. s := trans.FmtTimeFull(tt.t)
  778. if s != tt.expected {
  779. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  780. }
  781. }
  782. }
  783. func TestFmtTimeLong(t *testing.T) {
  784. loc, err := time.LoadLocation("America/Toronto")
  785. if err != nil {
  786. t.Errorf("Expected '<nil>' Got '%s'", err)
  787. }
  788. tests := []struct {
  789. t time.Time
  790. expected string
  791. }{
  792. {
  793. t: time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
  794. expected: "9:05:01 EST",
  795. },
  796. {
  797. t: time.Date(2016, 02, 03, 20, 5, 1, 0, loc),
  798. expected: "20:05:01 EST",
  799. },
  800. }
  801. trans := New()
  802. for _, tt := range tests {
  803. s := trans.FmtTimeLong(tt.t)
  804. if s != tt.expected {
  805. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  806. }
  807. }
  808. }
  809. func TestFmtTimeMedium(t *testing.T) {
  810. tests := []struct {
  811. t time.Time
  812. expected string
  813. }{
  814. {
  815. t: time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
  816. expected: "9:05:01",
  817. },
  818. {
  819. t: time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
  820. expected: "20:05:01",
  821. },
  822. }
  823. trans := New()
  824. for _, tt := range tests {
  825. s := trans.FmtTimeMedium(tt.t)
  826. if s != tt.expected {
  827. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  828. }
  829. }
  830. }
  831. func TestFmtTimeShort(t *testing.T) {
  832. tests := []struct {
  833. t time.Time
  834. expected string
  835. }{
  836. {
  837. t: time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
  838. expected: "9:05",
  839. },
  840. {
  841. t: time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
  842. expected: "20:05",
  843. },
  844. }
  845. trans := New()
  846. for _, tt := range tests {
  847. s := trans.FmtTimeShort(tt.t)
  848. if s != tt.expected {
  849. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  850. }
  851. }
  852. }
  853. func TestFmtDateFull(t *testing.T) {
  854. tests := []struct {
  855. t time.Time
  856. expected string
  857. }{
  858. {
  859. t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
  860. expected: "среда, 3 февраля 2016 г.",
  861. },
  862. }
  863. trans := New()
  864. for _, tt := range tests {
  865. s := trans.FmtDateFull(tt.t)
  866. if s != tt.expected {
  867. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  868. }
  869. }
  870. }
  871. func TestFmtDateLong(t *testing.T) {
  872. tests := []struct {
  873. t time.Time
  874. expected string
  875. }{
  876. {
  877. t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
  878. expected: "3 февраля 2016 г.",
  879. },
  880. }
  881. trans := New()
  882. for _, tt := range tests {
  883. s := trans.FmtDateLong(tt.t)
  884. if s != tt.expected {
  885. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  886. }
  887. }
  888. }
  889. func TestFmtDateMedium(t *testing.T) {
  890. tests := []struct {
  891. t time.Time
  892. expected string
  893. }{
  894. {
  895. t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
  896. expected: "3 февр. 2016 г.",
  897. },
  898. }
  899. trans := New()
  900. for _, tt := range tests {
  901. s := trans.FmtDateMedium(tt.t)
  902. if s != tt.expected {
  903. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  904. }
  905. }
  906. }
  907. func TestFmtDateShort(t *testing.T) {
  908. tests := []struct {
  909. t time.Time
  910. expected string
  911. }{
  912. {
  913. t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
  914. expected: "03.02.2016", // date format changed from v29 dd.MM.yy to v30 dd.MM.y so adjusted test for new CLDR data
  915. },
  916. {
  917. t: time.Date(-500, 02, 03, 9, 0, 1, 0, time.UTC),
  918. expected: "03.02.500",
  919. },
  920. }
  921. trans := New()
  922. for _, tt := range tests {
  923. s := trans.FmtDateShort(tt.t)
  924. if s != tt.expected {
  925. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  926. }
  927. }
  928. }
  929. func TestFmtNumber(t *testing.T) {
  930. tests := []struct {
  931. num float64
  932. v uint64
  933. expected string
  934. }{
  935. {
  936. num: 1123456.5643,
  937. v: 2,
  938. expected: "1 123 456,56",
  939. },
  940. {
  941. num: 1123456.5643,
  942. v: 1,
  943. expected: "1 123 456,6",
  944. },
  945. {
  946. num: 221123456.5643,
  947. v: 3,
  948. expected: "221 123 456,564",
  949. },
  950. {
  951. num: -221123456.5643,
  952. v: 3,
  953. expected: "-221 123 456,564",
  954. },
  955. {
  956. num: -221123456.5643,
  957. v: 3,
  958. expected: "-221 123 456,564",
  959. },
  960. {
  961. num: 0,
  962. v: 2,
  963. expected: "0,00",
  964. },
  965. {
  966. num: -0,
  967. v: 2,
  968. expected: "0,00",
  969. },
  970. {
  971. num: -0,
  972. v: 2,
  973. expected: "0,00",
  974. },
  975. }
  976. trans := New()
  977. for _, tt := range tests {
  978. s := trans.FmtNumber(tt.num, tt.v)
  979. if s != tt.expected {
  980. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  981. }
  982. }
  983. }
  984. func TestFmtCurrency(t *testing.T) {
  985. tests := []struct {
  986. num float64
  987. v uint64
  988. currency currency.Type
  989. expected string
  990. }{
  991. {
  992. num: 1123456.5643,
  993. v: 2,
  994. currency: currency.USD,
  995. expected: "1 123 456,56 USD",
  996. },
  997. {
  998. num: 1123456.5643,
  999. v: 1,
  1000. currency: currency.USD,
  1001. expected: "1 123 456,60 USD",
  1002. },
  1003. {
  1004. num: 221123456.5643,
  1005. v: 3,
  1006. currency: currency.USD,
  1007. expected: "221 123 456,564 USD",
  1008. },
  1009. {
  1010. num: -221123456.5643,
  1011. v: 3,
  1012. currency: currency.USD,
  1013. expected: "-221 123 456,564 USD",
  1014. },
  1015. {
  1016. num: -221123456.5643,
  1017. v: 3,
  1018. currency: currency.CAD,
  1019. expected: "-221 123 456,564 CAD",
  1020. },
  1021. {
  1022. num: 0,
  1023. v: 2,
  1024. currency: currency.USD,
  1025. expected: "0,00 USD",
  1026. },
  1027. {
  1028. num: -0,
  1029. v: 2,
  1030. currency: currency.USD,
  1031. expected: "0,00 USD",
  1032. },
  1033. {
  1034. num: -0,
  1035. v: 2,
  1036. currency: currency.CAD,
  1037. expected: "0,00 CAD",
  1038. },
  1039. {
  1040. num: 1.23,
  1041. v: 0,
  1042. currency: currency.USD,
  1043. expected: "1,00 USD",
  1044. },
  1045. }
  1046. trans := New()
  1047. for _, tt := range tests {
  1048. s := trans.FmtCurrency(tt.num, tt.v, tt.currency)
  1049. if s != tt.expected {
  1050. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  1051. }
  1052. }
  1053. }
  1054. func TestFmtAccounting(t *testing.T) {
  1055. tests := []struct {
  1056. num float64
  1057. v uint64
  1058. currency currency.Type
  1059. expected string
  1060. }{
  1061. {
  1062. num: 1123456.5643,
  1063. v: 2,
  1064. currency: currency.USD,
  1065. expected: "1 123 456,56 USD",
  1066. },
  1067. {
  1068. num: 1123456.5643,
  1069. v: 1,
  1070. currency: currency.USD,
  1071. expected: "1 123 456,60 USD",
  1072. },
  1073. {
  1074. num: 221123456.5643,
  1075. v: 3,
  1076. currency: currency.USD,
  1077. expected: "221 123 456,564 USD",
  1078. },
  1079. {
  1080. num: -221123456.5643,
  1081. v: 3,
  1082. currency: currency.USD,
  1083. expected: "-221 123 456,564 USD",
  1084. },
  1085. {
  1086. num: -221123456.5643,
  1087. v: 3,
  1088. currency: currency.CAD,
  1089. expected: "-221 123 456,564 CAD",
  1090. },
  1091. {
  1092. num: -0,
  1093. v: 2,
  1094. currency: currency.USD,
  1095. expected: "0,00 USD",
  1096. },
  1097. {
  1098. num: -0,
  1099. v: 2,
  1100. currency: currency.CAD,
  1101. expected: "0,00 CAD",
  1102. },
  1103. {
  1104. num: 1.23,
  1105. v: 0,
  1106. currency: currency.USD,
  1107. expected: "1,00 USD",
  1108. },
  1109. }
  1110. trans := New()
  1111. for _, tt := range tests {
  1112. s := trans.FmtAccounting(tt.num, tt.v, tt.currency)
  1113. if s != tt.expected {
  1114. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  1115. }
  1116. }
  1117. }
  1118. func TestFmtPercent(t *testing.T) {
  1119. tests := []struct {
  1120. num float64
  1121. v uint64
  1122. expected string
  1123. }{
  1124. {
  1125. num: 15,
  1126. v: 0,
  1127. expected: "15%",
  1128. },
  1129. {
  1130. num: 15,
  1131. v: 2,
  1132. expected: "15,00%",
  1133. },
  1134. {
  1135. num: 434.45,
  1136. v: 0,
  1137. expected: "434%",
  1138. },
  1139. {
  1140. num: 34.4,
  1141. v: 2,
  1142. expected: "34,40%",
  1143. },
  1144. {
  1145. num: -34,
  1146. v: 0,
  1147. expected: "-34%",
  1148. },
  1149. }
  1150. trans := New()
  1151. for _, tt := range tests {
  1152. s := trans.FmtPercent(tt.num, tt.v)
  1153. if s != tt.expected {
  1154. t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
  1155. }
  1156. }
  1157. }