holidays 9.2.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +38 -2
  4. data/lib/generated_definitions/au.rb +16 -42
  5. data/lib/generated_definitions/europe.rb +2 -10
  6. data/lib/generated_definitions/lu.rb +1 -1
  7. data/lib/generated_definitions/nz.rb +9 -1
  8. data/lib/generated_definitions/pl.rb +3 -11
  9. data/lib/holidays/definition/context/function_processor.rb +4 -5
  10. data/lib/holidays/definition/context/generator.rb +3 -1
  11. data/lib/holidays/version.rb +1 -1
  12. metadata +3 -313
  13. data/.github/workflows/changelog-check.yml +0 -47
  14. data/.github/workflows/release.yml +0 -46
  15. data/.github/workflows/ruby.yml +0 -26
  16. data/.gitmodules +0 -3
  17. data/CODE_OF_CONDUCT.md +0 -74
  18. data/Gemfile +0 -8
  19. data/Makefile +0 -60
  20. data/Rakefile +0 -137
  21. data/bin/console +0 -7
  22. data/bin/setup +0 -6
  23. data/doc/CONTRIBUTING.md +0 -72
  24. data/doc/MAINTAINERS.md +0 -79
  25. data/doc/REFERENCES +0 -19
  26. data/holidays.gemspec +0 -31
  27. data/test/coverage_report.rb +0 -24
  28. data/test/data/test_custom_year_range_holiday_defs.yaml +0 -31
  29. data/test/data/test_date_transform_conflict_region_1.yaml +0 -14
  30. data/test/data/test_date_transform_conflict_region_2.yaml +0 -14
  31. data/test/data/test_invalid_region.rb +0 -15
  32. data/test/data/test_region.rb +0 -15
  33. data/test/data/test_single_custom_holiday_defs.yaml +0 -12
  34. data/test/data/test_single_custom_holiday_with_custom_procs.yaml +0 -28
  35. data/test/defs/test_defs_ar.rb +0 -69
  36. data/test/defs/test_defs_at.rb +0 -31
  37. data/test/defs/test_defs_au.rb +0 -233
  38. data/test/defs/test_defs_be_fr.rb +0 -45
  39. data/test/defs/test_defs_be_nl.rb +0 -45
  40. data/test/defs/test_defs_bg.rb +0 -41
  41. data/test/defs/test_defs_br.rb +0 -49
  42. data/test/defs/test_defs_ca.rb +0 -289
  43. data/test/defs/test_defs_ch.rb +0 -51
  44. data/test/defs/test_defs_cl.rb +0 -69
  45. data/test/defs/test_defs_co.rb +0 -113
  46. data/test/defs/test_defs_cr.rb +0 -29
  47. data/test/defs/test_defs_cy.rb +0 -41
  48. data/test/defs/test_defs_cz.rb +0 -37
  49. data/test/defs/test_defs_de.rb +0 -91
  50. data/test/defs/test_defs_dk.rb +0 -47
  51. data/test/defs/test_defs_ecbtarget.rb +0 -27
  52. data/test/defs/test_defs_ee.rb +0 -41
  53. data/test/defs/test_defs_es.rb +0 -137
  54. data/test/defs/test_defs_europe.rb +0 -1530
  55. data/test/defs/test_defs_fed_ex.rb +0 -24
  56. data/test/defs/test_defs_federalreserve.rb +0 -119
  57. data/test/defs/test_defs_federalreservebanks.rb +0 -251
  58. data/test/defs/test_defs_fedex.rb +0 -31
  59. data/test/defs/test_defs_fi.rb +0 -59
  60. data/test/defs/test_defs_fr.rb +0 -43
  61. data/test/defs/test_defs_gb.rb +0 -163
  62. data/test/defs/test_defs_ge.rb +0 -53
  63. data/test/defs/test_defs_gr.rb +0 -41
  64. data/test/defs/test_defs_hk.rb +0 -93
  65. data/test/defs/test_defs_hr.rb +0 -45
  66. data/test/defs/test_defs_hu.rb +0 -47
  67. data/test/defs/test_defs_ie.rb +0 -53
  68. data/test/defs/test_defs_il.rb +0 -35
  69. data/test/defs/test_defs_in.rb +0 -94
  70. data/test/defs/test_defs_is.rb +0 -51
  71. data/test/defs/test_defs_it.rb +0 -57
  72. data/test/defs/test_defs_jp.rb +0 -159
  73. data/test/defs/test_defs_ke.rb +0 -31
  74. data/test/defs/test_defs_kr.rb +0 -37
  75. data/test/defs/test_defs_kz.rb +0 -39
  76. data/test/defs/test_defs_li.rb +0 -35
  77. data/test/defs/test_defs_lt.rb +0 -65
  78. data/test/defs/test_defs_lu.rb +0 -35
  79. data/test/defs/test_defs_lv.rb +0 -98
  80. data/test/defs/test_defs_ma.rb +0 -29
  81. data/test/defs/test_defs_mc.rb +0 -43
  82. data/test/defs/test_defs_mt_en.rb +0 -41
  83. data/test/defs/test_defs_mt_mt.rb +0 -41
  84. data/test/defs/test_defs_mx.rb +0 -49
  85. data/test/defs/test_defs_my.rb +0 -23
  86. data/test/defs/test_defs_nerc.rb +0 -29
  87. data/test/defs/test_defs_ng.rb +0 -29
  88. data/test/defs/test_defs_nl.rb +0 -33
  89. data/test/defs/test_defs_no.rb +0 -43
  90. data/test/defs/test_defs_northamerica.rb +0 -679
  91. data/test/defs/test_defs_nyse.rb +0 -46
  92. data/test/defs/test_defs_nz.rb +0 -67
  93. data/test/defs/test_defs_pe.rb +0 -47
  94. data/test/defs/test_defs_ph.rb +0 -29
  95. data/test/defs/test_defs_pl.rb +0 -229
  96. data/test/defs/test_defs_pt.rb +0 -47
  97. data/test/defs/test_defs_ro.rb +0 -69
  98. data/test/defs/test_defs_rs_cyrl.rb +0 -46
  99. data/test/defs/test_defs_rs_la.rb +0 -46
  100. data/test/defs/test_defs_ru.rb +0 -34
  101. data/test/defs/test_defs_scandinavia.rb +0 -215
  102. data/test/defs/test_defs_se.rb +0 -59
  103. data/test/defs/test_defs_sg.rb +0 -25
  104. data/test/defs/test_defs_si.rb +0 -105
  105. data/test/defs/test_defs_sk.rb +0 -37
  106. data/test/defs/test_defs_southamerica.rb +0 -327
  107. data/test/defs/test_defs_th.rb +0 -33
  108. data/test/defs/test_defs_tn.rb +0 -27
  109. data/test/defs/test_defs_tr.rb +0 -60
  110. data/test/defs/test_defs_tsx.rb +0 -70
  111. data/test/defs/test_defs_ua.rb +0 -41
  112. data/test/defs/test_defs_unitednations.rb +0 -11
  113. data/test/defs/test_defs_ups.rb +0 -31
  114. data/test/defs/test_defs_us.rb +0 -399
  115. data/test/defs/test_defs_ve.rb +0 -35
  116. data/test/defs/test_defs_vi.rb +0 -22
  117. data/test/defs/test_defs_za.rb +0 -35
  118. data/test/e2e/README.md +0 -52
  119. data/test/e2e/data/test_multiple_regions_with_conflicts_region_1.yaml +0 -38
  120. data/test/e2e/data/test_multiple_regions_with_conflicts_region_2.yaml +0 -38
  121. data/test/e2e/data/test_multiple_regions_with_conflicts_region_3.yaml +0 -38
  122. data/test/e2e/test_all_regions.rb +0 -49
  123. data/test/e2e/test_any_holidays_during_work_week.rb +0 -90
  124. data/test/e2e/test_holidays.rb +0 -244
  125. data/test/e2e/test_holidays_between.rb +0 -87
  126. data/test/e2e/test_multiple_regions.rb +0 -71
  127. data/test/e2e/test_multiple_regions_with_conflict.rb +0 -228
  128. data/test/e2e/test_nonstandard_regions.rb +0 -25
  129. data/test/holidays/core_extensions/test_date.rb +0 -122
  130. data/test/holidays/core_extensions/test_date_time.rb +0 -60
  131. data/test/holidays/date_calculator/test_day_of_month.rb +0 -27
  132. data/test/holidays/date_calculator/test_easter_gregorian.rb +0 -30
  133. data/test/holidays/date_calculator/test_easter_julian.rb +0 -36
  134. data/test/holidays/date_calculator/test_lunar_date.rb +0 -89
  135. data/test/holidays/date_calculator/test_weekend_modifier.rb +0 -54
  136. data/test/holidays/definition/context/test_function_processor.rb +0 -199
  137. data/test/holidays/definition/context/test_generator.rb +0 -226
  138. data/test/holidays/definition/context/test_load.rb +0 -37
  139. data/test/holidays/definition/context/test_merger.rb +0 -25
  140. data/test/holidays/definition/decorator/test_custom_method_proc.rb +0 -113
  141. data/test/holidays/definition/decorator/test_custom_method_source.rb +0 -96
  142. data/test/holidays/definition/decorator/test_test.rb +0 -123
  143. data/test/holidays/definition/generator/test_module.rb +0 -268
  144. data/test/holidays/definition/generator/test_regions.rb +0 -97
  145. data/test/holidays/definition/generator/test_test.rb +0 -113
  146. data/test/holidays/definition/parser/test_custom_method.rb +0 -79
  147. data/test/holidays/definition/parser/test_test.rb +0 -142
  148. data/test/holidays/definition/repository/test_cache.rb +0 -123
  149. data/test/holidays/definition/repository/test_custom_methods.rb +0 -43
  150. data/test/holidays/definition/repository/test_holidays_by_month.rb +0 -275
  151. data/test/holidays/definition/repository/test_proc_result_cache.rb +0 -91
  152. data/test/holidays/definition/repository/test_regions.rb +0 -104
  153. data/test/holidays/definition/validator/test_custom_method.rb +0 -94
  154. data/test/holidays/definition/validator/test_region.rb +0 -54
  155. data/test/holidays/definition/validator/test_test.rb +0 -60
  156. data/test/holidays/finder/context/test_between.rb +0 -172
  157. data/test/holidays/finder/context/test_dates_driver_builder.rb +0 -91
  158. data/test/holidays/finder/context/test_next_holiday.rb +0 -156
  159. data/test/holidays/finder/context/test_parse_options.rb +0 -141
  160. data/test/holidays/finder/context/test_search.rb +0 -290
  161. data/test/holidays/finder/context/test_year_holiday.rb +0 -202
  162. data/test/holidays/finder/rules/test_in_region.rb +0 -42
  163. data/test/holidays/finder/rules/test_year_range.rb +0 -166
  164. data/test/integration/README.md +0 -48
  165. data/test/integration/data/test_custom_govt_holiday_defs.yaml +0 -5
  166. data/test/integration/data/test_custom_informal_holidays_defs.yaml +0 -11
  167. data/test/integration/data/test_multiple_custom_holiday_defs.yaml +0 -12
  168. data/test/integration/test_custom_holidays.rb +0 -41
  169. data/test/integration/test_custom_informal_holidays.rb +0 -15
  170. data/test/integration/test_custom_year_range_holidays.rb +0 -35
  171. data/test/smoke/README.md +0 -31
  172. data/test/smoke/test_available_regions.rb +0 -18
  173. data/test/smoke/test_smoke.rb +0 -74
  174. data/test/test_helper.rb +0 -37
@@ -1,54 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../../test_helper'
2
-
3
- require 'holidays/date_calculator/weekend_modifier'
4
-
5
- class WeekendModifierDateCalculatorTests < Test::Unit::TestCase
6
- def setup
7
- @subject = Holidays::DateCalculator::WeekendModifier.new
8
- end
9
-
10
- def test_to_monday_if_weekend
11
- assert_equal Date.civil(2015, 5, 4), @subject.to_monday_if_weekend(Date.civil(2015, 5, 3))
12
- assert_equal Date.civil(2015, 5, 4), @subject.to_monday_if_weekend(Date.civil(2015, 5, 2))
13
- assert_equal Date.civil(2015, 5, 4), @subject.to_monday_if_weekend(Date.civil(2015, 5, 4))
14
- assert_equal Date.civil(2015, 5, 1), @subject.to_monday_if_weekend(Date.civil(2015, 5, 1))
15
- end
16
-
17
- def test_to_monday_if_sunday
18
- assert_equal Date.civil(2015, 5, 4), @subject.to_monday_if_sunday(Date.civil(2015, 5, 3))
19
- assert_equal Date.civil(2015, 5, 4), @subject.to_monday_if_sunday(Date.civil(2015, 5, 4))
20
- assert_equal Date.civil(2015, 5, 1), @subject.to_monday_if_sunday(Date.civil(2015, 5, 1))
21
- assert_equal Date.civil(2015, 5, 2), @subject.to_monday_if_sunday(Date.civil(2015, 5, 2))
22
- end
23
-
24
- def test_to_weekday_if_boxing_weekend
25
- assert_equal Date.civil(2015, 12, 25), @subject.to_weekday_if_boxing_weekend(Date.civil(2015, 12, 25))
26
- assert_equal Date.civil(2015, 12, 28), @subject.to_weekday_if_boxing_weekend(Date.civil(2015, 12, 26))
27
- assert_equal Date.civil(2015, 12, 29), @subject.to_weekday_if_boxing_weekend(Date.civil(2015, 12, 27))
28
- end
29
-
30
- def test_to_weekday_if_weekend
31
- assert_equal Date.civil(2015, 5, 4), @subject.to_weekday_if_weekend(Date.civil(2015, 5, 3))
32
- assert_equal Date.civil(2015, 5, 1), @subject.to_weekday_if_weekend(Date.civil(2015, 5, 2))
33
- end
34
-
35
- def test_to_weekday_if_boxing_weekend_from_year
36
- assert_equal Date.civil(2015, 12, 28), @subject.to_weekday_if_boxing_weekend_from_year(2015)
37
- end
38
-
39
- def test_to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday
40
- assert_equal Date.civil(2015, 12, 28), @subject.to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday(2015) # saturday to monday
41
- assert_equal Date.civil(2016, 12, 27), @subject.to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday(2016) # monday to tuesday
42
- end
43
-
44
- def test_to_tuesday_if_sunday_or_monday_if_saturday
45
- assert_equal Date.civil(2016, 12, 26), @subject.to_tuesday_if_sunday_or_monday_if_saturday(Date.civil(2016, 12, 24)) # sat to mon
46
- assert_equal Date.civil(2016, 12, 27), @subject.to_tuesday_if_sunday_or_monday_if_saturday(Date.civil(2016, 12, 25)) # sun to tue
47
- end
48
-
49
- def test_to_next_weekday
50
- assert_equal Date.civil(2016, 3, 21), @subject.to_next_weekday(Date.civil(2016, 3, 20))
51
- assert_equal Date.civil(2016, 3, 22), @subject.to_next_weekday(Date.civil(2016, 3, 21))
52
- assert_equal Date.civil(2016, 3, 28), @subject.to_next_weekday(Date.civil(2016, 3, 25))
53
- end
54
- end
@@ -1,199 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
-
3
- require 'holidays/definition/context/function_processor'
4
-
5
- class FunctionProcessorTests < Test::Unit::TestCase
6
- def setup
7
- @year = 2016
8
- @month = 1
9
- @day = 15
10
- @region = :test
11
- @input = { year: @year, month: @month, day: @day, region: @region }
12
-
13
- @func_id = "custom_function_id"
14
- @func_args = [:year]
15
- @func_modifier = 1
16
-
17
- @custom_methods_repo = mock()
18
- @proc_result_cache_repo = mock()
19
-
20
- @custom_func = mock()
21
-
22
- @custom_methods_repo.expects(:find).at_most_once.with(@func_id, @region).returns(@custom_func)
23
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns(Date.civil(@year, @month, @day))
24
-
25
- @subject = Holidays::Definition::Context::FunctionProcessor.new(
26
- @custom_methods_repo,
27
- @proc_result_cache_repo,
28
- )
29
- end
30
-
31
- def test_no_function_arguments_returns_error
32
- assert_raises ArgumentError do
33
- @subject.call(@input, @func_id, nil, @func_modifier)
34
- end
35
-
36
- assert_raises ArgumentError do
37
- @subject.call(@input, @func_id, [], @func_modifier)
38
- end
39
- end
40
-
41
- def test_unknown_function_argument_returns_error
42
- assert_raises ArgumentError do
43
- @subject.call(@input, @func_id, [:something], @func_modifier)
44
- end
45
- end
46
-
47
- def test_unknown_function_id_returns_error
48
- bad_id = "some-bad-id"
49
- @custom_methods_repo.expects(:find).at_most_once.with(bad_id, @region).returns(nil)
50
-
51
- assert_raises Holidays::FunctionNotFound do
52
- @subject.call(@input, bad_id, @func_args, @func_modifier)
53
- end
54
- end
55
-
56
- def test_year_arg_passed_to_func_call
57
- @func_args = [:year]
58
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns(Date.civil(2016, 1, 15))
59
-
60
- @subject.call(@input, @func_id, @func_args, @func_modifier)
61
- end
62
-
63
- def test_month_arg_passed_to_func_call
64
- @func_args = [:month]
65
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @month).returns(Date.civil(2016, 1, 15))
66
-
67
- @subject.call(@input, @func_id, @func_args, @func_modifier)
68
- end
69
-
70
- def test_day_arg_passed_to_func_call
71
- @func_args = [:day]
72
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @day).returns(Date.civil(2016, 1, 15))
73
-
74
- @subject.call(@input, @func_id, @func_args, @func_modifier)
75
- end
76
-
77
- def test_date_arg_passed_to_func_call
78
- @func_args = [:date]
79
- date = Date.civil(@year, @month, @day)
80
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, date).returns(date)
81
-
82
- @subject.call(@input, @func_id, @func_args, @func_modifier)
83
- end
84
-
85
- def test_multiple_args_passed_to_func_call
86
- @func_args = [:month, :day]
87
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @month, @day).returns(Date.civil(2016, 1, 15))
88
-
89
- @subject.call(@input, @func_id, @func_args, @func_modifier)
90
- end
91
-
92
- def test_multiple_args_with_region_passed_to_func_call
93
- @func_args = [:month, :day, :region]
94
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @month, @day, @region).returns(Date.civil(2016, 1, 15))
95
-
96
- @subject.call(@input, @func_id, @func_args, @func_modifier)
97
- end
98
-
99
- def test_call_returns_error_if_target_function_returns_unknown_value
100
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns("bad-response")
101
-
102
- assert_raises Holidays::InvalidFunctionResponse do
103
- @subject.call(@input, @func_id, @func_args, @func_modifier)
104
- end
105
- end
106
-
107
- def test_call_returns_date_with_modifier
108
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns(Date.civil(2016, 3, 10))
109
-
110
- result = @subject.call(@input, @func_id, @func_args, @func_modifier)
111
-
112
- assert_equal(Date.civil(2016, 3, 10) + @func_modifier, result)
113
- end
114
-
115
- def test_call_returns_date_no_modifier
116
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns(Date.civil(2016, 3, 10))
117
-
118
- result = @subject.call(@input, @func_id, @func_args, nil)
119
-
120
- assert_equal(Date.civil(2016, 3, 10), result)
121
- end
122
-
123
- def test_call_returns_errors_when_custom_function_returns_non_date
124
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns("bad")
125
-
126
- assert_raises Holidays::InvalidFunctionResponse do
127
- @subject.call(@input, @func_id, @func_args, nil)
128
- end
129
- end
130
-
131
- def test_call_returns_error_when_custom_function_returns_mday_but_resulting_date_is_invalid
132
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns(32)
133
-
134
- assert_raises Holidays::InvalidFunctionResponse do
135
- @subject.call(@input, @func_id, @func_args, nil)
136
- end
137
- end
138
-
139
- def test_call_returns_integer_returns_modified_date
140
- @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns(7)
141
-
142
- result = @subject.call(@input, @func_id, @func_args, nil)
143
-
144
- assert_equal(Date.civil(2016, 1, 7), result)
145
- end
146
-
147
- def test_func_modifier_not_required
148
- result = @subject.call(@input, @func_id, @func_args)
149
- assert_equal(Date.civil(2016, 1, 15), result)
150
- end
151
-
152
- def test_validate_returns_error_if_year_not_a_number
153
- @input[:year] = 'bad-year'
154
- assert_raises ArgumentError do
155
- @subject.call(@input, @func_id, @func_args)
156
- end
157
- end
158
-
159
- def test_validate_returns_error_if_month_not_valid
160
- @input[:month] = 'bad-month'
161
- assert_raises ArgumentError do
162
- @subject.call(@input, @func_id, [:month])
163
- end
164
-
165
- @input[:month] = -1
166
- assert_raises ArgumentError do
167
- @subject.call(@input, @func_id, [:month])
168
- end
169
-
170
- @input[:month] = 13
171
- assert_raises ArgumentError do
172
- @subject.call(@input, @func_id, [:month])
173
- end
174
- end
175
-
176
- def test_validate_returns_error_if_day_is_not_valid
177
- @input[:day] = 0
178
- assert_raises ArgumentError do
179
- @subject.call(@input, @func_id, [:day])
180
- end
181
-
182
- @input[:day] = 32
183
- assert_raises ArgumentError do
184
- @subject.call(@input, @func_id, [:day])
185
- end
186
-
187
- @input[:day] = 'bad-day'
188
- assert_raises ArgumentError do
189
- @subject.call(@input, @func_id, [:day])
190
- end
191
- end
192
-
193
- def test_validate_returns_error_if_region_not_a_symbol
194
- @input[:region] = 'blah'
195
- assert_raises ArgumentError do
196
- @subject.call(@input, @func_id, [:region])
197
- end
198
- end
199
- end
@@ -1,226 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
-
3
- require 'holidays/definition/context/generator'
4
-
5
- class GeneratorTests < Test::Unit::TestCase
6
- def setup
7
- @custom_method_parser = mock()
8
- @custom_method_source_decorator = mock()
9
- @custom_methods_repository = mock()
10
-
11
- @parsed_custom_method = Holidays::Definition::Entity::CustomMethod.new(
12
- name: 'custom_method',
13
- arguments: [:year, :month],
14
- source: "some source",
15
- )
16
-
17
- @test_parser = mock()
18
- @test_source_generator = mock()
19
-
20
- @module_source_generator = mock()
21
-
22
- @generator = Holidays::Definition::Context::Generator.new(
23
- @custom_method_parser,
24
- @custom_method_source_decorator,
25
- @custom_methods_repository,
26
- @test_parser,
27
- @test_source_generator,
28
- @module_source_generator,
29
- )
30
- end
31
-
32
- def test_parse_definition_files_raises_error_if_argument_is_nil
33
- assert_raises ArgumentError do
34
- @generator.parse_definition_files(nil)
35
- end
36
- end
37
-
38
- def test_parse_definition_files_raises_error_if_files_are_empty
39
- assert_raises ArgumentError do
40
- @generator.parse_definition_files([])
41
- end
42
- end
43
-
44
- def test_parse_definition_files_correctly_parse_regions
45
- files = ['test/data/test_single_custom_holiday_defs.yaml']
46
- @custom_method_parser.expects(:call).with(nil).returns({})
47
-
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]
51
-
52
- assert_equal [:custom_single_file], regions
53
- end
54
-
55
- def test_parse_definitions_files_correctly_parse_rules_by_month
56
- files = ['test/data/test_single_custom_holiday_defs.yaml']
57
- @custom_method_parser.expects(:call).with(nil).returns({})
58
-
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]
62
-
63
- expected_rules_by_month = {
64
- 6 => [
65
- {
66
- :mday => 20,
67
- :name => "Company Founding",
68
- :regions => [:custom_single_file]
69
- }
70
- ]
71
- }
72
-
73
- assert_equal expected_rules_by_month, rules_by_month
74
- end
75
-
76
- def test_parse_definition_files_correctly_parse_custom_methods
77
- files = ['test/data/test_single_custom_holiday_defs.yaml']
78
- @custom_method_parser.expects(:call).with(nil).returns({})
79
-
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]
83
-
84
- expected_custom_methods = {}
85
- assert_equal expected_custom_methods, custom_methods
86
- end
87
-
88
- def test_parse_definition_files_correctly_parse_tests
89
- files = ['test/data/test_single_custom_holiday_defs.yaml']
90
- @custom_method_parser.expects(:call).with(nil).returns({})
91
-
92
- @test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
93
-
94
- parsed_tests = @generator.parse_definition_files(files)[3]
95
-
96
- assert_equal ["parsed tests"], parsed_tests
97
- end
98
-
99
- def test_generate_definition_source_correctly_generate_module_src
100
- files = ['test/data/test_single_custom_holiday_defs.yaml']
101
- @custom_method_parser.expects(:call).with(nil).returns({})
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
-
108
- regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
109
- module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
110
-
111
- expected_module_src = "module source"
112
-
113
- assert_equal expected_module_src, module_src
114
- end
115
-
116
- def test_generate_definition_source_correctly_generate_test_src
117
- files = ['test/data/test_single_custom_holiday_defs.yaml']
118
- @custom_method_parser.expects(:call).with(nil).returns({})
119
-
120
- @test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
121
-
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]
128
-
129
- assert_equal 'test source', test_src
130
- end
131
-
132
- def test_parse_definitions_files_correctly_parse_year_range_by_month
133
- files = ['test/data/test_custom_year_range_holiday_defs.yaml']
134
- @custom_method_parser.expects(:call).with(nil).returns({})
135
-
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]
139
-
140
- expected_rules_by_month = {
141
- 6 => [
142
- {
143
- :name => "after_year",
144
- :regions => [:custom_year_range_file],
145
- :mday => 1,
146
- :year_ranges => {:from => 2016}
147
- },
148
- {
149
- :name => "before_year",
150
- :regions => [:custom_year_range_file],
151
- :mday => 2,
152
- :year_ranges => {:until => 2017}
153
- },
154
- {
155
- :name => "between_year",
156
- :regions => [:custom_year_range_file],
157
- :mday => 3,
158
- :year_ranges => {:between => 2016..2018 }
159
- },
160
- {
161
- :name => "limited_year",
162
- :regions => [:custom_year_range_file],
163
- :mday => 4,
164
- :year_ranges => {:limited => [2016,2018,2019]}
165
- }
166
- ]
167
- }
168
-
169
- assert_equal expected_rules_by_month, rules_by_month
170
- end
171
-
172
- def test_generate_definition_source_correctly_generate_yearrange_test_src
173
- files = ['test/data/test_custom_year_range_holiday_defs.yaml']
174
- @custom_method_parser.expects(:call).with(nil).returns({})
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
-
182
- regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
183
- module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
184
- expected_module_src = "module_source"
185
-
186
- assert_equal expected_module_src, module_src
187
- end
188
-
189
- def test_generate_definition_source_correctly_generate_module_src_with_custom_methods
190
- files = ['test/data/test_single_custom_holiday_with_custom_procs.yaml']
191
-
192
- @custom_method_parser.expects(:call).with(equals({'custom_method' => {'arguments' => 'year, month', 'source' => "d = Date.civil(year, month, 1)\nd + 2\n"}})).returns({"custom_method(year, month)" => @parsed_custom_method})
193
- @custom_methods_repository.expects(:find).twice.with('custom_method(year, month)').returns(nil)
194
- @custom_method_source_decorator.expects(:call).once.with(@parsed_custom_method).returns("\"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n}")
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
-
201
- regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
202
- module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
203
-
204
- expected_module_src = "module source"
205
-
206
- assert_equal expected_module_src, module_src
207
- end
208
-
209
- def test_generate_definition_source_correctly_generate_test_src_with_custom_methods
210
- files = ['test/data/test_single_custom_holiday_with_custom_procs.yaml']
211
-
212
- @custom_method_parser.expects(:call).with(equals({'custom_method' => {'arguments' => 'year, month', 'source' => "d = Date.civil(year, month, 1)\nd + 2\n"}})).returns({"custom_method(year, month)" => @parsed_custom_method})
213
- @custom_methods_repository.expects(:find).twice.with('custom_method(year, month)').returns(nil)
214
- @custom_method_source_decorator.expects(:call).once.with(@parsed_custom_method).returns("\"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n}")
215
-
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')
220
-
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]
223
-
224
- assert_equal 'test source', test_src
225
- end
226
- end
@@ -1,37 +0,0 @@
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
@@ -1,25 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
-
3
- require 'holidays/definition/context/merger'
4
-
5
- class MergerTests < Test::Unit::TestCase
6
- def setup
7
- @target_regions = [:new_region]
8
- @target_holidays = {0 => [:mday => 1, :name => "Test", :regions => [:test2, :test]]}
9
- @target_custom_methods = {"test_method" => Proc.new { |year| Date.civil(year, 1, 1) } }
10
-
11
- @holidays_repo = mock()
12
- @regions_repo = mock()
13
- @custom_methods_repo = mock()
14
-
15
- @subject = Holidays::Definition::Context::Merger.new(@holidays_repo, @regions_repo, @custom_methods_repo)
16
- end
17
-
18
- def test_repos_are_called_to_add_regions_and_holidays
19
- @holidays_repo.expects(:add).with(@target_holidays)
20
- @regions_repo.expects(:add).with(@target_regions)
21
- @custom_methods_repo.expects(:add).with(@target_custom_methods, {}, {})
22
-
23
- @subject.call(@target_regions, @target_holidays, @target_custom_methods)
24
- end
25
- end
@@ -1,113 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
-
3
- require 'holidays/definition/decorator/custom_method_proc'
4
- require 'holidays/definition/entity/custom_method'
5
-
6
- class DecoratorCustomMethodProcTests < Test::Unit::TestCase
7
- def setup
8
- @decorator = Holidays::Definition::Decorator::CustomMethodProc.new
9
- end
10
-
11
- def test_generates_lambda_from_entity
12
- entity = Holidays::Definition::Entity::CustomMethod.new(
13
- name: "test",
14
- arguments: ["year"],
15
- source: "Date.civil(year, 1, 1)"
16
- )
17
-
18
- proc = @decorator.call(entity)
19
- expected_proc = Proc.new { |year| eval("Date.civil(year, 1, 1)") }
20
-
21
- assert_equal expected_proc.call(2015), proc.call(2015)
22
- end
23
-
24
- def test_generates_lamba_from_entity_with_multiple_lines
25
- entity = Holidays::Definition::Entity::CustomMethod.new(
26
- name: "test",
27
- arguments: ["year"],
28
- source: "d = Date.civil(year, 1, 1)\nd + 2"
29
- )
30
-
31
- proc = @decorator.call(entity)
32
- expected_proc = Proc.new { |year| eval("d = Date.civil(year, 1, 1)\nd + 2") }
33
-
34
- assert_equal expected_proc.call(2015), proc.call(2015)
35
- end
36
-
37
- def test_generates_lamba_from_entity_with_multiple_arguments
38
- entity = Holidays::Definition::Entity::CustomMethod.new(
39
- name: "test",
40
- arguments: ["year", "month"],
41
- source: "Date.civil(year, month, 1)"
42
- )
43
-
44
- proc = @decorator.call(entity)
45
- expected_proc = Proc.new { |year, month| eval("Date.civil(year, month, 1)") }
46
-
47
- assert_equal expected_proc.call(2015, 6), proc.call(2015, 6)
48
- end
49
-
50
- def test_generate_returns_error_if_missing_name
51
- entity = Holidays::Definition::Entity::CustomMethod.new(
52
- arguments: ["year", "month"],
53
- source: "Date.civil(year, month, 1)"
54
- )
55
-
56
- assert_raises ArgumentError do
57
- @decorator.call(entity)
58
- end
59
-
60
- entity = Holidays::Definition::Entity::CustomMethod.new(
61
- name: "",
62
- arguments: ["year", "month"],
63
- source: "Date.civil(year, month, 1)"
64
- )
65
-
66
- assert_raises ArgumentError do
67
- @decorator.call(entity)
68
- end
69
- end
70
-
71
- def test_generate_returns_error_if_arguments_is_missing
72
- entity = Holidays::Definition::Entity::CustomMethod.new(
73
- name: "test",
74
- source: "Date.civil(year, month, 1)"
75
- )
76
-
77
- assert_raises ArgumentError do
78
- @decorator.call(entity)
79
- end
80
-
81
- entity = Holidays::Definition::Entity::CustomMethod.new(
82
- name: "test",
83
- arguments: [],
84
- source: "Date.civil(year, month, 1)"
85
- )
86
-
87
- assert_raises ArgumentError do
88
- @decorator.call(entity)
89
- end
90
- end
91
-
92
-
93
- def test_generate_returns_error_if_source_is_missing
94
- entity = Holidays::Definition::Entity::CustomMethod.new(
95
- name: "test",
96
- arguments: ["year"],
97
- )
98
-
99
- assert_raises ArgumentError do
100
- @decorator.call(entity)
101
- end
102
-
103
- entity = Holidays::Definition::Entity::CustomMethod.new(
104
- name: "test",
105
- arguments: ["year"],
106
- source: "",
107
- )
108
-
109
- assert_raises ArgumentError do
110
- @decorator.call(entity)
111
- end
112
- end
113
- end