twitter_cldr 1.9.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (403) hide show
  1. data/Gemfile +7 -0
  2. data/History.txt +11 -0
  3. data/README.md +93 -13
  4. data/Rakefile +27 -6
  5. data/lib/twitter_cldr/formatters.rb +15 -12
  6. data/lib/twitter_cldr/formatters/base.rb +1 -1
  7. data/lib/twitter_cldr/formatters/calendars/datetime_formatter.rb +18 -3
  8. data/lib/twitter_cldr/formatters/calendars/timespan_formatter.rb +24 -26
  9. data/lib/twitter_cldr/formatters/numbers/abbreviated/abbreviated_number_formatter.rb +47 -0
  10. data/lib/twitter_cldr/formatters/numbers/abbreviated/long_decimal_formatter.rb +18 -0
  11. data/lib/twitter_cldr/formatters/numbers/abbreviated/short_decimal_formatter.rb +18 -0
  12. data/lib/twitter_cldr/formatters/numbers/currency_formatter.rb +22 -17
  13. data/lib/twitter_cldr/formatters/numbers/decimal_formatter.rb +0 -9
  14. data/lib/twitter_cldr/formatters/numbers/helpers/base.rb +1 -1
  15. data/lib/twitter_cldr/formatters/numbers/number_formatter.rb +25 -10
  16. data/lib/twitter_cldr/formatters/numbers/percent_formatter.rb +9 -6
  17. data/lib/twitter_cldr/localized/localized_datetime.rb +6 -2
  18. data/lib/twitter_cldr/localized/localized_number.rb +9 -3
  19. data/lib/twitter_cldr/localized/localized_timespan.rb +1 -1
  20. data/lib/twitter_cldr/resources.rb +13 -12
  21. data/lib/twitter_cldr/resources/custom_locales_resources_importer.rb +1 -1
  22. data/lib/twitter_cldr/resources/download.rb +1 -1
  23. data/lib/twitter_cldr/resources/locales_resources_importer.rb +10 -6
  24. data/lib/twitter_cldr/shared/bidi.rb +27 -27
  25. data/lib/twitter_cldr/shared/currencies.rb +20 -13
  26. data/lib/twitter_cldr/tokenizers.rb +10 -9
  27. data/lib/twitter_cldr/tokenizers/base.rb +33 -21
  28. data/lib/twitter_cldr/tokenizers/calendars/additional_date_format_selector.rb +86 -0
  29. data/lib/twitter_cldr/tokenizers/calendars/date_tokenizer.rb +20 -11
  30. data/lib/twitter_cldr/tokenizers/calendars/datetime_tokenizer.rb +50 -13
  31. data/lib/twitter_cldr/tokenizers/calendars/time_tokenizer.rb +19 -10
  32. data/lib/twitter_cldr/tokenizers/calendars/timespan_tokenizer.rb +32 -32
  33. data/lib/twitter_cldr/tokenizers/numbers/number_tokenizer.rb +45 -22
  34. data/lib/twitter_cldr/utils.rb +16 -1
  35. data/lib/twitter_cldr/version.rb +1 -1
  36. data/resources/collation/tailoring/af.yml +1 -0
  37. data/resources/collation/tailoring/ar.yml +3 -2
  38. data/resources/collation/tailoring/be.yml +7 -0
  39. data/resources/collation/tailoring/bg.yml +5 -0
  40. data/resources/collation/tailoring/bn.yml +9 -0
  41. data/resources/collation/tailoring/ca.yml +3 -2
  42. data/resources/collation/tailoring/cs.yml +3 -2
  43. data/resources/collation/tailoring/cy.yml +51 -0
  44. data/resources/collation/tailoring/da.yml +3 -2
  45. data/resources/collation/tailoring/de.yml +1 -0
  46. data/resources/collation/tailoring/el.yml +1 -0
  47. data/resources/collation/tailoring/en.yml +1 -0
  48. data/resources/collation/tailoring/es.yml +3 -2
  49. data/resources/collation/tailoring/eu.yml +1 -0
  50. data/resources/collation/tailoring/fa.yml +3 -2
  51. data/resources/collation/tailoring/fi.yml +3 -2
  52. data/resources/collation/tailoring/fil.yml +3 -2
  53. data/resources/collation/tailoring/fr.yml +1 -0
  54. data/resources/collation/tailoring/ga.yml +5 -0
  55. data/resources/collation/tailoring/gl.yml +5 -0
  56. data/resources/collation/tailoring/he.yml +1 -0
  57. data/resources/collation/tailoring/hi.yml +3 -2
  58. data/resources/collation/tailoring/hu.yml +3 -2
  59. data/resources/collation/tailoring/id.yml +1 -0
  60. data/resources/collation/tailoring/it.yml +1 -0
  61. data/resources/collation/tailoring/ja.yml +107 -54
  62. data/resources/collation/tailoring/ko.yml +3 -2
  63. data/resources/collation/tailoring/lv.yml +35 -0
  64. data/resources/collation/tailoring/ms.yml +1 -0
  65. data/resources/collation/tailoring/nb.yml +3 -2
  66. data/resources/collation/tailoring/nl.yml +1 -0
  67. data/resources/collation/tailoring/pl.yml +3 -2
  68. data/resources/collation/tailoring/pt.yml +1 -0
  69. data/resources/collation/tailoring/ro.yml +31 -0
  70. data/resources/collation/tailoring/ru.yml +1 -0
  71. data/resources/collation/tailoring/sk.yml +35 -0
  72. data/resources/collation/tailoring/sq.yml +65 -0
  73. data/resources/collation/tailoring/sr.yml +5 -0
  74. data/resources/collation/tailoring/sv.yml +3 -2
  75. data/resources/collation/tailoring/ta.yml +57 -0
  76. data/resources/collation/tailoring/th.yml +3 -2
  77. data/resources/collation/tailoring/tr.yml +3 -2
  78. data/resources/collation/tailoring/uk.yml +3 -2
  79. data/resources/collation/tailoring/ur.yml +3 -2
  80. data/resources/collation/tailoring/zh-Hant.yml +3 -2
  81. data/resources/collation/tailoring/zh.yml +3 -2
  82. data/resources/collation/tries/be.dump +0 -0
  83. data/resources/collation/tries/bg.dump +0 -0
  84. data/resources/collation/tries/bn.dump +0 -0
  85. data/resources/collation/tries/cy.dump +0 -0
  86. data/resources/collation/tries/ga.dump +0 -0
  87. data/resources/collation/tries/gl.dump +0 -0
  88. data/resources/collation/tries/lv.dump +0 -0
  89. data/resources/collation/tries/ro.dump +0 -0
  90. data/resources/collation/tries/sk.dump +0 -0
  91. data/resources/collation/tries/sq.dump +0 -0
  92. data/resources/collation/tries/sr.dump +0 -0
  93. data/resources/collation/tries/ta.dump +0 -0
  94. data/resources/custom/locales/ar/units.yml +6 -6
  95. data/resources/custom/locales/be/units.yml +27 -0
  96. data/resources/custom/locales/bg/units.yml +19 -0
  97. data/resources/custom/locales/bn/units.yml +7 -0
  98. data/resources/custom/locales/cs/units.yml +3 -3
  99. data/resources/custom/locales/cy/units.yml +35 -0
  100. data/resources/custom/locales/fil/units.yml +2 -2
  101. data/resources/custom/locales/ga/units.yml +24 -0
  102. data/resources/custom/locales/gl/units.yml +19 -0
  103. data/resources/custom/locales/hu/plurals.yml +3 -0
  104. data/resources/custom/locales/hu/units.yml +4 -0
  105. data/resources/custom/locales/lv/units.yml +23 -0
  106. data/resources/custom/locales/ms/units.yml +1 -1
  107. data/resources/custom/locales/ro/units.yml +23 -0
  108. data/resources/custom/locales/sk/units.yml +23 -0
  109. data/resources/custom/locales/sr/units.yml +27 -0
  110. data/resources/custom/locales/ta/units.yml +11 -0
  111. data/resources/custom/locales/th/calendars.yml +14 -0
  112. data/resources/locales/af/calendars.yml +56 -0
  113. data/resources/locales/af/currencies.yml +358 -0
  114. data/resources/locales/af/languages.yml +23 -3
  115. data/resources/locales/af/numbers.yml +22 -8
  116. data/resources/locales/af/units.yml +26 -54
  117. data/resources/locales/ar/calendars.yml +99 -6
  118. data/resources/locales/ar/currencies.yml +1491 -0
  119. data/resources/locales/ar/languages.yml +33 -6
  120. data/resources/locales/ar/numbers.yml +27 -14
  121. data/resources/locales/ar/units.yml +31 -31
  122. data/resources/locales/be/calendars.yml +229 -0
  123. data/resources/locales/be/currencies.yml +66 -0
  124. data/resources/locales/be/languages.yml +149 -0
  125. data/resources/locales/be/layout.yml +4 -0
  126. data/resources/locales/be/lists.yml +7 -0
  127. data/resources/locales/be/numbers.yml +43 -0
  128. data/resources/locales/be/plurals.yml +5 -0
  129. data/resources/locales/be/units.yml +87 -0
  130. data/resources/locales/bg/calendars.yml +220 -0
  131. data/resources/locales/bg/currencies.yml +773 -0
  132. data/resources/locales/bg/languages.yml +513 -0
  133. data/resources/locales/bg/layout.yml +4 -0
  134. data/resources/locales/bg/lists.yml +7 -0
  135. data/resources/locales/bg/numbers.yml +57 -0
  136. data/resources/locales/bg/plurals.yml +3 -0
  137. data/resources/locales/bg/units.yml +108 -0
  138. data/resources/locales/bn/calendars.yml +205 -0
  139. data/resources/locales/bn/currencies.yml +564 -0
  140. data/resources/locales/bn/languages.yml +513 -0
  141. data/resources/locales/bn/layout.yml +4 -0
  142. data/resources/locales/bn/lists.yml +7 -0
  143. data/resources/locales/bn/numbers.yml +57 -0
  144. data/resources/locales/bn/plurals.yml +3 -0
  145. data/resources/locales/bn/units.yml +108 -0
  146. data/resources/locales/ca/calendars.yml +70 -21
  147. data/resources/locales/ca/currencies.yml +904 -0
  148. data/resources/locales/ca/languages.yml +70 -5
  149. data/resources/locales/ca/numbers.yml +19 -6
  150. data/resources/locales/ca/units.yml +0 -28
  151. data/resources/locales/cs/calendars.yml +73 -27
  152. data/resources/locales/cs/currencies.yml +1063 -0
  153. data/resources/locales/cs/languages.yml +113 -31
  154. data/resources/locales/cs/numbers.yml +17 -4
  155. data/resources/locales/cs/units.yml +0 -28
  156. data/resources/locales/cy/calendars.yml +266 -0
  157. data/resources/locales/cy/currencies.yml +54 -0
  158. data/resources/locales/cy/languages.yml +92 -0
  159. data/resources/locales/cy/layout.yml +4 -0
  160. data/resources/locales/cy/lists.yml +7 -0
  161. data/resources/locales/cy/numbers.yml +49 -0
  162. data/resources/locales/cy/plurals.yml +4 -0
  163. data/resources/locales/cy/units.yml +73 -0
  164. data/resources/locales/da/calendars.yml +117 -16
  165. data/resources/locales/da/currencies.yml +814 -0
  166. data/resources/locales/da/languages.yml +66 -5
  167. data/resources/locales/da/numbers.yml +16 -3
  168. data/resources/locales/da/units.yml +21 -35
  169. data/resources/locales/de/calendars.yml +115 -17
  170. data/resources/locales/de/currencies.yml +843 -0
  171. data/resources/locales/de/languages.yml +5 -3
  172. data/resources/locales/de/numbers.yml +18 -5
  173. data/resources/locales/de/units.yml +0 -28
  174. data/resources/locales/el/calendars.yml +61 -8
  175. data/resources/locales/el/currencies.yml +866 -0
  176. data/resources/locales/el/languages.yml +61 -5
  177. data/resources/locales/el/numbers.yml +18 -5
  178. data/resources/locales/el/units.yml +7 -42
  179. data/resources/locales/en/calendars.yml +43 -4
  180. data/resources/locales/en/currencies.yml +912 -0
  181. data/resources/locales/en/languages.yml +26 -6
  182. data/resources/locales/en/numbers.yml +17 -4
  183. data/resources/locales/es/calendars.yml +60 -0
  184. data/resources/locales/es/currencies.yml +820 -0
  185. data/resources/locales/es/languages.yml +66 -1
  186. data/resources/locales/es/numbers.yml +20 -7
  187. data/resources/locales/es/units.yml +0 -28
  188. data/resources/locales/eu/calendars.yml +43 -2
  189. data/resources/locales/eu/currencies.yml +378 -0
  190. data/resources/locales/eu/languages.yml +29 -13
  191. data/resources/locales/eu/numbers.yml +17 -4
  192. data/resources/locales/eu/units.yml +22 -43
  193. data/resources/locales/fa/calendars.yml +57 -0
  194. data/resources/locales/fa/currencies.yml +449 -0
  195. data/resources/locales/fa/languages.yml +8 -3
  196. data/resources/locales/fa/numbers.yml +20 -7
  197. data/resources/locales/fa/units.yml +0 -42
  198. data/resources/locales/fi/calendars.yml +49 -1
  199. data/resources/locales/fi/currencies.yml +903 -0
  200. data/resources/locales/fi/languages.yml +58 -2
  201. data/resources/locales/fi/numbers.yml +25 -12
  202. data/resources/locales/fi/units.yml +0 -28
  203. data/resources/locales/fil/calendars.yml +51 -0
  204. data/resources/locales/fil/currencies.yml +357 -0
  205. data/resources/locales/fil/languages.yml +25 -8
  206. data/resources/locales/fil/numbers.yml +18 -5
  207. data/resources/locales/fil/units.yml +14 -28
  208. data/resources/locales/fr/calendars.yml +114 -12
  209. data/resources/locales/fr/currencies.yml +884 -0
  210. data/resources/locales/fr/languages.yml +43 -9
  211. data/resources/locales/fr/numbers.yml +22 -9
  212. data/resources/locales/fr/units.yml +2 -30
  213. data/resources/locales/ga/calendars.yml +187 -0
  214. data/resources/locales/ga/currencies.yml +513 -0
  215. data/resources/locales/ga/languages.yml +147 -0
  216. data/resources/locales/ga/layout.yml +4 -0
  217. data/resources/locales/ga/lists.yml +7 -0
  218. data/resources/locales/ga/numbers.yml +43 -0
  219. data/resources/locales/ga/plurals.yml +4 -0
  220. data/resources/locales/ga/units.yml +66 -0
  221. data/resources/locales/gl/calendars.yml +216 -0
  222. data/resources/locales/gl/currencies.yml +476 -0
  223. data/resources/locales/gl/languages.yml +213 -0
  224. data/resources/locales/gl/layout.yml +4 -0
  225. data/resources/locales/gl/lists.yml +7 -0
  226. data/resources/locales/gl/numbers.yml +57 -0
  227. data/resources/locales/gl/plurals.yml +3 -0
  228. data/resources/locales/gl/units.yml +108 -0
  229. data/resources/locales/he/calendars.yml +70 -18
  230. data/resources/locales/he/currencies.yml +497 -0
  231. data/resources/locales/he/languages.yml +301 -7
  232. data/resources/locales/he/lists.yml +2 -2
  233. data/resources/locales/he/numbers.yml +23 -8
  234. data/resources/locales/he/plurals.yml +3 -2
  235. data/resources/locales/he/units.yml +72 -30
  236. data/resources/locales/hi/calendars.yml +54 -1
  237. data/resources/locales/hi/currencies.yml +388 -0
  238. data/resources/locales/hi/languages.yml +2 -0
  239. data/resources/locales/hi/numbers.yml +21 -8
  240. data/resources/locales/hi/units.yml +15 -29
  241. data/resources/locales/hu/calendars.yml +52 -5
  242. data/resources/locales/hu/currencies.yml +640 -0
  243. data/resources/locales/hu/languages.yml +60 -4
  244. data/resources/locales/hu/numbers.yml +25 -12
  245. data/resources/locales/hu/units.yml +1 -29
  246. data/resources/locales/id/calendars.yml +125 -21
  247. data/resources/locales/id/currencies.yml +603 -0
  248. data/resources/locales/id/languages.yml +113 -51
  249. data/resources/locales/id/numbers.yml +16 -3
  250. data/resources/locales/id/units.yml +0 -28
  251. data/resources/locales/it/calendars.yml +59 -6
  252. data/resources/locales/it/currencies.yml +722 -0
  253. data/resources/locales/it/languages.yml +77 -5
  254. data/resources/locales/it/numbers.yml +22 -9
  255. data/resources/locales/it/units.yml +0 -14
  256. data/resources/locales/ja/calendars.yml +55 -5
  257. data/resources/locales/ja/currencies.yml +602 -0
  258. data/resources/locales/ja/languages.yml +103 -43
  259. data/resources/locales/ja/numbers.yml +18 -5
  260. data/resources/locales/ja/units.yml +6 -34
  261. data/resources/locales/ko/calendars.yml +50 -0
  262. data/resources/locales/ko/currencies.yml +596 -0
  263. data/resources/locales/ko/languages.yml +75 -8
  264. data/resources/locales/ko/numbers.yml +17 -4
  265. data/resources/locales/ko/units.yml +0 -28
  266. data/resources/locales/lv/calendars.yml +275 -0
  267. data/resources/locales/lv/currencies.yml +765 -0
  268. data/resources/locales/lv/languages.yml +576 -0
  269. data/resources/locales/lv/layout.yml +4 -0
  270. data/resources/locales/lv/lists.yml +7 -0
  271. data/resources/locales/lv/numbers.yml +58 -0
  272. data/resources/locales/lv/plurals.yml +4 -0
  273. data/resources/locales/lv/units.yml +136 -0
  274. data/resources/locales/ms/calendars.yml +86 -4
  275. data/resources/locales/ms/currencies.yml +341 -0
  276. data/resources/locales/ms/languages.yml +25 -3
  277. data/resources/locales/ms/numbers.yml +19 -6
  278. data/resources/locales/ms/units.yml +0 -56
  279. data/resources/locales/nb/calendars.yml +48 -1
  280. data/resources/locales/nb/currencies.yml +846 -0
  281. data/resources/locales/nb/languages.yml +44 -2
  282. data/resources/locales/nb/numbers.yml +16 -3
  283. data/resources/locales/nb/units.yml +6 -28
  284. data/resources/locales/nl/calendars.yml +110 -9
  285. data/resources/locales/nl/currencies.yml +640 -0
  286. data/resources/locales/nl/languages.yml +68 -8
  287. data/resources/locales/nl/numbers.yml +25 -12
  288. data/resources/locales/nl/units.yml +14 -28
  289. data/resources/locales/pl/calendars.yml +53 -6
  290. data/resources/locales/pl/currencies.yml +1100 -0
  291. data/resources/locales/pl/languages.yml +13 -6
  292. data/resources/locales/pl/lists.yml +2 -2
  293. data/resources/locales/pl/numbers.yml +18 -5
  294. data/resources/locales/pl/units.yml +51 -92
  295. data/resources/locales/pt/calendars.yml +121 -9
  296. data/resources/locales/pt/currencies.yml +904 -0
  297. data/resources/locales/pt/languages.yml +5 -3
  298. data/resources/locales/pt/numbers.yml +17 -4
  299. data/resources/locales/pt/units.yml +0 -28
  300. data/resources/locales/ro/calendars.yml +278 -0
  301. data/resources/locales/ro/currencies.yml +946 -0
  302. data/resources/locales/ro/languages.yml +576 -0
  303. data/resources/locales/ro/layout.yml +4 -0
  304. data/resources/locales/ro/lists.yml +7 -0
  305. data/resources/locales/ro/numbers.yml +58 -0
  306. data/resources/locales/ro/plurals.yml +3 -0
  307. data/resources/locales/ro/units.yml +136 -0
  308. data/resources/locales/ru/calendars.yml +72 -12
  309. data/resources/locales/ru/currencies.yml +1061 -0
  310. data/resources/locales/ru/languages.yml +51 -6
  311. data/resources/locales/ru/numbers.yml +21 -5
  312. data/resources/locales/ru/units.yml +0 -28
  313. data/resources/locales/sk/calendars.yml +275 -0
  314. data/resources/locales/sk/currencies.yml +713 -0
  315. data/resources/locales/sk/languages.yml +576 -0
  316. data/resources/locales/sk/layout.yml +4 -0
  317. data/resources/locales/sk/lists.yml +7 -0
  318. data/resources/locales/sk/numbers.yml +58 -0
  319. data/resources/locales/sk/plurals.yml +3 -0
  320. data/resources/locales/sk/units.yml +136 -0
  321. data/resources/locales/sq/calendars.yml +188 -0
  322. data/resources/locales/sq/currencies.yml +56 -0
  323. data/resources/locales/sq/languages.yml +17 -0
  324. data/resources/locales/sq/layout.yml +4 -0
  325. data/resources/locales/sq/lists.yml +7 -0
  326. data/resources/locales/sq/numbers.yml +43 -0
  327. data/resources/locales/sq/plurals.yml +3 -0
  328. data/resources/locales/sq/units.yml +73 -0
  329. data/resources/locales/sr/calendars.yml +285 -0
  330. data/resources/locales/sr/currencies.yml +1494 -0
  331. data/resources/locales/sr/languages.yml +513 -0
  332. data/resources/locales/sr/layout.yml +4 -0
  333. data/resources/locales/sr/lists.yml +7 -0
  334. data/resources/locales/sr/numbers.yml +59 -0
  335. data/resources/locales/sr/plurals.yml +5 -0
  336. data/resources/locales/sr/units.yml +164 -0
  337. data/resources/locales/sv/calendars.yml +59 -1
  338. data/resources/locales/sv/currencies.yml +919 -0
  339. data/resources/locales/sv/languages.yml +47 -2
  340. data/resources/locales/sv/numbers.yml +27 -12
  341. data/resources/locales/sv/units.yml +4 -32
  342. data/resources/locales/ta/calendars.yml +264 -0
  343. data/resources/locales/ta/currencies.yml +346 -0
  344. data/resources/locales/ta/languages.yml +512 -0
  345. data/resources/locales/ta/layout.yml +4 -0
  346. data/resources/locales/ta/lists.yml +7 -0
  347. data/resources/locales/ta/numbers.yml +57 -0
  348. data/resources/locales/ta/plurals.yml +3 -0
  349. data/resources/locales/ta/units.yml +108 -0
  350. data/resources/locales/th/calendars.yml +125 -27
  351. data/resources/locales/th/currencies.yml +602 -0
  352. data/resources/locales/th/languages.yml +70 -5
  353. data/resources/locales/th/numbers.yml +24 -11
  354. data/resources/locales/th/units.yml +0 -28
  355. data/resources/locales/tr/calendars.yml +62 -12
  356. data/resources/locales/tr/currencies.yml +571 -0
  357. data/resources/locales/tr/languages.yml +94 -29
  358. data/resources/locales/tr/numbers.yml +19 -6
  359. data/resources/locales/tr/units.yml +1 -29
  360. data/resources/locales/uk/calendars.yml +52 -0
  361. data/resources/locales/uk/currencies.yml +799 -0
  362. data/resources/locales/uk/languages.yml +57 -2
  363. data/resources/locales/uk/numbers.yml +18 -5
  364. data/resources/locales/uk/units.yml +0 -28
  365. data/resources/locales/ur/calendars.yml +96 -32
  366. data/resources/locales/ur/currencies.yml +360 -0
  367. data/resources/locales/ur/languages.yml +49 -32
  368. data/resources/locales/ur/numbers.yml +13 -13
  369. data/resources/locales/ur/units.yml +28 -56
  370. data/resources/locales/zh-Hant/calendars.yml +59 -1
  371. data/resources/locales/zh-Hant/currencies.yml +602 -0
  372. data/resources/locales/zh-Hant/languages.yml +74 -8
  373. data/resources/locales/zh-Hant/numbers.yml +17 -4
  374. data/resources/locales/zh-Hant/units.yml +0 -28
  375. data/resources/locales/zh/calendars.yml +95 -35
  376. data/resources/locales/zh/currencies.yml +602 -0
  377. data/resources/locales/zh/languages.yml +116 -46
  378. data/resources/locales/zh/numbers.yml +20 -7
  379. data/resources/locales/zh/units.yml +6 -34
  380. data/resources/shared/currency_digits_and_rounding.yml +187 -0
  381. data/spec/bidi/bidi_spec.rb +1 -1
  382. data/spec/collation/tailoring_spec.rb +29 -25
  383. data/spec/formatters/calendars/datetime_formatter_spec.rb +50 -2
  384. data/spec/formatters/calendars/timespan_formatter_spec.rb +52 -8
  385. data/spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb +81 -0
  386. data/spec/formatters/numbers/abbreviated/long_decimal_formatter_spec.rb +37 -0
  387. data/spec/formatters/numbers/abbreviated/short_decimal_formatter_spec.rb +37 -0
  388. data/spec/formatters/numbers/currency_formatter_spec.rb +10 -1
  389. data/spec/localized/localized_date_spec.rb +11 -11
  390. data/spec/localized/localized_datetime_spec.rb +27 -3
  391. data/spec/localized/localized_number_spec.rb +34 -6
  392. data/spec/localized/localized_time_spec.rb +1 -1
  393. data/spec/readme_spec.rb +24 -3
  394. data/spec/shared/currencies_spec.rb +7 -9
  395. data/spec/spec_helper.rb +7 -0
  396. data/spec/tokenizers/base_spec.rb +71 -21
  397. data/spec/tokenizers/calendars/additional_date_format_selector_spec.rb +131 -0
  398. data/spec/tokenizers/calendars/datetime_tokenizer_spec.rb +54 -27
  399. data/spec/tokenizers/calendars/time_tokenizer_spec.rb +16 -16
  400. data/spec/tokenizers/numbers/number_tokenizer_spec.rb +9 -21
  401. data/spec/utils/yaml/yaml_spec.rb +21 -16
  402. data/spec/utils_spec.rb +6 -2
  403. metadata +218 -37
@@ -61,7 +61,7 @@ describe LocalizedTime do
61
61
  describe 'formatters' do
62
62
  it "don't raise errors for any locale" do
63
63
  TwitterCldr.supported_locales.each do |locale|
64
- TwitterCldr::Tokenizers::DateTimeTokenizer::VALID_TYPES.each do |type|
64
+ (TwitterCldr::Tokenizers::DateTimeTokenizer::VALID_TYPES - [:additional]).each do |type|
65
65
  lambda { Time.now.localize(locale).send(:"to_#{type}_s") }.should_not raise_error
66
66
  end
67
67
  end
data/spec/readme_spec.rb CHANGED
@@ -26,7 +26,7 @@ describe "README" do
26
26
  1337.localize(:es).to_s.should == "1.337"
27
27
  spaces(1337.localize(:es).to_currency.to_s).should == "1.337,00 $"
28
28
  spaces(1337.localize(:es).to_currency.to_s(:currency => "EUR").to_s).should == "1.337,00 €"
29
- spaces(1337.localize(:es).to_currency.to_s(:currency => "Peru").to_s).should == "1.337,00 S/."
29
+ spaces(1337.localize(:es).to_currency.to_s(:currency => "Peru").to_s).should == "1.337,00 PEN"
30
30
  1337.localize(:es).to_percent.to_s.should == "1.337%"
31
31
  1337.localize(:es).to_percent.to_s(:precision => 2).should == "1.337,00%"
32
32
  1337.localize(:es).to_decimal.to_s(:precision => 3).should == "1.337,000"
@@ -46,8 +46,16 @@ describe "README" do
46
46
  currency_codes.should include("LTL")
47
47
  currency_codes.should include("PHP")
48
48
 
49
- TwitterCldr::Shared::Currencies.for_country("Canada").should == { :currency => "Dollar", :symbol => "$", :code => "CAD" }
50
- TwitterCldr::Shared::Currencies.for_code("CAD").should == { :currency => "Dollar", :symbol => "$", :country => "Canada"}
49
+ TwitterCldr::Shared::Currencies.for_country("Canada").should == { :currency => :CAD, :symbol => "CA$", :name => "Canadian dollar"}
50
+ TwitterCldr::Shared::Currencies.for_code("CAD").should == { :currency => :CAD, :symbol => "CA$", :name => "Canadian dollar"}
51
+ end
52
+
53
+ it "verifies short and long decimals" do
54
+ 2337.localize.to_short_decimal.to_s.should == "2K"
55
+ 1337123.localize.to_short_decimal.to_s.should == "1M"
56
+
57
+ 2337.localize.to_long_decimal.to_s.should == "2 thousand"
58
+ 1337123.localize.to_long_decimal.to_s.should == "1 million"
51
59
  end
52
60
 
53
61
  it "verifies dates" do
@@ -74,6 +82,13 @@ describe "README" do
74
82
  dt.to_short_s.should == "12/12/11 21:44"
75
83
  end
76
84
 
85
+ it "verifies additional date formats" do
86
+ date_time = DateTime.new(2011, 12, 12, 21, 44, 57, -8.0 / 24.0)
87
+ TwitterCldr::Formatters::DateTimeFormatter.additional_formats_for(:ja).should be_a(Array)
88
+ date_time.localize(:ja).to_s.should == "2011/12/12 21:44:57"
89
+ date_time.localize(:ja).to_s(:format => "EEEEd").should == "12日月曜日"
90
+ end
91
+
77
92
  it "verifies relative time spans" do
78
93
  (DateTime.now - 1).localize.ago.to_s.should match_normalized("1 day ago")
79
94
  (DateTime.now - 0.5).localize.ago.to_s.should match_normalized("12 hours ago") # (i.e. half a day)
@@ -99,6 +114,12 @@ describe "README" do
99
114
  ts.to_s(:unit => :hour).should match_normalized("Vor 24 Stunden")
100
115
  end
101
116
 
117
+ it "verifies approximate timespans" do
118
+ TwitterCldr::Localized::LocalizedTimespan.new(44).to_s(:approximate => true).should == "In 44 seconds"
119
+ TwitterCldr::Localized::LocalizedTimespan.new(45).to_s(:approximate => true).should == "In 1 minute"
120
+ TwitterCldr::Localized::LocalizedTimespan.new(52).to_s(:approximate => true).should == "In 1 minute"
121
+ end
122
+
102
123
  it "verifies plural rules" do
103
124
  1.localize(:ru).plural_rule.should == :one
104
125
  2.localize(:ru).plural_rule.should == :few
@@ -24,7 +24,7 @@ describe Currencies do
24
24
  it "should list all supported country codes" do
25
25
  codes = Currencies.currency_codes
26
26
 
27
- codes.size.should == 112
27
+ codes.size.should == 296
28
28
  codes.should include(*TEST_CODES)
29
29
  end
30
30
  end
@@ -34,11 +34,10 @@ describe Currencies do
34
34
  data = Currencies.for_country("Peru")
35
35
 
36
36
  data.should be_a(Hash)
37
- data.should_not include(:country)
38
37
  data.should include(
39
- :code => "PEN",
40
- :currency => "Nuevo Sol",
41
- :symbol => "S/."
38
+ :currency => :PEN,
39
+ :name => "Peruvian nuevo sol",
40
+ :symbol => nil
42
41
  )
43
42
  end
44
43
  end
@@ -48,11 +47,10 @@ describe Currencies do
48
47
  data = Currencies.for_code("PEN")
49
48
 
50
49
  data.should be_a(Hash)
51
- data.should_not include(:code)
52
50
  data.should include(
53
- :country => "Peru",
54
- :currency => "Nuevo Sol",
55
- :symbol => "S/."
51
+ :name => "Peruvian nuevo sol",
52
+ :currency => :PEN,
53
+ :symbol => nil
56
54
  )
57
55
  end
58
56
  end
data/spec/spec_helper.rb CHANGED
@@ -4,8 +4,15 @@
4
4
  # http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
6
  require 'rspec'
7
+ require 'rspec/autorun' # somehow makes rcov work with rspec
7
8
  require 'twitter_cldr'
8
9
 
10
+ if ENV['SCOV']
11
+ require 'simplecov'
12
+ SimpleCov.start
13
+ puts 'Running simplecov'
14
+ end
15
+
9
16
  class FastGettext
10
17
  class << self
11
18
  @@locale = :en
@@ -15,7 +15,7 @@ module TwitterCldr
15
15
  end
16
16
  end
17
17
 
18
- describe Base do
18
+ describe TwitterCldr::Tokenizers::Base do
19
19
  before(:each) do
20
20
  @base = TwitterCldr::Tokenizers::Base.new # do NOT do this in production - must use subclass
21
21
  end
@@ -86,23 +86,26 @@ describe Base do
86
86
 
87
87
  describe "#expand_pattern" do
88
88
  it "recursively calls expand_pattern if a symbol (keypath) is given" do
89
+ @base.type = :fake_type
89
90
  mock(@base).traverse([:another, :path]) { "found_me" }
90
91
  mock(@base).pattern_for("found_me") { "pattern_text" }
91
- mock.proxy(@base).expand_pattern("pattern_text", :fake_type)
92
- mock.proxy(@base).expand_pattern(:'another.path', :fake_type)
93
- @base.send(:expand_pattern, :'another.path', :fake_type).should == [{ :value => "pattern_text", :type => :plaintext }]
92
+ mock.proxy(@base).expand_pattern("pattern_text")
93
+ mock.proxy(@base).expand_pattern(:'another.path')
94
+ @base.send(:expand_pattern, :'another.path').should == [{ :value => "pattern_text", :type => :plaintext }]
94
95
  end
95
96
 
96
97
  it "expands placeholders as necessary" do
97
98
  placeholder_obj = Object.new
98
99
  mock(placeholder_obj).tokens(:type => :man) { ["token1", "token2"] }
99
100
  @base.placeholders = [{ :name => "wallace", :object => placeholder_obj }]
100
- @base.send(:expand_pattern, "{{wallace}} rules", :man).should == ["token1", "token2", { :type => :plaintext, :value => " rules" }]
101
+ @base.type = :man
102
+ @base.send(:expand_pattern, "{{wallace}} rules").should == ["token1", "token2", { :type => :plaintext, :value => " rules" }]
101
103
  end
102
104
 
103
105
  it "doesn't choke if the placeholder can't be found" do
104
106
  @base.placeholders = [{ :name => "gromit", :object => "dog" }]
105
- @base.send(:expand_pattern, "{{wallace}} rules", :man).should == [{ :type => :plaintext, :value => " rules" }]
107
+ @base.type = :man
108
+ @base.send(:expand_pattern, "{{wallace}} rules").should == [{ :type => :plaintext, :value => " rules" }]
106
109
  end
107
110
  end
108
111
 
@@ -113,34 +116,37 @@ describe Base do
113
116
  before(:each) do
114
117
  stub(@base).traverse([:fake_key]) { "fake_pattern" }
115
118
  stub(@base).pattern_for("fake_pattern") { "fake_expandable_pattern" }
116
- stub(@base).expand_pattern("fake_expandable_pattern", "fake_type") { [token1, token2] }
119
+ stub(@base).expand_pattern("fake_expandable_pattern") { [token1, token2] }
117
120
  end
118
121
 
119
122
  it "caches tokens" do
120
- result = @base.send(:tokens_for, [:fake_key], "fake_type")
123
+ @base.type = "fake_type"
124
+ result = @base.send(:tokens_for, [:fake_key])
121
125
  result[0].value.should == "token1"
122
126
  result[1].value.should == "token2"
123
- @base.class.send(:class_variable_get, :'@@token_cache')["en|fake_key|fake_type".hash].should == result
127
+ @base.class.send(:class_variable_get, :'@@token_cache')["en|fake_key|fake_type|nil".hash].should == result
124
128
 
125
- result_again = @base.send(:tokens_for, [:fake_key], "fake_type")
129
+ @base.type = "fake_type"
130
+ result_again = @base.send(:tokens_for, [:fake_key])
126
131
  result_again.object_id.should == result.object_id
127
132
  end
128
133
 
129
134
  it "caches tokens per language" do
130
- result_en = @base.send(:tokens_for, [:fake_key], "fake_type")
135
+ @base.type = "fake_type"
136
+ result_en = @base.send(:tokens_for, [:fake_key])
131
137
  result_en[0].value.should == "token1"
132
138
  result_en[1].value.should == "token2"
133
- @base.class.send(:class_variable_get, :'@@token_cache')["en|fake_key|fake_type".hash].should == result_en
134
- result_en2 = @base.send(:tokens_for, [:fake_key], "fake_type")
139
+ @base.class.send(:class_variable_get, :'@@token_cache')["en|fake_key|fake_type|nil".hash].should == result_en
140
+ result_en2 = @base.send(:tokens_for, [:fake_key])
135
141
  result_en2.object_id.should == result_en.object_id
136
142
 
137
143
  @base.instance_variable_set(:'@locale', :pt)
138
- result_pt = @base.send(:tokens_for, [:fake_key], "fake_type")
144
+ result_pt = @base.send(:tokens_for, [:fake_key])
139
145
  result_pt[0].value.should == "token1"
140
146
  result_pt[1].value.should == "token2"
141
- @base.class.send(:class_variable_get, :'@@token_cache')["pt|fake_key|fake_type".hash].should == result_pt
147
+ @base.class.send(:class_variable_get, :'@@token_cache')["pt|fake_key|fake_type|nil".hash].should == result_pt
142
148
  result_pt.object_id.should_not == result_en.object_id
143
- result_pt2 = @base.send(:tokens_for, [:fake_key], "fake_type")
149
+ result_pt2 = @base.send(:tokens_for, [:fake_key])
144
150
  result_pt2.object_id.should == result_pt.object_id
145
151
  result_pt2.object_id.should_not == result_en.object_id
146
152
  result_pt2.object_id.should_not == result_en2.object_id
@@ -191,11 +197,21 @@ describe Base do
191
197
  # expanded format string into whatever parts are defined by the subclass's token type and token splitter regexes.
192
198
  describe "#tokenize_format" do
193
199
  it "assigns the right token types to the tokens" do
194
- stub(@base).token_splitter_regex { /([abc])/ }
195
- stub(@base).token_type_regexes { [{ :type => :a, :regex => /a/ },
196
- { :type => :b, :regex => /b/ },
197
- { :type => :c, :regex => /c/ },
198
- { :type => :plaintext, :regex => // }] }
200
+ stub(@base).token_splitter_regexes do
201
+ { :else => /([abc])/ }
202
+ end
203
+
204
+ stub(@base).token_type_regexes do
205
+ {
206
+ :else => {
207
+ :a => { :regex => /a/, :priority => 1 },
208
+ :b => { :regex => /b/, :priority => 1 },
209
+ :c => { :regex => /c/, :priority => 1 },
210
+ :plaintext => { :regex => //, :priority => 2 }
211
+ }
212
+ }
213
+ end
214
+
199
215
  tokens = @base.send(:tokenize_format, "a b c")
200
216
  tokens.size.should == 5
201
217
 
@@ -206,4 +222,38 @@ describe Base do
206
222
  tokens[4].value.should == "c"; tokens[4].type.should == :c
207
223
  end
208
224
  end
225
+
226
+ describe "#token_type_regexes_for" do
227
+ before(:each) do
228
+ @base.instance_variable_set(:'@token_type_regexes', {
229
+ :blarg => "blarg",
230
+ :else => "otherwise"
231
+ })
232
+ end
233
+
234
+ it "returns the correct regexes by name" do
235
+ @base.send(:token_type_regexes_for, :blarg).should == "blarg"
236
+ end
237
+
238
+ it "defaults to the regexes stored at :else if the name given can't be found" do
239
+ @base.send(:token_type_regexes_for, :foo).should == "otherwise"
240
+ end
241
+ end
242
+
243
+ describe "#token_splitter_regex_for" do
244
+ before(:each) do
245
+ @base.instance_variable_set(:'@token_splitter_regexes', {
246
+ :blarg => "blarg",
247
+ :else => "otherwise"
248
+ })
249
+ end
250
+
251
+ it "returns the correct regexes by name" do
252
+ @base.send(:token_splitter_regex_for, :blarg).should == "blarg"
253
+ end
254
+
255
+ it "defaults to the regexes stored at :else if the name given can't be found" do
256
+ @base.send(:token_splitter_regex_for, :foo).should == "otherwise"
257
+ end
258
+ end
209
259
  end
@@ -0,0 +1,131 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Twitter, Inc
4
+ # http://www.apache.org/licenses/LICENSE-2.0
5
+
6
+ require 'spec_helper'
7
+
8
+ include TwitterCldr::Tokenizers
9
+
10
+ describe AdditionalDateFormatSelector do
11
+ let(:selector) do
12
+ AdditionalDateFormatSelector.new(
13
+ TwitterCldr.get_locale_resource(:en, :calendars)[:en][:calendars][:gregorian][:additional_formats]
14
+ )
15
+ end
16
+
17
+ describe "#position_score" do
18
+ it "calculates the score based on relative offset from actual position" do
19
+ goal_entities = selector.send(:separate, "MMMyyd")
20
+ entities = selector.send(:separate, "d")
21
+ selector.send(:position_score, entities, goal_entities).should == 2
22
+ end
23
+
24
+ it "calculates a zero score if all entites are in the same positions" do
25
+ goal_entities = selector.send(:separate, "MMMyyd")
26
+ entities = selector.send(:separate, "MMMyyd")
27
+ selector.send(:position_score, entities, goal_entities).should == 0
28
+ end
29
+ end
30
+
31
+ describe "#exist_score" do
32
+ it "calculates a higher score if an entity doesn't exist" do
33
+ goal_entities = selector.send(:separate, "MMMd")
34
+ entities = selector.send(:separate, "d")
35
+ selector.send(:exist_score, entities, goal_entities).should == 1
36
+ end
37
+
38
+ it "calculates a zero score if all entities exist" do
39
+ goal_entities = selector.send(:separate, "MMMyyd")
40
+ entities = selector.send(:separate, "dMMMyy")
41
+ selector.send(:exist_score, entities, goal_entities).should == 0
42
+ end
43
+ end
44
+
45
+ describe "#count_score" do
46
+ it "calculates the score based on the difference in the length of each matching entity" do
47
+ goal_entities = selector.send(:separate, "MMMyyd")
48
+ entities = selector.send(:separate, "ddMMy")
49
+ selector.send(:count_score, entities, goal_entities).should == 3
50
+ end
51
+
52
+ it "calculates a zero score if all entities are the same length" do
53
+ goal_entities = selector.send(:separate, "MMMyyd")
54
+ entities = selector.send(:separate, "d")
55
+ selector.send(:count_score, entities, goal_entities).should == 0
56
+ end
57
+ end
58
+
59
+ describe "#score" do
60
+ it "calculates a cumulative score from position and count" do
61
+ goal_entities = selector.send(:separate, "MMMyydGG")
62
+ entities = selector.send(:separate, "ddMMGGyy")
63
+ selector.send(:exist_score, entities, goal_entities).should == 0
64
+ selector.send(:count_score, entities, goal_entities).should == 2
65
+ selector.send(:position_score, entities, goal_entities).should == 3
66
+ selector.send(:score, entities, goal_entities).should == 5
67
+ end
68
+
69
+ it "calculates a cumulative score from position, count, and existence (existence weighted by 2)" do
70
+ goal_entities = selector.send(:separate, "MMMyydGG")
71
+ entities = selector.send(:separate, "ddMMyy")
72
+ selector.send(:exist_score, entities, goal_entities).should == 1
73
+ selector.send(:count_score, entities, goal_entities).should == 2
74
+ selector.send(:position_score, entities, goal_entities).should == 1
75
+ # (exist_score * 2) + count_score + position_score
76
+ selector.send(:score, entities, goal_entities).should == 5
77
+ end
78
+ end
79
+
80
+ describe "#rank" do
81
+ it "returns a score for each available format" do
82
+ ranked_formats = selector.send(:rank, "MMMd")
83
+ ranked_formats["MMMd"].should == 0
84
+ ranked_formats["yMEd"].should == 4
85
+ ranked_formats["y"].should == 4
86
+ ranked_formats["EHms"].should == 4
87
+ ranked_formats["MMM"].should == 2
88
+ end
89
+ end
90
+
91
+ describe "#find_closest" do
92
+ it "returns an exact match if it exists" do
93
+ selector.find_closest("MMMd").should == "MMMd"
94
+ selector.find_closest("Hms").should == "Hms"
95
+ selector.find_closest("yQQQQ").should == "yQQQQ"
96
+ end
97
+
98
+ it "returns the next closest match (lowest score) if an exact match can't be found" do
99
+ selector.find_closest("MMMMd").should == "MMMd"
100
+ selector.find_closest("mHs").should == "Hms"
101
+ selector.find_closest("Med").should == "MEd"
102
+ end
103
+
104
+ it "returns nil if an empty pattern is given" do
105
+ selector.find_closest(nil).should be_nil
106
+ selector.find_closest("").should be_nil
107
+ selector.find_closest(" ").should be_nil
108
+ end
109
+ end
110
+
111
+ describe "#separate" do
112
+ it "divides a string into entities by runs of equal characters" do
113
+ selector.send(:separate, "ddMMyy").should == ["dd", "MM", "yy"]
114
+ selector.send(:separate, "ddMMyyMM").should == ["dd", "MM", "yy", "MM"]
115
+ selector.send(:separate, "mmMM").should == ["mm", "MM"]
116
+ end
117
+ end
118
+
119
+ describe "#patterns" do
120
+ it "returns a list of all available patterns" do
121
+ patterns = selector.patterns
122
+ patterns.should be_a(Array)
123
+ patterns.should include(:MMMd)
124
+ patterns.should include(:yQQQ)
125
+ patterns.should include(:yQQQQ)
126
+ patterns.should include(:EHms)
127
+ patterns.should include(:d)
128
+ end
129
+ end
130
+
131
+ end
@@ -8,6 +8,8 @@ require 'spec_helper'
8
8
  include TwitterCldr::Tokenizers
9
9
 
10
10
  describe DateTimeTokenizer do
11
+ let(:tokenizer) { DateTimeTokenizer.new }
12
+
11
13
  describe "#initialize" do
12
14
  it "chooses gregorian as the calendar type if none is specified" do
13
15
  DateTimeTokenizer.new.calendar_type.should == :gregorian
@@ -15,7 +17,7 @@ describe DateTimeTokenizer do
15
17
  end
16
18
 
17
19
  it "initializes individual date and time placeholder tokenizers" do
18
- placeholders = DateTimeTokenizer.new.placeholders
20
+ placeholders = tokenizer.placeholders
19
21
  placeholders[0][:name].should == :time
20
22
  placeholders[0][:object].should be_a(TimeTokenizer)
21
23
  placeholders[1][:name].should == :date
@@ -25,7 +27,6 @@ describe DateTimeTokenizer do
25
27
 
26
28
  describe "#tokens" do
27
29
  it "should choose the default date time path if no other type is specified" do
28
- tokenizer = DateTimeTokenizer.new
29
30
  mock.proxy(tokenizer.paths)[:default]
30
31
  tokenizer.tokens
31
32
  end
@@ -34,25 +35,25 @@ describe DateTimeTokenizer do
34
35
  tokenizer = DateTimeTokenizer.new(:locale => :es)
35
36
  got = tokenizer.tokens(:type => :full)
36
37
  expected = [
37
- { :value => "EEEE", :type => :pattern },
38
- { :value => ", ", :type => :plaintext },
39
- { :value => "d", :type => :pattern },
40
- { :value => " ", :type => :plaintext },
41
- { :value => "'de'", :type => :plaintext },
42
- { :value => " ", :type => :plaintext },
43
- { :value => "MMMM", :type => :pattern },
44
- { :value => " ", :type => :plaintext },
45
- { :value => "'de'", :type => :plaintext },
46
- { :value => " ", :type => :plaintext },
47
- { :value => "y", :type => :pattern },
48
- { :value => " ", :type => :plaintext },
49
- { :value => "HH", :type => :pattern },
50
- { :value => ":", :type => :plaintext },
51
- { :value => "mm", :type => :pattern },
52
- { :value => ":", :type => :plaintext },
53
- { :value => "ss", :type => :pattern },
54
- { :value => " ", :type => :plaintext },
55
- { :value => "zzzz", :type => :pattern },
38
+ { :value => "EEEE", :type => :pattern },
39
+ { :value => ", ", :type => :plaintext },
40
+ { :value => "d", :type => :pattern },
41
+ { :value => " ", :type => :plaintext },
42
+ { :value => "'de'", :type => :plaintext },
43
+ { :value => " ", :type => :plaintext },
44
+ { :value => "MMMM", :type => :pattern },
45
+ { :value => " ", :type => :plaintext },
46
+ { :value => "'de'", :type => :plaintext },
47
+ { :value => " ", :type => :plaintext },
48
+ { :value => "y", :type => :pattern },
49
+ { :value => " ", :type => :plaintext },
50
+ { :value => "HH", :type => :pattern },
51
+ { :value => ":", :type => :plaintext },
52
+ { :value => "mm", :type => :pattern },
53
+ { :value => ":", :type => :plaintext },
54
+ { :value => "ss", :type => :pattern },
55
+ { :value => " ", :type => :plaintext },
56
+ { :value => "zzzz", :type => :pattern }
56
57
  ]
57
58
  check_token_list(got, expected)
58
59
  end
@@ -61,17 +62,16 @@ describe DateTimeTokenizer do
61
62
  describe "#mirror_resource" do
62
63
  it "should add only the missing keys" do
63
64
  from = {
64
- :a => 1,
65
- :b => { :c => 2, :d => 3 },
66
- :e => { :f => 4 }
65
+ :a => 1,
66
+ :b => { :c => 2, :d => 3 },
67
+ :e => { :f => 4 }
67
68
  }
68
69
 
69
70
  to = {
70
- :b => { :c => 100 },
71
- :e => 101
71
+ :b => { :c => 100 },
72
+ :e => 101
72
73
  }
73
74
 
74
- tokenizer = DateTimeTokenizer.new
75
75
  tokenizer.send(:mirror_resource, :from => from, :to => to)
76
76
 
77
77
  to[:a].should == 1
@@ -88,4 +88,31 @@ describe DateTimeTokenizer do
88
88
  from[:e][:f].should == 4
89
89
  end
90
90
  end
91
+
92
+ describe "#merge_token_type_regexes" do
93
+ it "merges the token type regex hash recursively, uniting regexes" do
94
+ first = {
95
+ :type1 => { :regex => /a/, :content => /aa/, :priority => 1 },
96
+ :type2 => { :regex => /b/, :priority => 2 },
97
+ }
98
+
99
+ second = {
100
+ :type1 => { :regex => /c/, :content => /cc/, :priority => 1 },
101
+ :type2 => { :regex => /d/, :priority => 2 },
102
+ }
103
+
104
+ tokenizer.send(:merge_token_type_regexes, first, second).should == {
105
+ :type1 => { :regex => Regexp.union(/a/, /c/), :content => Regexp.union(/aa/, /cc/), :priority => 1 },
106
+ :type2 => { :regex => Regexp.union(/b/, /d/), :priority => 2 }
107
+ }
108
+ end
109
+ end
110
+
111
+ describe "#pattern_for" do
112
+ it "returns the closest matching pattern if this tokenizer has been set up to handle additional date formats" do
113
+ tokenizer.instance_variable_set(:'@type', :additional)
114
+ tokenizer.instance_variable_set(:'@format', "MMMd")
115
+ tokenizer.send(:pattern_for, { :MMMd => "found me!" }).should == "found me!"
116
+ end
117
+ end
91
118
  end