holidays 6.6.1 → 8.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +25 -0
- data/CHANGELOG.md +76 -0
- data/README.md +74 -60
- data/doc/CONTRIBUTING.md +2 -1
- data/holidays.gemspec +10 -5
- data/lib/generated_definitions/MANIFEST +13 -5
- data/lib/generated_definitions/REGIONS.rb +2 -2
- data/lib/generated_definitions/ar.rb +28 -9
- data/lib/generated_definitions/at.rb +2 -2
- data/lib/generated_definitions/au.rb +60 -12
- data/lib/generated_definitions/be_fr.rb +2 -2
- data/lib/generated_definitions/be_nl.rb +2 -2
- data/lib/generated_definitions/bg.rb +2 -2
- data/lib/generated_definitions/br.rb +4 -3
- data/lib/generated_definitions/ca.rb +25 -17
- data/lib/generated_definitions/ch.rb +15 -3
- data/lib/generated_definitions/cl.rb +7 -7
- data/lib/generated_definitions/co.rb +2 -2
- data/lib/generated_definitions/cr.rb +2 -2
- data/lib/generated_definitions/cz.rb +2 -2
- data/lib/generated_definitions/de.rb +12 -7
- data/lib/generated_definitions/dk.rb +3 -3
- data/lib/generated_definitions/{ecb_target.rb → ecbtarget.rb} +10 -10
- data/lib/generated_definitions/ee.rb +2 -2
- data/lib/generated_definitions/el.rb +2 -2
- data/lib/generated_definitions/es.rb +6 -4
- data/lib/generated_definitions/europe.rb +135 -46
- data/lib/generated_definitions/{federal_reserve.rb → federalreserve.rb} +15 -14
- data/lib/generated_definitions/federalreservebanks.rb +35 -0
- data/lib/generated_definitions/fedex.rb +2 -2
- data/lib/generated_definitions/fi.rb +2 -2
- data/lib/generated_definitions/fr.rb +4 -4
- data/lib/generated_definitions/gb.rb +15 -7
- data/lib/generated_definitions/ge.rb +2 -2
- data/lib/generated_definitions/gr.rb +38 -0
- data/lib/generated_definitions/hk.rb +2 -2
- data/lib/generated_definitions/hr.rb +10 -8
- data/lib/generated_definitions/hu.rb +4 -3
- data/lib/generated_definitions/ie.rb +2 -2
- data/lib/generated_definitions/is.rb +2 -2
- data/lib/generated_definitions/it.rb +16 -7
- data/lib/generated_definitions/jp.rb +31 -16
- data/lib/generated_definitions/ke.rb +34 -0
- data/lib/generated_definitions/kr.rb +2 -2
- data/lib/generated_definitions/kz.rb +38 -0
- data/lib/generated_definitions/li.rb +2 -2
- data/lib/generated_definitions/lt.rb +4 -3
- data/lib/generated_definitions/lu.rb +4 -2
- data/lib/generated_definitions/lv.rb +56 -0
- data/lib/generated_definitions/ma.rb +2 -2
- data/lib/generated_definitions/mt_en.rb +2 -2
- data/lib/generated_definitions/mt_mt.rb +2 -2
- data/lib/generated_definitions/mx.rb +7 -7
- data/lib/generated_definitions/my.rb +2 -2
- data/lib/generated_definitions/nerc.rb +2 -2
- data/lib/generated_definitions/ng.rb +33 -0
- data/lib/generated_definitions/nl.rb +2 -2
- data/lib/generated_definitions/no.rb +2 -2
- data/lib/generated_definitions/{north_america.rb → northamerica.rb} +34 -26
- data/lib/generated_definitions/nyse.rb +3 -2
- data/lib/generated_definitions/nz.rb +43 -4
- data/lib/generated_definitions/pe.rb +2 -2
- data/lib/generated_definitions/ph.rb +2 -2
- data/lib/generated_definitions/pl.rb +2 -2
- data/lib/generated_definitions/pt.rb +2 -2
- data/lib/generated_definitions/ro.rb +6 -3
- data/lib/generated_definitions/rs_cyrl.rb +3 -3
- data/lib/generated_definitions/rs_la.rb +3 -3
- data/lib/generated_definitions/ru.rb +2 -2
- data/lib/generated_definitions/scandinavia.rb +3 -3
- data/lib/generated_definitions/se.rb +2 -2
- data/lib/generated_definitions/sg.rb +2 -2
- data/lib/generated_definitions/si.rb +4 -3
- data/lib/generated_definitions/sk.rb +2 -2
- data/lib/generated_definitions/{south_america.rb → southamerica.rb} +33 -13
- data/lib/generated_definitions/th.rb +36 -0
- data/lib/generated_definitions/tn.rb +2 -2
- data/lib/generated_definitions/tr.rb +7 -5
- data/lib/generated_definitions/ua.rb +37 -0
- data/lib/generated_definitions/{united_nations.rb → unitednations.rb} +61 -61
- data/lib/generated_definitions/ups.rb +2 -2
- data/lib/generated_definitions/us.rb +9 -9
- data/lib/generated_definitions/ve.rb +2 -2
- data/lib/generated_definitions/vi.rb +2 -2
- data/lib/generated_definitions/za.rb +3 -3
- data/lib/holidays/definition/context/generator.rb +23 -70
- data/lib/holidays/definition/generator/module.rb +54 -0
- data/lib/holidays/definition/generator/regions.rb +1 -1
- data/lib/holidays/definition/repository/holidays_by_month.rb +9 -1
- data/lib/holidays/factory/definition.rb +7 -0
- data/lib/holidays/finder/context/search.rb +35 -31
- data/lib/holidays/finder/rules/year_range.rb +30 -54
- data/lib/holidays/version.rb +1 -1
- data/lib/holidays.rb +2 -0
- data/test/coverage_report.rb +23 -5
- data/test/data/test_custom_year_range_holiday_defs.yaml +6 -10
- data/test/data/test_multiple_regions_with_conflicts_region_1.yaml +38 -0
- data/test/data/test_multiple_regions_with_conflicts_region_2.yaml +38 -0
- data/test/defs/test_defs_ar.rb +20 -4
- data/test/defs/test_defs_au.rb +33 -0
- data/test/defs/test_defs_br.rb +4 -0
- data/test/defs/test_defs_ca.rb +71 -8
- data/test/defs/test_defs_ch.rb +4 -0
- data/test/defs/test_defs_co.rb +3 -3
- data/test/defs/test_defs_de.rb +10 -0
- data/test/defs/test_defs_dk.rb +4 -0
- data/test/defs/{test_defs_ecb_target.rb → test_defs_ecbtarget.rb} +11 -11
- data/test/defs/test_defs_es.rb +2 -0
- data/test/defs/test_defs_europe.rb +262 -39
- data/test/defs/test_defs_federalreserve.rb +119 -0
- data/test/defs/test_defs_federalreservebanks.rb +251 -0
- data/test/defs/test_defs_fr.rb +3 -3
- data/test/defs/test_defs_gb.rb +42 -0
- data/test/defs/{test_defs_el.rb → test_defs_gr.rb} +18 -18
- data/test/defs/test_defs_hr.rb +6 -6
- data/test/defs/test_defs_hu.rb +12 -4
- data/test/defs/test_defs_it.rb +20 -0
- data/test/defs/test_defs_jp.rb +22 -2
- data/test/defs/test_defs_ke.rb +31 -0
- data/test/defs/test_defs_kz.rb +39 -0
- data/test/defs/test_defs_lt.rb +2 -0
- data/test/defs/test_defs_lu.rb +6 -0
- data/test/defs/test_defs_lv.rb +98 -0
- data/test/defs/test_defs_mx.rb +3 -1
- data/test/defs/test_defs_ng.rb +29 -0
- data/test/defs/{test_defs_north_america.rb → test_defs_northamerica.rb} +85 -20
- data/test/defs/test_defs_nyse.rb +7 -0
- data/test/defs/test_defs_nz.rb +8 -0
- data/test/defs/test_defs_ro.rb +14 -0
- data/test/defs/test_defs_rs_cyrl.rb +1 -1
- data/test/defs/test_defs_rs_la.rb +1 -1
- data/test/defs/test_defs_scandinavia.rb +4 -0
- data/test/defs/{test_defs_south_america.rb → test_defs_southamerica.rb} +29 -9
- data/test/defs/test_defs_th.rb +33 -0
- data/test/defs/test_defs_tr.rb +7 -0
- data/test/defs/test_defs_ua.rb +41 -0
- data/test/defs/{test_defs_united_nations.rb → test_defs_unitednations.rb} +3 -3
- data/test/defs/test_defs_us.rb +11 -11
- data/test/holidays/core_extensions/test_date.rb +3 -2
- data/test/holidays/definition/context/test_generator.rb +17 -20
- data/test/holidays/definition/generator/test_module.rb +268 -0
- data/test/holidays/definition/repository/test_holidays_by_month.rb +121 -1
- data/test/holidays/finder/rules/test_year_range.rb +43 -47
- data/test/integration/test_available_regions.rb +1 -1
- data/test/integration/test_custom_year_range_holidays.rb +0 -7
- data/test/integration/test_holidays.rb +2 -36
- data/test/integration/test_holidays_between.rb +11 -1
- data/test/integration/test_multiple_regions_with_conflict.rb +29 -0
- data/test/integration/test_nonstandard_regions.rb +25 -0
- metadata +71 -35
- data/test/defs/test_defs_federal_reserve.rb +0 -113
@@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
|
3
3
|
|
4
4
|
# This file is generated by the Ruby Holiday gem.
|
5
5
|
#
|
6
|
-
# Definitions loaded: definitions/
|
7
|
-
class
|
6
|
+
# Definitions loaded: definitions/unitednations.yaml
|
7
|
+
class UnitednationsDefinitionTests < Test::Unit::TestCase # :nodoc:
|
8
8
|
|
9
|
-
def
|
9
|
+
def test_unitednations
|
10
10
|
end
|
11
11
|
end
|
data/test/defs/test_defs_us.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
|
3
3
|
|
4
4
|
# This file is generated by the Ruby Holiday gem.
|
5
5
|
#
|
6
|
-
# Definitions loaded: definitions/us.yaml, definitions/
|
6
|
+
# Definitions loaded: definitions/us.yaml, definitions/northamericainformal.yaml
|
7
7
|
class UsDefinitionTests < Test::Unit::TestCase # :nodoc:
|
8
8
|
|
9
9
|
def test_us
|
@@ -87,10 +87,6 @@ assert_equal "Presidents' Day", (Holidays.on(Date.civil(2018, 2, 19), [:us])[0]
|
|
87
87
|
assert_nil (Holidays.on(Date.civil(2018, 3, 5), [:us])[0] || {})[:name]
|
88
88
|
assert_nil (Holidays.on(Date.civil(2019, 3, 4), [:us])[0] || {})[:name]
|
89
89
|
|
90
|
-
assert_equal "Casimir Pulaski Day", (Holidays.on(Date.civil(2017, 3, 6), [:us_il])[0] || {})[:name]
|
91
|
-
assert_equal "Casimir Pulaski Day", (Holidays.on(Date.civil(2018, 3, 5), [:us_il])[0] || {})[:name]
|
92
|
-
assert_equal "Casimir Pulaski Day", (Holidays.on(Date.civil(2019, 3, 4), [:us_il])[0] || {})[:name]
|
93
|
-
|
94
90
|
assert_nil (Holidays.on(Date.civil(2017, 3, 7), [:us])[0] || {})[:name]
|
95
91
|
assert_nil (Holidays.on(Date.civil(2018, 3, 6), [:us])[0] || {})[:name]
|
96
92
|
assert_nil (Holidays.on(Date.civil(2019, 3, 5), [:us])[0] || {})[:name]
|
@@ -127,7 +123,7 @@ assert_equal "Seward's Day", (Holidays.on(Date.civil(2019, 3, 25), [:us_ak])[0]
|
|
127
123
|
assert_equal "Emancipation Day", (Holidays.on(Date.civil(2022, 4, 15), [:us_dc, :us_ca], [:observed])[0] || {})[:name]
|
128
124
|
assert_equal "Emancipation Day", (Holidays.on(Date.civil(2028, 4, 17), [:us_dc, :us_ca], [:observed])[0] || {})[:name]
|
129
125
|
|
130
|
-
assert_equal "Emancipation Day", (Holidays.on(Date.civil(2017, 4, 16), [:us_dc
|
126
|
+
assert_equal "Emancipation Day", (Holidays.on(Date.civil(2017, 4, 16), [:us_dc])[0] || {})[:name]
|
131
127
|
|
132
128
|
assert_nil (Holidays.on(Date.civil(2017, 4, 17), [:us])[0] || {})[:name]
|
133
129
|
assert_nil (Holidays.on(Date.civil(2018, 4, 16), [:us])[0] || {})[:name]
|
@@ -197,6 +193,10 @@ assert_equal "King Kamehameha I Day", (Holidays.on(Date.civil(2022, 6, 10), [:us
|
|
197
193
|
|
198
194
|
assert_equal "King Kamehameha I Day", (Holidays.on(Date.civil(2017, 6, 11), [:us_hi])[0] || {})[:name]
|
199
195
|
|
196
|
+
assert_nil (Holidays.on(Date.civil(2021, 6, 19), [:us], [:observed])[0] || {})[:name]
|
197
|
+
|
198
|
+
assert_equal "Juneteenth National Independence Day", (Holidays.on(Date.civil(2021, 6, 18), [:us], [:observed])[0] || {})[:name]
|
199
|
+
|
200
200
|
assert_equal "Emancipation Day in Texas", (Holidays.on(Date.civil(2017, 6, 19), [:us_tx])[0] || {})[:name]
|
201
201
|
|
202
202
|
assert_nil (Holidays.on(Date.civil(2017, 6, 20), [:us])[0] || {})[:name]
|
@@ -303,9 +303,9 @@ assert_equal "Nevada Day", (Holidays.on(Date.civil(2019, 10, 25), [:us_nv])[0] |
|
|
303
303
|
assert_nil (Holidays.on(Date.civil(2018, 11, 6), [:us])[0] || {})[:name]
|
304
304
|
assert_nil (Holidays.on(Date.civil(2021, 11, 2), [:us])[0] || {})[:name]
|
305
305
|
|
306
|
-
assert_equal "Election Day", (Holidays.on(Date.civil(2017, 11, 7), [:us_de, :us_hi, :
|
307
|
-
assert_equal "Election Day", (Holidays.on(Date.civil(2018, 11, 6), [:us_de, :us_hi, :
|
308
|
-
assert_equal "Election Day", (Holidays.on(Date.civil(2021, 11, 2), [:us_de, :us_hi, :
|
306
|
+
assert_equal "Election Day", (Holidays.on(Date.civil(2017, 11, 7), [:us_de, :us_hi, :us_in, :us_mt, :us_nj, :us_ny, :us_pa, :us_ri])[0] || {})[:name]
|
307
|
+
assert_equal "Election Day", (Holidays.on(Date.civil(2018, 11, 6), [:us_de, :us_hi, :us_in, :us_mt, :us_nj, :us_ny, :us_pa, :us_ri])[0] || {})[:name]
|
308
|
+
assert_equal "Election Day", (Holidays.on(Date.civil(2021, 11, 2), [:us_de, :us_hi, :us_in, :us_mt, :us_nj, :us_ny, :us_pa, :us_ri])[0] || {})[:name]
|
309
309
|
|
310
310
|
assert_equal "Veterans Day", (Holidays.on(Date.civil(2017, 11, 10), [:us], [:observed])[0] || {})[:name]
|
311
311
|
assert_equal "Veterans Day", (Holidays.on(Date.civil(2018, 11, 12), [:us], [:observed])[0] || {})[:name]
|
@@ -355,9 +355,9 @@ assert_equal "Christmas Eve (Holiday)", (Holidays.on(Date.civil(2028, 12, 22), [
|
|
355
355
|
assert_nil (Holidays.on(Date.civil(2022, 12, 26), [:us])[0] || {})[:name]
|
356
356
|
assert_nil (Holidays.on(Date.civil(2027, 12, 27), [:us])[0] || {})[:name]
|
357
357
|
|
358
|
-
assert_equal "Christmas Day", (Holidays.on(Date.civil(2021, 12,
|
358
|
+
assert_equal "Christmas Day", (Holidays.on(Date.civil(2021, 12, 24), [:us], [:observed])[0] || {})[:name]
|
359
359
|
assert_equal "Christmas Day", (Holidays.on(Date.civil(2022, 12, 26), [:us], [:observed])[0] || {})[:name]
|
360
|
-
assert_equal "Christmas Day", (Holidays.on(Date.civil(2027, 12,
|
360
|
+
assert_equal "Christmas Day", (Holidays.on(Date.civil(2027, 12, 24), [:us], [:observed])[0] || {})[:name]
|
361
361
|
|
362
362
|
assert_equal "Christmas Day", (Holidays.on(Date.civil(2017, 12, 25), [:us])[0] || {})[:name]
|
363
363
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__)) + '/../../test_helper'
|
2
2
|
|
3
|
+
require 'date'
|
3
4
|
require 'holidays/core_extensions/date'
|
4
5
|
|
5
6
|
class Date
|
@@ -114,8 +115,8 @@ class CoreExtensionDateTests < Test::Unit::TestCase
|
|
114
115
|
|
115
116
|
def test_datetime_holiday?
|
116
117
|
# in situations with activesupport
|
117
|
-
assert DateTime.
|
118
|
-
assert DateTime.
|
118
|
+
assert DateTime.civil(2008, 1, 1).to_date.holiday?('ca')
|
119
|
+
assert DateTime.civil(2008, 1, 1).holiday?('ca')
|
119
120
|
end
|
120
121
|
|
121
122
|
end
|
@@ -17,12 +17,15 @@ class GeneratorTests < Test::Unit::TestCase
|
|
17
17
|
@test_parser = mock()
|
18
18
|
@test_source_generator = mock()
|
19
19
|
|
20
|
+
@module_source_generator = mock()
|
21
|
+
|
20
22
|
@generator = Holidays::Definition::Context::Generator.new(
|
21
23
|
@custom_method_parser,
|
22
24
|
@custom_method_source_decorator,
|
23
25
|
@custom_methods_repository,
|
24
26
|
@test_parser,
|
25
27
|
@test_source_generator,
|
28
|
+
@module_source_generator,
|
26
29
|
)
|
27
30
|
end
|
28
31
|
|
@@ -99,12 +102,13 @@ class GeneratorTests < Test::Unit::TestCase
|
|
99
102
|
|
100
103
|
@test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
|
101
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")
|
102
106
|
@test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_defs.yaml'], ['parsed tests']).returns("test source")
|
103
107
|
|
104
108
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
105
109
|
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
106
110
|
|
107
|
-
expected_module_src = "
|
111
|
+
expected_module_src = "module source"
|
108
112
|
|
109
113
|
assert_equal expected_module_src, module_src
|
110
114
|
end
|
@@ -115,6 +119,8 @@ class GeneratorTests < Test::Unit::TestCase
|
|
115
119
|
|
116
120
|
@test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
|
117
121
|
|
122
|
+
@module_source_generator.expects(:call).returns("module_source")
|
123
|
+
|
118
124
|
@test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_defs.yaml'], ['parsed tests']).returns("test source")
|
119
125
|
|
120
126
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
@@ -137,31 +143,25 @@ class GeneratorTests < Test::Unit::TestCase
|
|
137
143
|
:name => "after_year",
|
138
144
|
:regions => [:custom_year_range_file],
|
139
145
|
:mday => 1,
|
140
|
-
:year_ranges =>
|
146
|
+
:year_ranges => {:from => 2016}
|
141
147
|
},
|
142
148
|
{
|
143
149
|
:name => "before_year",
|
144
150
|
:regions => [:custom_year_range_file],
|
145
151
|
:mday => 2,
|
146
|
-
:year_ranges =>
|
152
|
+
:year_ranges => {:until => 2017}
|
147
153
|
},
|
148
154
|
{
|
149
155
|
:name => "between_year",
|
150
156
|
:regions => [:custom_year_range_file],
|
151
157
|
:mday => 3,
|
152
|
-
:year_ranges =>
|
158
|
+
:year_ranges => {:between => 2016..2018 }
|
153
159
|
},
|
154
160
|
{
|
155
161
|
:name => "limited_year",
|
156
162
|
:regions => [:custom_year_range_file],
|
157
163
|
:mday => 4,
|
158
|
-
:year_ranges =>
|
159
|
-
},
|
160
|
-
{
|
161
|
-
:name => "multiple_conditions",
|
162
|
-
:regions => [:custom_year_range_file],
|
163
|
-
:mday => 5,
|
164
|
-
:year_ranges => [{"before" => 2015}, {"after" => 2017}]
|
164
|
+
:year_ranges => {:limited => [2016,2018,2019]}
|
165
165
|
}
|
166
166
|
]
|
167
167
|
}
|
@@ -177,9 +177,11 @@ class GeneratorTests < Test::Unit::TestCase
|
|
177
177
|
|
178
178
|
@test_source_generator.expects(:call).with('test', ['test/data/test_custom_year_range_holiday_defs.yaml'], ['parsed tests']).returns('test source')
|
179
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
|
+
|
180
182
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
181
183
|
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
182
|
-
expected_module_src = "
|
184
|
+
expected_module_src = "module_source"
|
183
185
|
|
184
186
|
assert_equal expected_module_src, module_src
|
185
187
|
end
|
@@ -193,12 +195,13 @@ class GeneratorTests < Test::Unit::TestCase
|
|
193
195
|
|
194
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'])
|
195
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")
|
196
199
|
@test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_with_custom_procs.yaml'], ['parsed tests']).returns('test source')
|
197
200
|
|
198
201
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
199
202
|
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
200
203
|
|
201
|
-
expected_module_src = "
|
204
|
+
expected_module_src = "module source"
|
202
205
|
|
203
206
|
assert_equal expected_module_src, module_src
|
204
207
|
end
|
@@ -212,6 +215,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
212
215
|
|
213
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'])
|
214
217
|
|
218
|
+
@module_source_generator.expects(:call).returns("module_source")
|
215
219
|
@test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_with_custom_procs.yaml'], ['parsed tests']).returns('test source')
|
216
220
|
|
217
221
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
@@ -219,11 +223,4 @@ class GeneratorTests < Test::Unit::TestCase
|
|
219
223
|
|
220
224
|
assert_equal 'test source', test_src
|
221
225
|
end
|
222
|
-
|
223
|
-
#TODO Missing test scenarios. Adding here so I don't forget when I split this
|
224
|
-
# apart into smaller components.
|
225
|
-
#
|
226
|
-
# 1) If a year_range contains empty entries then we should blow up.
|
227
|
-
# 2) If year_range contains invalid (i.e. too many types per entry) then
|
228
|
-
# we should blow up
|
229
226
|
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
|
@@ -109,7 +109,7 @@ class HolidaysByMonthRepoTests < Test::Unit::TestCase
|
|
109
109
|
assert_equal(expected, @subject.all)
|
110
110
|
end
|
111
111
|
|
112
|
-
def
|
112
|
+
def test_add_is_successful_if_only_region_is_different_and_updates_regions_to_existing_matching_definitions
|
113
113
|
target_holidays = {0 => [:mday => 1, :name => "Test", :regions => [:test2]]}
|
114
114
|
|
115
115
|
@subject.add(@existing_holidays_by_month)
|
@@ -152,4 +152,124 @@ class HolidaysByMonthRepoTests < Test::Unit::TestCase
|
|
152
152
|
@subject.find_by_month(-1)
|
153
153
|
end
|
154
154
|
end
|
155
|
+
|
156
|
+
def test_add_is_successful_if_only_function_is_different
|
157
|
+
initial_holidays = {0=> [{:mday => 1, :name=>"Test", :regions=>[:test], :function=>"easter(year)", :function_arguments=>[:year]}]}
|
158
|
+
|
159
|
+
@subject.add(initial_holidays)
|
160
|
+
|
161
|
+
second_holidays = {0=> [{:mday => 1, :name=>"Test", :regions=>[:test2], :function=>"orthodox_easter(year)", :function_arguments=>[:year]}]}
|
162
|
+
@subject.add(second_holidays)
|
163
|
+
|
164
|
+
expected = {
|
165
|
+
0 => [
|
166
|
+
{
|
167
|
+
:function=>"easter(year)",
|
168
|
+
:function_arguments=>[:year],
|
169
|
+
:mday=>1,
|
170
|
+
:name=>"Test",
|
171
|
+
:regions=>[:test]
|
172
|
+
},
|
173
|
+
{
|
174
|
+
:function=>"orthodox_easter(year)",
|
175
|
+
:function_arguments=>[:year],
|
176
|
+
:mday=>1,
|
177
|
+
:name=>"Test",
|
178
|
+
:regions=>[:test2]
|
179
|
+
}
|
180
|
+
]
|
181
|
+
}
|
182
|
+
|
183
|
+
assert_equal(expected, @subject.all)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_add_is_successful_if_only_function_modifier_is_different
|
187
|
+
initial_holidays = {0=> [{:mday => 1, :name=>"Test", :regions=>[:test], :function=>"easter(year)", :function_modifier=>1, :function_arguments=>[:year]}]}
|
188
|
+
|
189
|
+
@subject.add(initial_holidays)
|
190
|
+
|
191
|
+
second_holidays = {0=> [{:mday => 1, :name=>"Test", :regions=>[:test2], :function=>"easter(year)", :function_modifier=>2, :function_arguments=>[:year]}]}
|
192
|
+
@subject.add(second_holidays)
|
193
|
+
|
194
|
+
expected = {
|
195
|
+
0 => [
|
196
|
+
{
|
197
|
+
:function=>"easter(year)",
|
198
|
+
:function_arguments=>[:year],
|
199
|
+
:function_modifier=>1,
|
200
|
+
:mday=>1,
|
201
|
+
:name=>"Test",
|
202
|
+
:regions=>[:test]
|
203
|
+
},
|
204
|
+
{
|
205
|
+
:function=>"easter(year)",
|
206
|
+
:function_arguments=>[:year],
|
207
|
+
:function_modifier=>2,
|
208
|
+
:mday=>1,
|
209
|
+
:name=>"Test",
|
210
|
+
:regions=>[:test2]
|
211
|
+
}
|
212
|
+
]
|
213
|
+
}
|
214
|
+
|
215
|
+
assert_equal(expected, @subject.all)
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_add_is_successful_if_only_observed_is_different
|
219
|
+
initial_holidays = {0=> [{:mday => 1, :name=>"Test", :regions=>[:test], :observed=>"to_weekday_if_weekend(year)", :function_arguments=>[:year]}]}
|
220
|
+
|
221
|
+
@subject.add(initial_holidays)
|
222
|
+
|
223
|
+
second_holidays = {0=> [{:mday => 1, :name=>"Test", :regions=>[:test2], :observed =>"to_friday_if_saturday(year)", :function_arguments=>[:year]}]}
|
224
|
+
@subject.add(second_holidays)
|
225
|
+
|
226
|
+
expected = {
|
227
|
+
0 => [
|
228
|
+
{
|
229
|
+
:observed =>"to_weekday_if_weekend(year)",
|
230
|
+
:function_arguments=>[:year],
|
231
|
+
:mday=>1,
|
232
|
+
:name=>"Test",
|
233
|
+
:regions=>[:test]
|
234
|
+
},
|
235
|
+
{
|
236
|
+
:observed =>"to_friday_if_saturday(year)",
|
237
|
+
:function_arguments=>[:year],
|
238
|
+
:mday=>1,
|
239
|
+
:name=>"Test",
|
240
|
+
:regions=>[:test2]
|
241
|
+
}
|
242
|
+
]
|
243
|
+
}
|
244
|
+
|
245
|
+
assert_equal(expected, @subject.all)
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_add_is_successful_if_only_year_ranges_is_different
|
249
|
+
initial_holidays = {0=> [{:mday => 1, :name=>"Test", :regions=>[:test], :year_ranges => {:from => 1990}}]}
|
250
|
+
|
251
|
+
@subject.add(initial_holidays)
|
252
|
+
|
253
|
+
second_holidays = {0=> [{:mday => 1, :name=>"Test", :regions=>[:test2], :year_ranges => {:until => 2002}}]}
|
254
|
+
@subject.add(second_holidays)
|
255
|
+
|
256
|
+
expected = {
|
257
|
+
0 => [
|
258
|
+
{
|
259
|
+
:mday=>1,
|
260
|
+
:name=>"Test",
|
261
|
+
:regions=>[:test],
|
262
|
+
:year_ranges => {:from => 1990}
|
263
|
+
},
|
264
|
+
{
|
265
|
+
:mday=>1,
|
266
|
+
:name=>"Test",
|
267
|
+
:regions=>[:test2],
|
268
|
+
:year_ranges => {:until => 2002}
|
269
|
+
}
|
270
|
+
]
|
271
|
+
}
|
272
|
+
|
273
|
+
assert_equal(expected, @subject.all)
|
274
|
+
end
|
155
275
|
end
|