holidays 4.2.0 → 8.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (330) hide show
  1. checksums.yaml +5 -5
  2. data/.gitmodules +3 -0
  3. data/CHANGELOG.md +195 -0
  4. data/Makefile +45 -0
  5. data/README.md +253 -77
  6. data/Rakefile +10 -11
  7. data/bin/console +0 -0
  8. data/bin/setup +1 -0
  9. data/doc/CONTRIBUTING.md +72 -0
  10. data/doc/MAINTAINERS.md +81 -0
  11. data/{REFERENCES → doc/REFERENCES} +0 -0
  12. data/holidays.gemspec +9 -9
  13. data/lib/generated_definitions/MANIFEST +26 -4
  14. data/lib/generated_definitions/REGIONS.rb +3 -1
  15. data/lib/generated_definitions/ar.rb +4 -10
  16. data/lib/generated_definitions/at.rb +3 -9
  17. data/lib/generated_definitions/au.rb +32 -25
  18. data/lib/generated_definitions/be_fr.rb +2 -8
  19. data/lib/generated_definitions/be_nl.rb +2 -8
  20. data/lib/generated_definitions/bg.rb +2 -8
  21. data/lib/generated_definitions/br.rb +2 -8
  22. data/lib/generated_definitions/ca.rb +33 -32
  23. data/lib/generated_definitions/ch.rb +17 -11
  24. data/lib/generated_definitions/cl.rb +38 -12
  25. data/lib/generated_definitions/co.rb +121 -0
  26. data/lib/generated_definitions/cr.rb +2 -8
  27. data/lib/generated_definitions/cz.rb +2 -8
  28. data/lib/generated_definitions/de.rb +11 -14
  29. data/lib/generated_definitions/dk.rb +2 -8
  30. data/lib/generated_definitions/{ecb_target.rb → ecbtarget.rb} +10 -16
  31. data/lib/generated_definitions/ee.rb +36 -0
  32. data/lib/generated_definitions/el.rb +2 -8
  33. data/lib/generated_definitions/es.rb +8 -11
  34. data/lib/generated_definitions/europe.rb +121 -51
  35. data/lib/generated_definitions/federalreserve.rb +34 -0
  36. data/lib/generated_definitions/{federal_reserve.rb → federalreservebanks.rb} +14 -20
  37. data/lib/generated_definitions/fedex.rb +3 -9
  38. data/lib/generated_definitions/fi.rb +2 -8
  39. data/lib/generated_definitions/fr.rb +6 -10
  40. data/lib/generated_definitions/gb.rb +12 -16
  41. data/lib/generated_definitions/ge.rb +41 -0
  42. data/lib/generated_definitions/hk.rb +106 -0
  43. data/lib/generated_definitions/hr.rb +10 -14
  44. data/lib/generated_definitions/hu.rb +4 -9
  45. data/lib/generated_definitions/ie.rb +3 -17
  46. data/lib/generated_definitions/is.rb +3 -9
  47. data/lib/generated_definitions/it.rb +16 -13
  48. data/lib/generated_definitions/jp.rb +47 -36
  49. data/lib/generated_definitions/kr.rb +40 -0
  50. data/lib/generated_definitions/kz.rb +38 -0
  51. data/lib/generated_definitions/li.rb +2 -8
  52. data/lib/generated_definitions/lt.rb +2 -8
  53. data/lib/generated_definitions/lu.rb +35 -0
  54. data/lib/generated_definitions/lv.rb +52 -0
  55. data/lib/generated_definitions/ma.rb +2 -8
  56. data/lib/generated_definitions/mt_en.rb +38 -0
  57. data/lib/generated_definitions/mt_mt.rb +38 -0
  58. data/lib/generated_definitions/mx.rb +6 -12
  59. data/lib/generated_definitions/my.rb +30 -0
  60. data/lib/generated_definitions/nerc.rb +2 -8
  61. data/lib/generated_definitions/ng.rb +33 -0
  62. data/lib/generated_definitions/nl.rb +2 -8
  63. data/lib/generated_definitions/no.rb +2 -8
  64. data/lib/generated_definitions/northamerica.rb +223 -0
  65. data/lib/generated_definitions/nyse.rb +3 -9
  66. data/lib/generated_definitions/nz.rb +2 -9
  67. data/lib/generated_definitions/pe.rb +43 -0
  68. data/lib/generated_definitions/ph.rb +4 -10
  69. data/lib/generated_definitions/pl.rb +2 -8
  70. data/lib/generated_definitions/pt.rb +12 -12
  71. data/lib/generated_definitions/ro.rb +6 -9
  72. data/lib/generated_definitions/rs_cyrl.rb +39 -0
  73. data/lib/generated_definitions/rs_la.rb +39 -0
  74. data/lib/generated_definitions/ru.rb +37 -0
  75. data/lib/generated_definitions/scandinavia.rb +3 -9
  76. data/lib/generated_definitions/se.rb +2 -8
  77. data/lib/generated_definitions/sg.rb +2 -8
  78. data/lib/generated_definitions/si.rb +2 -8
  79. data/lib/generated_definitions/sk.rb +2 -8
  80. data/lib/generated_definitions/southamerica.rb +228 -0
  81. data/lib/generated_definitions/th.rb +36 -0
  82. data/lib/generated_definitions/tn.rb +32 -0
  83. data/lib/generated_definitions/tr.rb +64 -0
  84. data/lib/generated_definitions/ua.rb +37 -0
  85. data/lib/generated_definitions/{united_nations.rb → unitednations.rb} +61 -67
  86. data/lib/generated_definitions/ups.rb +3 -9
  87. data/lib/generated_definitions/us.rb +113 -23
  88. data/lib/generated_definitions/ve.rb +2 -8
  89. data/lib/generated_definitions/vi.rb +6 -11
  90. data/lib/generated_definitions/za.rb +2 -8
  91. data/lib/holidays/core_extensions/date.rb +21 -3
  92. data/lib/holidays/core_extensions/time.rb +23 -0
  93. data/lib/holidays/date_calculator/day_of_month.rb +3 -3
  94. data/lib/holidays/date_calculator/lunar_date.rb +371 -0
  95. data/lib/holidays/date_calculator/weekend_modifier.rb +0 -7
  96. data/lib/holidays/definition/context/function_processor.rb +91 -0
  97. data/lib/holidays/definition/context/generator.rb +37 -96
  98. data/lib/holidays/definition/context/load.rb +29 -0
  99. data/lib/holidays/definition/context/merger.rb +0 -4
  100. data/lib/holidays/definition/decorator/test.rb +37 -0
  101. data/lib/holidays/definition/entity/test.rb +11 -0
  102. data/lib/holidays/definition/generator/module.rb +54 -0
  103. data/lib/holidays/definition/generator/regions.rb +55 -0
  104. data/lib/holidays/definition/generator/test.rb +51 -0
  105. data/lib/holidays/definition/parser/custom_method.rb +3 -5
  106. data/lib/holidays/definition/parser/test.rb +86 -0
  107. data/lib/holidays/definition/repository/cache.rb +23 -9
  108. data/lib/holidays/definition/repository/holidays_by_month.rb +10 -2
  109. data/lib/holidays/definition/repository/proc_result_cache.rb +1 -1
  110. data/lib/holidays/definition/repository/regions.rb +23 -13
  111. data/lib/holidays/definition/validator/custom_method.rb +1 -1
  112. data/lib/holidays/definition/validator/region.rb +2 -11
  113. data/lib/holidays/definition/validator/test.rb +71 -0
  114. data/lib/holidays/errors.rb +5 -0
  115. data/lib/holidays/factory/date_calculator.rb +42 -0
  116. data/lib/holidays/factory/definition.rb +143 -0
  117. data/lib/holidays/factory/finder.rb +70 -0
  118. data/lib/holidays/finder/context/between.rb +45 -0
  119. data/lib/holidays/{use_case → finder}/context/dates_driver_builder.rb +11 -15
  120. data/lib/holidays/finder/context/next_holiday.rb +57 -0
  121. data/lib/holidays/finder/context/parse_options.rb +104 -0
  122. data/lib/holidays/finder/context/search.rb +110 -0
  123. data/lib/holidays/finder/context/year_holiday.rb +57 -0
  124. data/lib/holidays/finder/rules/in_region.rb +31 -0
  125. data/lib/holidays/finder/rules/year_range.rb +58 -0
  126. data/lib/holidays/load_all_definitions.rb +16 -17
  127. data/lib/holidays/version.rb +1 -1
  128. data/lib/holidays.rb +50 -125
  129. data/test/coverage_report.rb +26 -0
  130. data/test/data/test_custom_informal_holidays_defs.yaml +11 -0
  131. data/test/data/test_custom_year_range_holiday_defs.yaml +13 -10
  132. data/test/data/test_invalid_region.rb +15 -0
  133. data/test/data/test_multiple_custom_holiday_defs.yaml +7 -4
  134. data/test/data/test_multiple_regions_with_conflicts_region_1.yaml +38 -0
  135. data/test/data/test_multiple_regions_with_conflicts_region_2.yaml +38 -0
  136. data/test/data/test_region.rb +15 -0
  137. data/test/data/test_single_custom_holiday_defs.yaml +7 -4
  138. data/test/data/test_single_custom_holiday_with_custom_procs.yaml +11 -7
  139. data/test/defs/test_defs_ar.rb +41 -19
  140. data/test/defs/test_defs_at.rb +18 -11
  141. data/test/defs/test_defs_au.rb +185 -126
  142. data/test/defs/test_defs_be_fr.rb +33 -14
  143. data/test/defs/test_defs_be_nl.rb +33 -14
  144. data/test/defs/test_defs_bg.rb +29 -17
  145. data/test/defs/test_defs_br.rb +33 -19
  146. data/test/defs/test_defs_ca.rb +246 -136
  147. data/test/defs/test_defs_ch.rb +35 -23
  148. data/test/defs/test_defs_cl.rb +57 -27
  149. data/test/defs/test_defs_co.rb +113 -0
  150. data/test/defs/test_defs_cr.rb +17 -11
  151. data/test/defs/test_defs_cz.rb +25 -15
  152. data/test/defs/test_defs_de.rb +60 -59
  153. data/test/defs/test_defs_dk.rb +31 -19
  154. data/test/defs/test_defs_ecbtarget.rb +27 -0
  155. data/test/defs/test_defs_ee.rb +41 -0
  156. data/test/defs/test_defs_el.rb +29 -17
  157. data/test/defs/test_defs_es.rb +116 -52
  158. data/test/defs/test_defs_europe.rb +1382 -701
  159. data/test/defs/test_defs_federalreserve.rb +113 -0
  160. data/test/defs/test_defs_federalreservebanks.rb +247 -0
  161. data/test/defs/test_defs_fedex.rb +19 -12
  162. data/test/defs/test_defs_fi.rb +47 -27
  163. data/test/defs/test_defs_fr.rb +31 -18
  164. data/test/defs/test_defs_gb.rb +120 -51
  165. data/test/defs/test_defs_ge.rb +53 -0
  166. data/test/defs/test_defs_hk.rb +59 -0
  167. data/test/defs/test_defs_hr.rb +32 -18
  168. data/test/defs/test_defs_hu.rb +34 -16
  169. data/test/defs/test_defs_ie.rb +41 -25
  170. data/test/defs/test_defs_is.rb +39 -22
  171. data/test/defs/test_defs_it.rb +43 -14
  172. data/test/defs/test_defs_jp.rb +141 -55
  173. data/test/defs/test_defs_kr.rb +37 -0
  174. data/test/defs/test_defs_kz.rb +39 -0
  175. data/test/defs/test_defs_li.rb +20 -20
  176. data/test/defs/test_defs_lt.rb +51 -30
  177. data/test/defs/test_defs_lu.rb +35 -0
  178. data/test/defs/test_defs_lv.rb +90 -0
  179. data/test/defs/test_defs_ma.rb +17 -11
  180. data/test/defs/test_defs_mt_en.rb +41 -0
  181. data/test/defs/test_defs_mt_mt.rb +41 -0
  182. data/test/defs/test_defs_mx.rb +34 -23
  183. data/test/defs/test_defs_my.rb +23 -0
  184. data/test/defs/test_defs_nerc.rb +17 -11
  185. data/test/defs/test_defs_ng.rb +29 -0
  186. data/test/defs/test_defs_nl.rb +21 -13
  187. data/test/defs/test_defs_no.rb +31 -18
  188. data/test/defs/test_defs_northamerica.rb +644 -0
  189. data/test/defs/test_defs_nyse.rb +27 -11
  190. data/test/defs/test_defs_nz.rb +47 -28
  191. data/test/defs/test_defs_pe.rb +47 -0
  192. data/test/defs/test_defs_ph.rb +17 -13
  193. data/test/defs/test_defs_pl.rb +200 -119
  194. data/test/defs/test_defs_pt.rb +35 -15
  195. data/test/defs/test_defs_ro.rb +53 -24
  196. data/test/defs/test_defs_rs_cyrl.rb +46 -0
  197. data/test/defs/test_defs_rs_la.rb +46 -0
  198. data/test/defs/test_defs_ru.rb +34 -0
  199. data/test/defs/test_defs_scandinavia.rb +193 -116
  200. data/test/defs/test_defs_se.rb +47 -28
  201. data/test/defs/test_defs_sg.rb +13 -9
  202. data/test/defs/test_defs_si.rb +93 -24
  203. data/test/defs/test_defs_sk.rb +29 -17
  204. data/test/defs/test_defs_southamerica.rb +307 -0
  205. data/test/defs/test_defs_th.rb +33 -0
  206. data/test/defs/test_defs_tn.rb +27 -0
  207. data/test/defs/test_defs_tr.rb +60 -0
  208. data/test/defs/test_defs_ua.rb +41 -0
  209. data/test/defs/{test_defs_united_nations.rb → test_defs_unitednations.rb} +3 -4
  210. data/test/defs/test_defs_ups.rb +19 -12
  211. data/test/defs/test_defs_us.rb +370 -30
  212. data/test/defs/test_defs_ve.rb +23 -16
  213. data/test/defs/test_defs_vi.rb +10 -6
  214. data/test/defs/test_defs_za.rb +23 -14
  215. data/test/holidays/core_extensions/test_date.rb +3 -2
  216. data/test/holidays/core_extensions/test_date_time.rb +60 -0
  217. data/test/holidays/date_calculator/test_lunar_date.rb +89 -0
  218. data/test/holidays/definition/context/test_function_processor.rb +199 -0
  219. data/test/holidays/definition/context/test_generator.rb +66 -35
  220. data/test/holidays/definition/context/test_load.rb +37 -0
  221. data/test/holidays/definition/decorator/test_test.rb +123 -0
  222. data/test/holidays/definition/generator/test_module.rb +268 -0
  223. data/test/holidays/definition/generator/test_regions.rb +97 -0
  224. data/test/holidays/definition/generator/test_test.rb +113 -0
  225. data/test/holidays/definition/parser/test_custom_method.rb +6 -6
  226. data/test/holidays/definition/parser/test_test.rb +142 -0
  227. data/test/holidays/definition/repository/test_cache.rb +47 -6
  228. data/test/holidays/definition/repository/test_holidays_by_month.rb +121 -1
  229. data/test/holidays/definition/repository/test_proc_result_cache.rb +8 -1
  230. data/test/holidays/definition/repository/test_regions.rb +31 -13
  231. data/test/holidays/definition/validator/test_custom_method.rb +5 -0
  232. data/test/holidays/definition/validator/test_region.rb +16 -12
  233. data/test/holidays/definition/validator/test_test.rb +60 -0
  234. data/test/holidays/finder/context/test_between.rb +172 -0
  235. data/test/holidays/{use_case → finder}/context/test_dates_driver_builder.rb +2 -2
  236. data/test/holidays/finder/context/test_next_holiday.rb +156 -0
  237. data/test/holidays/finder/context/test_parse_options.rb +141 -0
  238. data/test/holidays/finder/context/test_search.rb +232 -0
  239. data/test/holidays/finder/context/test_year_holiday.rb +202 -0
  240. data/test/holidays/finder/rules/test_in_region.rb +42 -0
  241. data/test/holidays/finder/rules/test_year_range.rb +166 -0
  242. data/test/integration/README.md +9 -0
  243. data/test/{test_all_regions.rb → integration/test_all_regions.rb} +18 -4
  244. data/test/integration/test_any_holidays_during_work_week.rb +90 -0
  245. data/test/integration/test_available_regions.rb +23 -0
  246. data/test/{test_custom_holidays.rb → integration/test_custom_holidays.rb} +6 -6
  247. data/test/integration/test_custom_informal_holidays.rb +15 -0
  248. data/test/{test_custom_year_range_holidays.rb → integration/test_custom_year_range_holidays.rb} +1 -9
  249. data/test/{test_holidays.rb → integration/test_holidays.rb} +100 -69
  250. data/test/{test_holidays_between.rb → integration/test_holidays_between.rb} +19 -17
  251. data/test/integration/test_multiple_regions.rb +71 -0
  252. data/test/integration/test_multiple_regions_with_conflict.rb +29 -0
  253. data/test/integration/test_nonstandard_regions.rb +25 -0
  254. data/test/test_helper.rb +7 -3
  255. metadata +204 -132
  256. data/CONTRIBUTING.md +0 -41
  257. data/benchmark.rb +0 -8
  258. data/definitions/README.md +0 -353
  259. data/definitions/ar.yaml +0 -93
  260. data/definitions/at.yaml +0 -72
  261. data/definitions/au.yaml +0 -375
  262. data/definitions/be_fr.yaml +0 -69
  263. data/definitions/be_nl.yaml +0 -69
  264. data/definitions/bg.yaml +0 -127
  265. data/definitions/br.yaml +0 -77
  266. data/definitions/ca.yaml +0 -302
  267. data/definitions/ch.yaml +0 -193
  268. data/definitions/cl.yaml +0 -94
  269. data/definitions/cr.yaml +0 -65
  270. data/definitions/cz.yaml +0 -73
  271. data/definitions/de.yaml +0 -209
  272. data/definitions/dk.yaml +0 -130
  273. data/definitions/ecb_target.yaml +0 -44
  274. data/definitions/el.yaml +0 -84
  275. data/definitions/es.yaml +0 -203
  276. data/definitions/federal_reserve.yaml +0 -114
  277. data/definitions/fedex.yaml +0 -62
  278. data/definitions/fi.yaml +0 -115
  279. data/definitions/fr.yaml +0 -79
  280. data/definitions/gb.yaml +0 -151
  281. data/definitions/hr.yaml +0 -79
  282. data/definitions/hu.yaml +0 -63
  283. data/definitions/ie.yaml +0 -89
  284. data/definitions/index.yaml +0 -57
  285. data/definitions/is.yaml +0 -146
  286. data/definitions/it.yaml +0 -67
  287. data/definitions/jp.yaml +0 -316
  288. data/definitions/li.yaml +0 -107
  289. data/definitions/lt.yaml +0 -89
  290. data/definitions/ma.yaml +0 -52
  291. data/definitions/mx.yaml +0 -106
  292. data/definitions/nerc.yaml +0 -51
  293. data/definitions/nl.yaml +0 -73
  294. data/definitions/no.yaml +0 -90
  295. data/definitions/north_america_informal.yaml +0 -61
  296. data/definitions/nyse.yaml +0 -64
  297. data/definitions/nz.yaml +0 -163
  298. data/definitions/ph.yaml +0 -94
  299. data/definitions/pl.yaml +0 -320
  300. data/definitions/pt.yaml +0 -69
  301. data/definitions/ro.yaml +0 -78
  302. data/definitions/se.yaml +0 -120
  303. data/definitions/sg.yaml +0 -56
  304. data/definitions/si.yaml +0 -86
  305. data/definitions/sk.yaml +0 -80
  306. data/definitions/united_nations.yaml +0 -189
  307. data/definitions/ups.yaml +0 -62
  308. data/definitions/us.yaml +0 -103
  309. data/definitions/ve.yaml +0 -74
  310. data/definitions/vi.yaml +0 -29
  311. data/definitions/za.yaml +0 -80
  312. data/lib/generated_definitions/north_america.rb +0 -126
  313. data/lib/holidays/date_calculator_factory.rb +0 -35
  314. data/lib/holidays/definition_factory.rb +0 -86
  315. data/lib/holidays/option/context/parse_options.rb +0 -106
  316. data/lib/holidays/option_factory.rb +0 -15
  317. data/lib/holidays/use_case/context/between.rb +0 -45
  318. data/lib/holidays/use_case/context/context_common.rb +0 -123
  319. data/lib/holidays/use_case/context/next_holiday.rb +0 -54
  320. data/lib/holidays/use_case_factory.rb +0 -31
  321. data/test/defs/test_defs_ecb_target.rb +0 -23
  322. data/test/defs/test_defs_federal_reserve.rb +0 -69
  323. data/test/defs/test_defs_north_america.rb +0 -195
  324. data/test/holidays/option/context/test_parse_options.rb +0 -74
  325. data/test/holidays/test_date_calculator_factory.rb +0 -27
  326. data/test/holidays/test_definition_factory.rb +0 -49
  327. data/test/holidays/test_option_factory.rb +0 -9
  328. data/test/holidays/test_use_case_factory.rb +0 -13
  329. data/test/holidays/use_case/context/test_between.rb +0 -77
  330. data/test/test_multiple_regions.rb +0 -24
@@ -14,10 +14,18 @@ class GeneratorTests < Test::Unit::TestCase
14
14
  source: "some source",
15
15
  )
16
16
 
17
+ @test_parser = mock()
18
+ @test_source_generator = mock()
19
+
20
+ @module_source_generator = mock()
21
+
17
22
  @generator = Holidays::Definition::Context::Generator.new(
18
23
  @custom_method_parser,
19
24
  @custom_method_source_decorator,
20
25
  @custom_methods_repository,
26
+ @test_parser,
27
+ @test_source_generator,
28
+ @module_source_generator,
21
29
  )
22
30
  end
23
31
 
@@ -37,7 +45,9 @@ class GeneratorTests < Test::Unit::TestCase
37
45
  files = ['test/data/test_single_custom_holiday_defs.yaml']
38
46
  @custom_method_parser.expects(:call).with(nil).returns({})
39
47
 
40
- regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
48
+ @test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
49
+
50
+ regions = @generator.parse_definition_files(files)[0]
41
51
 
42
52
  assert_equal [:custom_single_file], regions
43
53
  end
@@ -46,7 +56,9 @@ class GeneratorTests < Test::Unit::TestCase
46
56
  files = ['test/data/test_single_custom_holiday_defs.yaml']
47
57
  @custom_method_parser.expects(:call).with(nil).returns({})
48
58
 
49
- regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
59
+ @test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
60
+
61
+ rules_by_month = @generator.parse_definition_files(files)[1]
50
62
 
51
63
  expected_rules_by_month = {
52
64
  6 => [
@@ -65,7 +77,9 @@ class GeneratorTests < Test::Unit::TestCase
65
77
  files = ['test/data/test_single_custom_holiday_defs.yaml']
66
78
  @custom_method_parser.expects(:call).with(nil).returns({})
67
79
 
68
- regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
80
+ @test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
81
+
82
+ custom_methods = @generator.parse_definition_files(files)[2]
69
83
 
70
84
  expected_custom_methods = {}
71
85
  assert_equal expected_custom_methods, custom_methods
@@ -75,23 +89,26 @@ class GeneratorTests < Test::Unit::TestCase
75
89
  files = ['test/data/test_single_custom_holiday_defs.yaml']
76
90
  @custom_method_parser.expects(:call).with(nil).returns({})
77
91
 
78
- regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
92
+ @test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
79
93
 
80
- expected_tests = [[
81
- "{Date.civil(2013,6,20) => 'Company Founding'}.each do |date, name|\n assert_equal name, (Holidays.on(date, :custom_single_file)[0] || {})[:name]\nend"
82
- ]]
94
+ parsed_tests = @generator.parse_definition_files(files)[3]
83
95
 
84
- assert_equal expected_tests, tests
96
+ assert_equal ["parsed tests"], parsed_tests
85
97
  end
86
98
 
87
99
  def test_generate_definition_source_correctly_generate_module_src
88
100
  files = ['test/data/test_single_custom_holiday_defs.yaml']
89
101
  @custom_method_parser.expects(:call).with(nil).returns({})
90
102
 
103
+ @test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
104
+
105
+ @module_source_generator.expects(:call).with("test", ["test/data/test_single_custom_holiday_defs.yaml"], [:custom_single_file], [" 6 => [{:mday => 20, :name => \"Company Founding\", :regions => [:custom_single_file]}]"], "").returns("module source")
106
+ @test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_defs.yaml'], ['parsed tests']).returns("test source")
107
+
91
108
  regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
92
- module_src, test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)
109
+ module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
93
110
 
94
- expected_module_src = "# encoding: utf-8\nmodule Holidays\n # This file is generated by the Ruby Holidays gem.\n #\n # Definitions loaded: test/data/test_single_custom_holiday_defs.yaml\n #\n # To use the definitions in this file, load it right after you load the\n # Holiday gem:\n #\n # require 'holidays'\n # require 'generated_definitions/test'\n #\n # All the definitions are available at https://github.com/holidays/holidays\n module TEST # :nodoc:\n def self.defined_regions\n [:custom_single_file]\n end\n\n def self.holidays_by_month\n {\n 6 => [{:mday => 20, :name => \"Company Founding\", :regions => [:custom_single_file]}]\n }\n end\n\n def self.custom_methods\n {\n \n }\n end\n end\nend\n"
111
+ expected_module_src = "module source"
95
112
 
96
113
  assert_equal expected_module_src, module_src
97
114
  end
@@ -100,19 +117,25 @@ class GeneratorTests < Test::Unit::TestCase
100
117
  files = ['test/data/test_single_custom_holiday_defs.yaml']
101
118
  @custom_method_parser.expects(:call).with(nil).returns({})
102
119
 
103
- regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
104
- module_src, test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)
120
+ @test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
105
121
 
106
- expected_test_src = "# encoding: utf-8\nrequire File.expand_path(File.dirname(__FILE__)) + '/../test_helper'\n\n# This file is generated by the Ruby Holiday gem.\n#\n# Definitions loaded: test/data/test_single_custom_holiday_defs.yaml\nclass TestDefinitionTests < Test::Unit::TestCase # :nodoc:\n\n def test_test\n{Date.civil(2013,6,20) => 'Company Founding'}.each do |date, name|\n assert_equal name, (Holidays.on(date, :custom_single_file)[0] || {})[:name]\nend\n end\nend\n"
122
+ @module_source_generator.expects(:call).returns("module_source")
123
+
124
+ @test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_defs.yaml'], ['parsed tests']).returns("test source")
125
+
126
+ regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
127
+ test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[1]
107
128
 
108
- assert_equal expected_test_src, test_src
129
+ assert_equal 'test source', test_src
109
130
  end
110
131
 
111
132
  def test_parse_definitions_files_correctly_parse_year_range_by_month
112
133
  files = ['test/data/test_custom_year_range_holiday_defs.yaml']
113
134
  @custom_method_parser.expects(:call).with(nil).returns({})
114
135
 
115
- regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
136
+ @test_parser.expects(:call).with([{'given' => {'date' => '2017-01-01', 'regions' => ['custom_year_range_file']}, 'expect' => {'name' => 'after_year'}}]).returns(['parsed tests'])
137
+
138
+ rules_by_month = @generator.parse_definition_files(files)[1]
116
139
 
117
140
  expected_rules_by_month = {
118
141
  6 => [
@@ -120,31 +143,25 @@ class GeneratorTests < Test::Unit::TestCase
120
143
  :name => "after_year",
121
144
  :regions => [:custom_year_range_file],
122
145
  :mday => 1,
123
- :year_ranges => [{"after" => 2016}]
146
+ :year_ranges => {:from => 2016}
124
147
  },
125
148
  {
126
149
  :name => "before_year",
127
150
  :regions => [:custom_year_range_file],
128
151
  :mday => 2,
129
- :year_ranges => [{"before" => 2017}]
152
+ :year_ranges => {:until => 2017}
130
153
  },
131
154
  {
132
155
  :name => "between_year",
133
156
  :regions => [:custom_year_range_file],
134
157
  :mday => 3,
135
- :year_ranges => [{"between" => "2016..2018"}]
158
+ :year_ranges => {:between => 2016..2018 }
136
159
  },
137
160
  {
138
161
  :name => "limited_year",
139
162
  :regions => [:custom_year_range_file],
140
163
  :mday => 4,
141
- :year_ranges => [{"limited" => [2016,2018,2019]}]
142
- },
143
- {
144
- :name => "multiple_conditions",
145
- :regions => [:custom_year_range_file],
146
- :mday => 5,
147
- :year_ranges => [{"before" => 2015}, {"after" => 2017}]
164
+ :year_ranges => {:limited => [2016,2018,2019]}
148
165
  }
149
166
  ]
150
167
  }
@@ -156,9 +173,15 @@ class GeneratorTests < Test::Unit::TestCase
156
173
  files = ['test/data/test_custom_year_range_holiday_defs.yaml']
157
174
  @custom_method_parser.expects(:call).with(nil).returns({})
158
175
 
176
+ @test_parser.expects(:call).with([{'given' => {'date' => '2017-01-01', 'regions' => ['custom_year_range_file']}, 'expect' => {'name' => 'after_year'}}]).returns(['parsed tests'])
177
+
178
+ @test_source_generator.expects(:call).with('test', ['test/data/test_custom_year_range_holiday_defs.yaml'], ['parsed tests']).returns('test source')
179
+
180
+ @module_source_generator.expects(:call).with("test", ["test/data/test_custom_year_range_holiday_defs.yaml"], [:custom_year_range_file], [" 6 => [{:mday => 1, :year_ranges => { :from => 2016 },:name => \"after_year\", :regions => [:custom_year_range_file]},\n {:mday => 2, :year_ranges => { :until => 2017 },:name => \"before_year\", :regions => [:custom_year_range_file]},\n {:mday => 3, :year_ranges => { :between => 2016..2018 },:name => \"between_year\", :regions => [:custom_year_range_file]},\n {:mday => 4, :year_ranges => { :limited => [2016, 2018, 2019] },:name => \"limited_year\", :regions => [:custom_year_range_file]}]"], "").returns('module_source')
181
+
159
182
  regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
160
- module_src, test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)
161
- expected_module_src = "# encoding: utf-8\nmodule Holidays\n # This file is generated by the Ruby Holidays gem.\n #\n # Definitions loaded: test/data/test_custom_year_range_holiday_defs.yaml\n #\n # To use the definitions in this file, load it right after you load the\n # Holiday gem:\n #\n # require 'holidays'\n # require 'generated_definitions/test'\n #\n # All the definitions are available at https://github.com/holidays/holidays\n module TEST # :nodoc:\n def self.defined_regions\n [:custom_year_range_file]\n end\n\n def self.holidays_by_month\n {\n 6 => [{:mday => 1, :year_ranges => [{:after => 2016}],:name => \"after_year\", :regions => [:custom_year_range_file]},\n {:mday => 2, :year_ranges => [{:before => 2017}],:name => \"before_year\", :regions => [:custom_year_range_file]},\n {:mday => 3, :year_ranges => [{:between => 2016..2018}],:name => \"between_year\", :regions => [:custom_year_range_file]},\n {:mday => 4, :year_ranges => [{:limited => [2016, 2018, 2019]}],:name => \"limited_year\", :regions => [:custom_year_range_file]},\n {:mday => 5, :year_ranges => [{:before => 2015},{:after => 2017}],:name => \"multiple_conditions\", :regions => [:custom_year_range_file]}]\n }\n end\n\n def self.custom_methods\n {\n \n }\n end\n end\nend\n"
183
+ module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
184
+ expected_module_src = "module_source"
162
185
 
163
186
  assert_equal expected_module_src, module_src
164
187
  end
@@ -170,10 +193,15 @@ class GeneratorTests < Test::Unit::TestCase
170
193
  @custom_methods_repository.expects(:find).twice.with('custom_method(year, month)').returns(nil)
171
194
  @custom_method_source_decorator.expects(:call).once.with(@parsed_custom_method).returns("\"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n}")
172
195
 
196
+ @test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}, {'given' => {'date' => '2015-01-01', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Custom Holiday'}}]).returns(['parsed tests'])
197
+
198
+ @module_source_generator.expects(:call).with("test", ["test/data/test_single_custom_holiday_with_custom_procs.yaml"], [:custom_single_file], [" 0 => [{:function => \"custom_method(year, month)\", :function_arguments => [:year, :month], :function_modifier => 5, :name => \"Custom Holiday\", :regions => [:custom_single_file]}]", " 6 => [{:mday => 20, :name => \"Company Founding\", :regions => [:custom_single_file]}]"], "\"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n},\n\n").returns("module source")
199
+ @test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_with_custom_procs.yaml'], ['parsed tests']).returns('test source')
200
+
173
201
  regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
174
- module_src, test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)
202
+ module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
175
203
 
176
- expected_module_src = "# encoding: utf-8\nmodule Holidays\n # This file is generated by the Ruby Holidays gem.\n #\n # Definitions loaded: test/data/test_single_custom_holiday_with_custom_procs.yaml\n #\n # To use the definitions in this file, load it right after you load the\n # Holiday gem:\n #\n # require 'holidays'\n # require 'generated_definitions/test'\n #\n # All the definitions are available at https://github.com/holidays/holidays\n module TEST # :nodoc:\n def self.defined_regions\n [:custom_single_file]\n end\n\n def self.holidays_by_month\n {\n 0 => [{:function => \"custom_method(year, month)\", :function_arguments => [:year, :month], :function_modifier => 5, :name => \"Custom Holiday\", :regions => [:custom_single_file]}],\n 6 => [{:mday => 20, :name => \"Company Founding\", :regions => [:custom_single_file]}]\n }\n end\n\n def self.custom_methods\n {\n \"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n},\n\n\n }\n end\n end\nend\n"
204
+ expected_module_src = "module source"
177
205
 
178
206
  assert_equal expected_module_src, module_src
179
207
  end
@@ -181,15 +209,18 @@ class GeneratorTests < Test::Unit::TestCase
181
209
  def test_generate_definition_source_correctly_generate_test_src_with_custom_methods
182
210
  files = ['test/data/test_single_custom_holiday_with_custom_procs.yaml']
183
211
 
184
- @custom_method_parser.expects(:call).with('custom_method' => {'arguments' => 'year, month', 'source' => "d = Date.civil(year, month, 1)\nd + 2\n"}).returns({:parsed => "method"})
212
+ @custom_method_parser.expects(:call).with('custom_method' => {'arguments' => 'year, month', 'source' => "d = Date.civil(year, month, 1)\nd + 2\n"}).returns({"custom_method(year, month)" => @parsed_custom_method})
185
213
  @custom_methods_repository.expects(:find).twice.with('custom_method(year, month)').returns(nil)
186
- @custom_method_source_decorator.expects(:call).once.with("method").returns("\"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n}")
214
+ @custom_method_source_decorator.expects(:call).once.with(@parsed_custom_method).returns("\"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n}")
187
215
 
188
- regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
189
- module_src, test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)
216
+ @test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}, {'given' => {'date' => '2015-01-01', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Custom Holiday'}}]).returns(['parsed tests'])
217
+
218
+ @module_source_generator.expects(:call).returns("module_source")
219
+ @test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_with_custom_procs.yaml'], ['parsed tests']).returns('test source')
190
220
 
191
- expected_test_src = "# encoding: utf-8\nrequire File.expand_path(File.dirname(__FILE__)) + '/../test_helper'\n\n# This file is generated by the Ruby Holiday gem.\n#\n# Definitions loaded: test/data/test_single_custom_holiday_with_custom_procs.yaml\nclass TestDefinitionTests < Test::Unit::TestCase # :nodoc:\n\n def test_test\n{Date.civil(2013,6,20) => 'Company Founding'}.each do |date, name|\n assert_equal name, (Holidays.on(date, :custom_single_file)[0] || {})[:name]\nend\n\n{Date.civil(2015, 1, 1) => 'Custom Holiday'}.each do |date, name|\n assert_equal name, (Holidays.on(date, :custom_single_file)[0] || {}[:name]\nend\n\n end\nend\n"
221
+ regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
222
+ test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[1]
192
223
 
193
- assert_equal expected_test_src, test_src
224
+ assert_equal 'test source', test_src
194
225
  end
195
226
  end
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/definition/context/load'
4
+
5
+ class LoadTests < Test::Unit::TestCase
6
+ def setup
7
+ @definition_merger = mock()
8
+ full_definitions_path = File.expand_path(File.dirname(__FILE__)) + '/../../../data'
9
+
10
+ @subject = Holidays::Definition::Context::Load.new(
11
+ @definition_merger,
12
+ full_definitions_path,
13
+ )
14
+ end
15
+
16
+ def test_region_is_found_and_loaded_and_merged
17
+ @definition_merger.expects(:call).with(:test_region, {}, {})
18
+ @subject.call(:test_region)
19
+ end
20
+
21
+ def test_region_file_not_found
22
+ assert_raises Holidays::UnknownRegionError do
23
+ @subject.call(:unknown)
24
+ end
25
+ end
26
+
27
+ def test_region_can_be_loaded_but_file_is_invalid
28
+ assert_raises Holidays::UnknownRegionError do
29
+ @subject.call(:test_invalid_region)
30
+ end
31
+ end
32
+
33
+ def test_returns_list_of_loaded_regions
34
+ @definition_merger.expects(:call).with(:test_region, {}, {})
35
+ assert_equal([:test_region, :test_region2], @subject.call(:test_region), "Should cache subregions under the parent region's name")
36
+ end
37
+ end
@@ -0,0 +1,123 @@
1
+ # Heh at this file name
2
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
3
+
4
+ require 'holidays/definition/decorator/test'
5
+ require 'holidays/definition/entity/test'
6
+
7
+ class DecoratorTestTests < Test::Unit::TestCase
8
+ def setup
9
+ @decorator = Holidays::Definition::Decorator::Test.new
10
+ end
11
+
12
+ def test_call_generates_source_from_entity_single_date
13
+ entity = Holidays::Definition::Entity::Test.new(
14
+ :dates => [DateTime.parse('2016-01-01')],
15
+ :regions => [:us],
16
+ :name => 'Test Holiday',
17
+ :holiday? => true,
18
+ )
19
+
20
+ source = @decorator.call(entity)
21
+ expected_source = "assert_equal \"Test Holiday\", (Holidays.on(Date.civil(2016, 1, 1), [:us])[0] || {})[:name]\n"
22
+
23
+ assert_equal expected_source, source
24
+ end
25
+
26
+ def test_call_generates_source_from_entity_multiple_dates
27
+ entity = Holidays::Definition::Entity::Test.new(
28
+ :dates => [DateTime.parse('2016-01-01'), DateTime.parse('2017-01-01')],
29
+ :regions => [:us],
30
+ :name => 'Test Holiday',
31
+ :holiday? => true
32
+ )
33
+
34
+ source = @decorator.call(entity)
35
+ expected_source = "assert_equal \"Test Holiday\", (Holidays.on(Date.civil(2016, 1, 1), [:us])[0] || {})[:name]\nassert_equal \"Test Holiday\", (Holidays.on(Date.civil(2017, 1, 1), [:us])[0] || {})[:name]\n"
36
+
37
+ assert_equal expected_source, source
38
+ end
39
+
40
+ def test_call_generates_source_from_entity_single_date_with_options
41
+ entity = Holidays::Definition::Entity::Test.new(
42
+ :dates => [DateTime.parse('2016-01-01')],
43
+ :regions => [:us],
44
+ :options => ['option1'],
45
+ :name => 'Test Holiday',
46
+ :holiday? => true,
47
+ )
48
+
49
+ source = @decorator.call(entity)
50
+ expected_source = "assert_equal \"Test Holiday\", (Holidays.on(Date.civil(2016, 1, 1), [:us], [:option1])[0] || {})[:name]\n"
51
+
52
+ assert_equal expected_source, source
53
+ end
54
+
55
+ def test_call_generates_source_from_entity_single_date_with_holiday_flag
56
+ entity = Holidays::Definition::Entity::Test.new(
57
+ :dates => [DateTime.parse('2016-01-01')],
58
+ :regions => [:us],
59
+ :holiday? => false,
60
+ )
61
+
62
+ source = @decorator.call(entity)
63
+ expected_source = "assert_nil (Holidays.on(Date.civil(2016, 1, 1), [:us])[0] || {})[:name]\n"
64
+
65
+ assert_equal expected_source, source
66
+ end
67
+
68
+ def test_call_generates_source_from_entity_single_date_multiple_regions
69
+ entity = Holidays::Definition::Entity::Test.new(
70
+ :dates => [DateTime.parse('2016-01-01')],
71
+ :regions => [:us, :us_ca, :ca],
72
+ :name => 'Test Holiday',
73
+ :holiday? => true,
74
+ )
75
+
76
+ source = @decorator.call(entity)
77
+ expected_source = "assert_equal \"Test Holiday\", (Holidays.on(Date.civil(2016, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\n"
78
+
79
+ assert_equal expected_source, source
80
+ end
81
+
82
+ def test_call_generates_source_from_entity_multiple_dates_multiple_regions
83
+ entity = Holidays::Definition::Entity::Test.new(
84
+ :dates => [DateTime.parse('2016-01-01'), DateTime.parse('2017-01-01')],
85
+ :regions => [:us, :us_ca, :ca],
86
+ :name => 'Test Holiday',
87
+ :holiday? => true,
88
+ )
89
+
90
+ source = @decorator.call(entity)
91
+ expected_source = "assert_equal \"Test Holiday\", (Holidays.on(Date.civil(2016, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\nassert_equal \"Test Holiday\", (Holidays.on(Date.civil(2017, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\n"
92
+
93
+ assert_equal expected_source, source
94
+ end
95
+
96
+ def test_call_generates_source_from_entity_multiple_dates_multiple_regions_holiday_flag_false
97
+ entity = Holidays::Definition::Entity::Test.new(
98
+ :dates => [DateTime.parse('2016-01-01'), DateTime.parse('2017-01-01')],
99
+ :regions => [:us, :us_ca, :ca],
100
+ :name => 'Test Holiday',
101
+ :holiday? => false,
102
+ )
103
+
104
+ source = @decorator.call(entity)
105
+ expected_source = "assert_nil (Holidays.on(Date.civil(2016, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\nassert_nil (Holidays.on(Date.civil(2017, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\n"
106
+
107
+ assert_equal expected_source, source
108
+ end
109
+
110
+ def test_call_generates_source_from_entity_single_date_multiple_regions_holiday_flag_false
111
+ entity = Holidays::Definition::Entity::Test.new(
112
+ :dates => [DateTime.parse('2016-01-01')],
113
+ :regions => [:us, :us_ca, :ca],
114
+ :name => 'Test Holiday',
115
+ :holiday? => false,
116
+ )
117
+
118
+ source = @decorator.call(entity)
119
+ expected_source = "assert_nil (Holidays.on(Date.civil(2016, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\n"
120
+
121
+ assert_equal expected_source, source
122
+ end
123
+ end
@@ -0,0 +1,268 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
+
3
+ require 'holidays/definition/generator/module'
4
+
5
+ class GeneratorModuleTests < Test::Unit::TestCase
6
+ def setup
7
+ @generator = Holidays::Definition::Generator::Module.new
8
+
9
+ @module_name = "TEST"
10
+ @files = ["file1.rb", "file2.rb"]
11
+ @regions = [:test, :test2]
12
+ @month_strings = ["first-string", "second-string"]
13
+ @custom_methods = "custom-methods"
14
+ end
15
+
16
+ def subject
17
+ @generator.call(
18
+ @module_name,
19
+ @files,
20
+ @regions,
21
+ @month_strings,
22
+ @custom_methods,
23
+ )
24
+ end
25
+
26
+ def test_generates_source
27
+ expected = <<-EOF
28
+ # encoding: utf-8
29
+ module Holidays
30
+ # This file is generated by the Ruby Holidays gem.
31
+ #
32
+ # Definitions loaded: file1.rb, file2.rb
33
+ #
34
+ # All the definitions are available at https://github.com/holidays/holidays
35
+ module TEST # :nodoc:
36
+ def self.defined_regions
37
+ [:test, :test2]
38
+ end
39
+
40
+ def self.holidays_by_month
41
+ {
42
+ first-string,
43
+ second-string
44
+ }
45
+ end
46
+
47
+ def self.custom_methods
48
+ {
49
+ custom-methods
50
+ }
51
+ end
52
+ end
53
+ end
54
+ EOF
55
+
56
+ assert_equal expected, subject
57
+ end
58
+
59
+ def test_module_name_more_than_one_word
60
+ @module_name = "TESTWITHHYPHEN"
61
+
62
+ expected = <<-EOF
63
+ # encoding: utf-8
64
+ module Holidays
65
+ # This file is generated by the Ruby Holidays gem.
66
+ #
67
+ # Definitions loaded: file1.rb, file2.rb
68
+ #
69
+ # All the definitions are available at https://github.com/holidays/holidays
70
+ module TESTWITHHYPHEN # :nodoc:
71
+ def self.defined_regions
72
+ [:test, :test2]
73
+ end
74
+
75
+ def self.holidays_by_month
76
+ {
77
+ first-string,
78
+ second-string
79
+ }
80
+ end
81
+
82
+ def self.custom_methods
83
+ {
84
+ custom-methods
85
+ }
86
+ end
87
+ end
88
+ end
89
+ EOF
90
+
91
+ assert_equal expected, subject
92
+ end
93
+
94
+ def test_generates_source_with_blank_custom_methods
95
+ @custom_methods = ""
96
+
97
+ expected = <<-EOF
98
+ # encoding: utf-8
99
+ module Holidays
100
+ # This file is generated by the Ruby Holidays gem.
101
+ #
102
+ # Definitions loaded: file1.rb, file2.rb
103
+ #
104
+ # All the definitions are available at https://github.com/holidays/holidays
105
+ module TEST # :nodoc:
106
+ def self.defined_regions
107
+ [:test, :test2]
108
+ end
109
+
110
+ def self.holidays_by_month
111
+ {
112
+ first-string,
113
+ second-string
114
+ }
115
+ end
116
+
117
+ def self.custom_methods
118
+ {
119
+
120
+ }
121
+ end
122
+ end
123
+ end
124
+ EOF
125
+
126
+ assert_equal expected, subject
127
+ end
128
+
129
+ def test_generates_source_with_nil_custom_methods
130
+ @custom_methods = nil
131
+
132
+ expected = <<-EOF
133
+ # encoding: utf-8
134
+ module Holidays
135
+ # This file is generated by the Ruby Holidays gem.
136
+ #
137
+ # Definitions loaded: file1.rb, file2.rb
138
+ #
139
+ # All the definitions are available at https://github.com/holidays/holidays
140
+ module TEST # :nodoc:
141
+ def self.defined_regions
142
+ [:test, :test2]
143
+ end
144
+
145
+ def self.holidays_by_month
146
+ {
147
+ first-string,
148
+ second-string
149
+ }
150
+ end
151
+
152
+ def self.custom_methods
153
+ {
154
+
155
+ }
156
+ end
157
+ end
158
+ end
159
+ EOF
160
+
161
+ assert_equal expected, subject
162
+ end
163
+
164
+ def test_generates_source_with_symbol_module_name
165
+ @module_name = :test
166
+
167
+ expected = <<-EOF
168
+ # encoding: utf-8
169
+ module Holidays
170
+ # This file is generated by the Ruby Holidays gem.
171
+ #
172
+ # Definitions loaded: file1.rb, file2.rb
173
+ #
174
+ # All the definitions are available at https://github.com/holidays/holidays
175
+ module TEST # :nodoc:
176
+ def self.defined_regions
177
+ [:test, :test2]
178
+ end
179
+
180
+ def self.holidays_by_month
181
+ {
182
+ first-string,
183
+ second-string
184
+ }
185
+ end
186
+
187
+ def self.custom_methods
188
+ {
189
+ custom-methods
190
+ }
191
+ end
192
+ end
193
+ end
194
+ EOF
195
+
196
+ assert_equal expected, subject
197
+ end
198
+
199
+ def test_raise_error_if_module_name_is_blank
200
+ @module_name = ""
201
+ assert_raises ArgumentError do
202
+ subject
203
+ end
204
+ end
205
+
206
+ def test_raise_error_if_module_name_is_nil
207
+ @module_name = nil
208
+ assert_raises ArgumentError do
209
+ subject
210
+ end
211
+ end
212
+
213
+ def test_raise_error_if_files_are_empty
214
+ @files = []
215
+
216
+ assert_raises ArgumentError do
217
+ subject
218
+ end
219
+ end
220
+
221
+ def test_raise_error_if_files_are_not_all_strings
222
+ @files = [:test, 1]
223
+
224
+ assert_raises ArgumentError do
225
+ subject
226
+ end
227
+ end
228
+
229
+ def test_raise_error_if_files_is_nil
230
+ @files = nil
231
+
232
+ assert_raises ArgumentError do
233
+ subject
234
+ end
235
+ end
236
+
237
+ def test_raise_error_if_regions_are_empty
238
+ @regions = []
239
+
240
+ assert_raises ArgumentError do
241
+ subject
242
+ end
243
+ end
244
+
245
+ def test_raise_error_if_regions_is_nil
246
+ @regions = nil
247
+
248
+ assert_raises ArgumentError do
249
+ subject
250
+ end
251
+ end
252
+
253
+ def test_raise_error_if_month_strings_are_empty
254
+ @month_strings = []
255
+
256
+ assert_raises ArgumentError do
257
+ subject
258
+ end
259
+ end
260
+
261
+ def test_raise_error_if_month_strings_is_nil
262
+ @month_strings = nil
263
+
264
+ assert_raises ArgumentError do
265
+ subject
266
+ end
267
+ end
268
+ end