holidays 4.2.0 → 8.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitmodules +3 -0
- data/CHANGELOG.md +195 -0
- data/Makefile +45 -0
- data/README.md +253 -77
- data/Rakefile +10 -11
- data/bin/console +0 -0
- data/bin/setup +1 -0
- data/doc/CONTRIBUTING.md +72 -0
- data/doc/MAINTAINERS.md +81 -0
- data/{REFERENCES → doc/REFERENCES} +0 -0
- data/holidays.gemspec +9 -9
- data/lib/generated_definitions/MANIFEST +26 -4
- data/lib/generated_definitions/REGIONS.rb +3 -1
- data/lib/generated_definitions/ar.rb +4 -10
- data/lib/generated_definitions/at.rb +3 -9
- data/lib/generated_definitions/au.rb +32 -25
- data/lib/generated_definitions/be_fr.rb +2 -8
- data/lib/generated_definitions/be_nl.rb +2 -8
- data/lib/generated_definitions/bg.rb +2 -8
- data/lib/generated_definitions/br.rb +2 -8
- data/lib/generated_definitions/ca.rb +33 -32
- data/lib/generated_definitions/ch.rb +17 -11
- data/lib/generated_definitions/cl.rb +38 -12
- data/lib/generated_definitions/co.rb +121 -0
- data/lib/generated_definitions/cr.rb +2 -8
- data/lib/generated_definitions/cz.rb +2 -8
- data/lib/generated_definitions/de.rb +11 -14
- data/lib/generated_definitions/dk.rb +2 -8
- data/lib/generated_definitions/{ecb_target.rb → ecbtarget.rb} +10 -16
- data/lib/generated_definitions/ee.rb +36 -0
- data/lib/generated_definitions/el.rb +2 -8
- data/lib/generated_definitions/es.rb +8 -11
- data/lib/generated_definitions/europe.rb +121 -51
- data/lib/generated_definitions/federalreserve.rb +34 -0
- data/lib/generated_definitions/{federal_reserve.rb → federalreservebanks.rb} +14 -20
- data/lib/generated_definitions/fedex.rb +3 -9
- data/lib/generated_definitions/fi.rb +2 -8
- data/lib/generated_definitions/fr.rb +6 -10
- data/lib/generated_definitions/gb.rb +12 -16
- data/lib/generated_definitions/ge.rb +41 -0
- data/lib/generated_definitions/hk.rb +106 -0
- data/lib/generated_definitions/hr.rb +10 -14
- data/lib/generated_definitions/hu.rb +4 -9
- data/lib/generated_definitions/ie.rb +3 -17
- data/lib/generated_definitions/is.rb +3 -9
- data/lib/generated_definitions/it.rb +16 -13
- data/lib/generated_definitions/jp.rb +47 -36
- data/lib/generated_definitions/kr.rb +40 -0
- data/lib/generated_definitions/kz.rb +38 -0
- data/lib/generated_definitions/li.rb +2 -8
- data/lib/generated_definitions/lt.rb +2 -8
- data/lib/generated_definitions/lu.rb +35 -0
- data/lib/generated_definitions/lv.rb +52 -0
- data/lib/generated_definitions/ma.rb +2 -8
- data/lib/generated_definitions/mt_en.rb +38 -0
- data/lib/generated_definitions/mt_mt.rb +38 -0
- data/lib/generated_definitions/mx.rb +6 -12
- data/lib/generated_definitions/my.rb +30 -0
- data/lib/generated_definitions/nerc.rb +2 -8
- data/lib/generated_definitions/ng.rb +33 -0
- data/lib/generated_definitions/nl.rb +2 -8
- data/lib/generated_definitions/no.rb +2 -8
- data/lib/generated_definitions/northamerica.rb +223 -0
- data/lib/generated_definitions/nyse.rb +3 -9
- data/lib/generated_definitions/nz.rb +2 -9
- data/lib/generated_definitions/pe.rb +43 -0
- data/lib/generated_definitions/ph.rb +4 -10
- data/lib/generated_definitions/pl.rb +2 -8
- data/lib/generated_definitions/pt.rb +12 -12
- data/lib/generated_definitions/ro.rb +6 -9
- data/lib/generated_definitions/rs_cyrl.rb +39 -0
- data/lib/generated_definitions/rs_la.rb +39 -0
- data/lib/generated_definitions/ru.rb +37 -0
- data/lib/generated_definitions/scandinavia.rb +3 -9
- data/lib/generated_definitions/se.rb +2 -8
- data/lib/generated_definitions/sg.rb +2 -8
- data/lib/generated_definitions/si.rb +2 -8
- data/lib/generated_definitions/sk.rb +2 -8
- data/lib/generated_definitions/southamerica.rb +228 -0
- data/lib/generated_definitions/th.rb +36 -0
- data/lib/generated_definitions/tn.rb +32 -0
- data/lib/generated_definitions/tr.rb +64 -0
- data/lib/generated_definitions/ua.rb +37 -0
- data/lib/generated_definitions/{united_nations.rb → unitednations.rb} +61 -67
- data/lib/generated_definitions/ups.rb +3 -9
- data/lib/generated_definitions/us.rb +113 -23
- data/lib/generated_definitions/ve.rb +2 -8
- data/lib/generated_definitions/vi.rb +6 -11
- data/lib/generated_definitions/za.rb +2 -8
- data/lib/holidays/core_extensions/date.rb +21 -3
- data/lib/holidays/core_extensions/time.rb +23 -0
- data/lib/holidays/date_calculator/day_of_month.rb +3 -3
- data/lib/holidays/date_calculator/lunar_date.rb +371 -0
- data/lib/holidays/date_calculator/weekend_modifier.rb +0 -7
- data/lib/holidays/definition/context/function_processor.rb +91 -0
- data/lib/holidays/definition/context/generator.rb +37 -96
- data/lib/holidays/definition/context/load.rb +29 -0
- data/lib/holidays/definition/context/merger.rb +0 -4
- data/lib/holidays/definition/decorator/test.rb +37 -0
- data/lib/holidays/definition/entity/test.rb +11 -0
- data/lib/holidays/definition/generator/module.rb +54 -0
- data/lib/holidays/definition/generator/regions.rb +55 -0
- data/lib/holidays/definition/generator/test.rb +51 -0
- data/lib/holidays/definition/parser/custom_method.rb +3 -5
- data/lib/holidays/definition/parser/test.rb +86 -0
- data/lib/holidays/definition/repository/cache.rb +23 -9
- data/lib/holidays/definition/repository/holidays_by_month.rb +10 -2
- data/lib/holidays/definition/repository/proc_result_cache.rb +1 -1
- data/lib/holidays/definition/repository/regions.rb +23 -13
- data/lib/holidays/definition/validator/custom_method.rb +1 -1
- data/lib/holidays/definition/validator/region.rb +2 -11
- data/lib/holidays/definition/validator/test.rb +71 -0
- data/lib/holidays/errors.rb +5 -0
- data/lib/holidays/factory/date_calculator.rb +42 -0
- data/lib/holidays/factory/definition.rb +143 -0
- data/lib/holidays/factory/finder.rb +70 -0
- data/lib/holidays/finder/context/between.rb +45 -0
- data/lib/holidays/{use_case → finder}/context/dates_driver_builder.rb +11 -15
- data/lib/holidays/finder/context/next_holiday.rb +57 -0
- data/lib/holidays/finder/context/parse_options.rb +104 -0
- data/lib/holidays/finder/context/search.rb +110 -0
- data/lib/holidays/finder/context/year_holiday.rb +57 -0
- data/lib/holidays/finder/rules/in_region.rb +31 -0
- data/lib/holidays/finder/rules/year_range.rb +58 -0
- data/lib/holidays/load_all_definitions.rb +16 -17
- data/lib/holidays/version.rb +1 -1
- data/lib/holidays.rb +50 -125
- data/test/coverage_report.rb +26 -0
- data/test/data/test_custom_informal_holidays_defs.yaml +11 -0
- data/test/data/test_custom_year_range_holiday_defs.yaml +13 -10
- data/test/data/test_invalid_region.rb +15 -0
- data/test/data/test_multiple_custom_holiday_defs.yaml +7 -4
- 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/data/test_region.rb +15 -0
- data/test/data/test_single_custom_holiday_defs.yaml +7 -4
- data/test/data/test_single_custom_holiday_with_custom_procs.yaml +11 -7
- data/test/defs/test_defs_ar.rb +41 -19
- data/test/defs/test_defs_at.rb +18 -11
- data/test/defs/test_defs_au.rb +185 -126
- data/test/defs/test_defs_be_fr.rb +33 -14
- data/test/defs/test_defs_be_nl.rb +33 -14
- data/test/defs/test_defs_bg.rb +29 -17
- data/test/defs/test_defs_br.rb +33 -19
- data/test/defs/test_defs_ca.rb +246 -136
- data/test/defs/test_defs_ch.rb +35 -23
- data/test/defs/test_defs_cl.rb +57 -27
- data/test/defs/test_defs_co.rb +113 -0
- data/test/defs/test_defs_cr.rb +17 -11
- data/test/defs/test_defs_cz.rb +25 -15
- data/test/defs/test_defs_de.rb +60 -59
- data/test/defs/test_defs_dk.rb +31 -19
- data/test/defs/test_defs_ecbtarget.rb +27 -0
- data/test/defs/test_defs_ee.rb +41 -0
- data/test/defs/test_defs_el.rb +29 -17
- data/test/defs/test_defs_es.rb +116 -52
- data/test/defs/test_defs_europe.rb +1382 -701
- data/test/defs/test_defs_federalreserve.rb +113 -0
- data/test/defs/test_defs_federalreservebanks.rb +247 -0
- data/test/defs/test_defs_fedex.rb +19 -12
- data/test/defs/test_defs_fi.rb +47 -27
- data/test/defs/test_defs_fr.rb +31 -18
- data/test/defs/test_defs_gb.rb +120 -51
- data/test/defs/test_defs_ge.rb +53 -0
- data/test/defs/test_defs_hk.rb +59 -0
- data/test/defs/test_defs_hr.rb +32 -18
- data/test/defs/test_defs_hu.rb +34 -16
- data/test/defs/test_defs_ie.rb +41 -25
- data/test/defs/test_defs_is.rb +39 -22
- data/test/defs/test_defs_it.rb +43 -14
- data/test/defs/test_defs_jp.rb +141 -55
- data/test/defs/test_defs_kr.rb +37 -0
- data/test/defs/test_defs_kz.rb +39 -0
- data/test/defs/test_defs_li.rb +20 -20
- data/test/defs/test_defs_lt.rb +51 -30
- data/test/defs/test_defs_lu.rb +35 -0
- data/test/defs/test_defs_lv.rb +90 -0
- data/test/defs/test_defs_ma.rb +17 -11
- data/test/defs/test_defs_mt_en.rb +41 -0
- data/test/defs/test_defs_mt_mt.rb +41 -0
- data/test/defs/test_defs_mx.rb +34 -23
- data/test/defs/test_defs_my.rb +23 -0
- data/test/defs/test_defs_nerc.rb +17 -11
- data/test/defs/test_defs_ng.rb +29 -0
- data/test/defs/test_defs_nl.rb +21 -13
- data/test/defs/test_defs_no.rb +31 -18
- data/test/defs/test_defs_northamerica.rb +644 -0
- data/test/defs/test_defs_nyse.rb +27 -11
- data/test/defs/test_defs_nz.rb +47 -28
- data/test/defs/test_defs_pe.rb +47 -0
- data/test/defs/test_defs_ph.rb +17 -13
- data/test/defs/test_defs_pl.rb +200 -119
- data/test/defs/test_defs_pt.rb +35 -15
- data/test/defs/test_defs_ro.rb +53 -24
- data/test/defs/test_defs_rs_cyrl.rb +46 -0
- data/test/defs/test_defs_rs_la.rb +46 -0
- data/test/defs/test_defs_ru.rb +34 -0
- data/test/defs/test_defs_scandinavia.rb +193 -116
- data/test/defs/test_defs_se.rb +47 -28
- data/test/defs/test_defs_sg.rb +13 -9
- data/test/defs/test_defs_si.rb +93 -24
- data/test/defs/test_defs_sk.rb +29 -17
- data/test/defs/test_defs_southamerica.rb +307 -0
- data/test/defs/test_defs_th.rb +33 -0
- data/test/defs/test_defs_tn.rb +27 -0
- data/test/defs/test_defs_tr.rb +60 -0
- data/test/defs/test_defs_ua.rb +41 -0
- data/test/defs/{test_defs_united_nations.rb → test_defs_unitednations.rb} +3 -4
- data/test/defs/test_defs_ups.rb +19 -12
- data/test/defs/test_defs_us.rb +370 -30
- data/test/defs/test_defs_ve.rb +23 -16
- data/test/defs/test_defs_vi.rb +10 -6
- data/test/defs/test_defs_za.rb +23 -14
- data/test/holidays/core_extensions/test_date.rb +3 -2
- data/test/holidays/core_extensions/test_date_time.rb +60 -0
- data/test/holidays/date_calculator/test_lunar_date.rb +89 -0
- data/test/holidays/definition/context/test_function_processor.rb +199 -0
- data/test/holidays/definition/context/test_generator.rb +66 -35
- data/test/holidays/definition/context/test_load.rb +37 -0
- data/test/holidays/definition/decorator/test_test.rb +123 -0
- data/test/holidays/definition/generator/test_module.rb +268 -0
- data/test/holidays/definition/generator/test_regions.rb +97 -0
- data/test/holidays/definition/generator/test_test.rb +113 -0
- data/test/holidays/definition/parser/test_custom_method.rb +6 -6
- data/test/holidays/definition/parser/test_test.rb +142 -0
- data/test/holidays/definition/repository/test_cache.rb +47 -6
- data/test/holidays/definition/repository/test_holidays_by_month.rb +121 -1
- data/test/holidays/definition/repository/test_proc_result_cache.rb +8 -1
- data/test/holidays/definition/repository/test_regions.rb +31 -13
- data/test/holidays/definition/validator/test_custom_method.rb +5 -0
- data/test/holidays/definition/validator/test_region.rb +16 -12
- data/test/holidays/definition/validator/test_test.rb +60 -0
- data/test/holidays/finder/context/test_between.rb +172 -0
- data/test/holidays/{use_case → finder}/context/test_dates_driver_builder.rb +2 -2
- data/test/holidays/finder/context/test_next_holiday.rb +156 -0
- data/test/holidays/finder/context/test_parse_options.rb +141 -0
- data/test/holidays/finder/context/test_search.rb +232 -0
- data/test/holidays/finder/context/test_year_holiday.rb +202 -0
- data/test/holidays/finder/rules/test_in_region.rb +42 -0
- data/test/holidays/finder/rules/test_year_range.rb +166 -0
- data/test/integration/README.md +9 -0
- data/test/{test_all_regions.rb → integration/test_all_regions.rb} +18 -4
- data/test/integration/test_any_holidays_during_work_week.rb +90 -0
- data/test/integration/test_available_regions.rb +23 -0
- data/test/{test_custom_holidays.rb → integration/test_custom_holidays.rb} +6 -6
- data/test/integration/test_custom_informal_holidays.rb +15 -0
- data/test/{test_custom_year_range_holidays.rb → integration/test_custom_year_range_holidays.rb} +1 -9
- data/test/{test_holidays.rb → integration/test_holidays.rb} +100 -69
- data/test/{test_holidays_between.rb → integration/test_holidays_between.rb} +19 -17
- data/test/integration/test_multiple_regions.rb +71 -0
- data/test/integration/test_multiple_regions_with_conflict.rb +29 -0
- data/test/integration/test_nonstandard_regions.rb +25 -0
- data/test/test_helper.rb +7 -3
- metadata +204 -132
- data/CONTRIBUTING.md +0 -41
- data/benchmark.rb +0 -8
- data/definitions/README.md +0 -353
- data/definitions/ar.yaml +0 -93
- data/definitions/at.yaml +0 -72
- data/definitions/au.yaml +0 -375
- data/definitions/be_fr.yaml +0 -69
- data/definitions/be_nl.yaml +0 -69
- data/definitions/bg.yaml +0 -127
- data/definitions/br.yaml +0 -77
- data/definitions/ca.yaml +0 -302
- data/definitions/ch.yaml +0 -193
- data/definitions/cl.yaml +0 -94
- data/definitions/cr.yaml +0 -65
- data/definitions/cz.yaml +0 -73
- data/definitions/de.yaml +0 -209
- data/definitions/dk.yaml +0 -130
- data/definitions/ecb_target.yaml +0 -44
- data/definitions/el.yaml +0 -84
- data/definitions/es.yaml +0 -203
- data/definitions/federal_reserve.yaml +0 -114
- data/definitions/fedex.yaml +0 -62
- data/definitions/fi.yaml +0 -115
- data/definitions/fr.yaml +0 -79
- data/definitions/gb.yaml +0 -151
- data/definitions/hr.yaml +0 -79
- data/definitions/hu.yaml +0 -63
- data/definitions/ie.yaml +0 -89
- data/definitions/index.yaml +0 -57
- data/definitions/is.yaml +0 -146
- data/definitions/it.yaml +0 -67
- data/definitions/jp.yaml +0 -316
- data/definitions/li.yaml +0 -107
- data/definitions/lt.yaml +0 -89
- data/definitions/ma.yaml +0 -52
- data/definitions/mx.yaml +0 -106
- data/definitions/nerc.yaml +0 -51
- data/definitions/nl.yaml +0 -73
- data/definitions/no.yaml +0 -90
- data/definitions/north_america_informal.yaml +0 -61
- data/definitions/nyse.yaml +0 -64
- data/definitions/nz.yaml +0 -163
- data/definitions/ph.yaml +0 -94
- data/definitions/pl.yaml +0 -320
- data/definitions/pt.yaml +0 -69
- data/definitions/ro.yaml +0 -78
- data/definitions/se.yaml +0 -120
- data/definitions/sg.yaml +0 -56
- data/definitions/si.yaml +0 -86
- data/definitions/sk.yaml +0 -80
- data/definitions/united_nations.yaml +0 -189
- data/definitions/ups.yaml +0 -62
- data/definitions/us.yaml +0 -103
- data/definitions/ve.yaml +0 -74
- data/definitions/vi.yaml +0 -29
- data/definitions/za.yaml +0 -80
- data/lib/generated_definitions/north_america.rb +0 -126
- data/lib/holidays/date_calculator_factory.rb +0 -35
- data/lib/holidays/definition_factory.rb +0 -86
- data/lib/holidays/option/context/parse_options.rb +0 -106
- data/lib/holidays/option_factory.rb +0 -15
- data/lib/holidays/use_case/context/between.rb +0 -45
- data/lib/holidays/use_case/context/context_common.rb +0 -123
- data/lib/holidays/use_case/context/next_holiday.rb +0 -54
- data/lib/holidays/use_case_factory.rb +0 -31
- data/test/defs/test_defs_ecb_target.rb +0 -23
- data/test/defs/test_defs_federal_reserve.rb +0 -69
- data/test/defs/test_defs_north_america.rb +0 -195
- data/test/holidays/option/context/test_parse_options.rb +0 -74
- data/test/holidays/test_date_calculator_factory.rb +0 -27
- data/test/holidays/test_definition_factory.rb +0 -49
- data/test/holidays/test_option_factory.rb +0 -9
- data/test/holidays/test_use_case_factory.rb +0 -13
- data/test/holidays/use_case/context/test_between.rb +0 -77
- data/test/test_multiple_regions.rb +0 -24
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
2
2
|
|
3
3
|
require "#{Holidays::DEFINITIONS_PATH}/ca"
|
4
4
|
|
@@ -8,16 +8,16 @@ require "#{Holidays::DEFINITIONS_PATH}/ca"
|
|
8
8
|
# NOTE: this test is a mixture of integration and unit tests. It's messy and bad.
|
9
9
|
# I am not fixing it here because I am trying to clean up the 'between' use case
|
10
10
|
# and don't want to bite off more than I can chew.
|
11
|
-
require "#{Holidays::DEFINITIONS_PATH}/
|
11
|
+
require "#{Holidays::DEFINITIONS_PATH}/northamerica"
|
12
12
|
|
13
|
-
class
|
13
|
+
class HolidaysBetweenTests < Test::Unit::TestCase
|
14
14
|
def setup
|
15
15
|
@date = Date.civil(2008,1,1)
|
16
16
|
@subject = Holidays.method(:between)
|
17
17
|
end
|
18
18
|
|
19
19
|
def teardown
|
20
|
-
Holidays::
|
20
|
+
Holidays::Factory::Definition.cache_repository.reset!
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_between
|
@@ -41,12 +41,22 @@ class HolidaysTests < Test::Unit::TestCase
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
def test_between_raises_error_if_end_date_is_before_start_date
|
45
|
+
assert_raise ArgumentError do
|
46
|
+
@subject.call(Date.civil(2019, 2, 1), Date.civil(2019, 1, 1), :us)
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_raise ArgumentError do
|
50
|
+
@subject.call(Date.civil(2008,7,2), Date.civil(2000,7,2), :ca)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
44
54
|
def test_cached_holidays_are_returned_if_present
|
45
55
|
start_date = Date.civil(2015, 1, 1)
|
46
56
|
end_date = Date.civil(2015, 1, 31)
|
47
57
|
options = [:us, :informal]
|
48
58
|
|
49
|
-
Holidays::
|
59
|
+
Holidays::Factory::Definition.cache_repository.expects(:find).with(start_date, end_date, options).returns({cached: 'data'})
|
50
60
|
|
51
61
|
assert_equal({cached: 'data'}, @subject.call(start_date, end_date, *options))
|
52
62
|
end
|
@@ -56,13 +66,9 @@ class HolidaysTests < Test::Unit::TestCase
|
|
56
66
|
end_date = Date.civil(2015, 1, 31)
|
57
67
|
options = [:us]
|
58
68
|
|
59
|
-
options_parser_mock = mock()
|
60
|
-
Holidays::OptionFactory.stubs(:parse_options).returns(options_parser_mock)
|
61
|
-
options_parser_mock.expects(:call).with(options).returns([[:us], false, false])
|
62
|
-
|
63
69
|
between_mock = mock()
|
64
|
-
Holidays::
|
65
|
-
between_mock.expects(:call).with(start_date, end_date,
|
70
|
+
Holidays::Factory::Finder.stubs(:between).returns(between_mock)
|
71
|
+
between_mock.expects(:call).with(start_date, end_date, [:us])
|
66
72
|
|
67
73
|
@subject.call(start_date, end_date, *options)
|
68
74
|
end
|
@@ -72,13 +78,9 @@ class HolidaysTests < Test::Unit::TestCase
|
|
72
78
|
end_date = Date.civil(2015, 1, 31)
|
73
79
|
options = [:us]
|
74
80
|
|
75
|
-
dates_driver_builder_mock = mock()
|
76
|
-
Holidays::UseCaseFactory.stubs(:dates_driver_builder).returns(dates_driver_builder_mock)
|
77
|
-
dates_driver_builder_mock.expects(:call).with(start_date, end_date).returns({2015 => [0, 1, 2]})
|
78
|
-
|
79
81
|
between_mock = mock()
|
80
|
-
Holidays::
|
81
|
-
between_mock.expects(:call).with(start_date, end_date,
|
82
|
+
Holidays::Factory::Finder.stubs(:between).returns(between_mock)
|
83
|
+
between_mock.expects(:call).with(start_date, end_date, [:us])
|
82
84
|
|
83
85
|
@subject.call(start_date, end_date, *options)
|
84
86
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
2
|
+
require "#{Holidays::DEFINITIONS_PATH}/gb"
|
3
|
+
require "#{Holidays::DEFINITIONS_PATH}/ie"
|
4
|
+
|
5
|
+
class MultipleRegionsTests < Test::Unit::TestCase
|
6
|
+
# Simulate load of new environment where the repositories begin empty
|
7
|
+
def reset_cache
|
8
|
+
Holidays::Factory::Definition.instance_variable_set(:@regions_repo, nil)
|
9
|
+
Holidays::Factory::Definition.instance_variable_set(:@holidays_repo, nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_defining_holidays
|
13
|
+
h = Holidays.on(Date.new(2008, 12, 26), :ie)
|
14
|
+
assert_equal 'St. Stephen\'s Day', h[0][:name]
|
15
|
+
|
16
|
+
h = Holidays.on(Date.new(2008, 5, 9), :gb_)
|
17
|
+
assert_equal 'Liberation Day', (h[0] || {})[:name]
|
18
|
+
|
19
|
+
h = Holidays.on(Date.new(2008, 5, 9), :je)
|
20
|
+
assert_equal 'Liberation Day', h[0][:name]
|
21
|
+
|
22
|
+
h = Holidays.on(Date.new(2008, 5, 9), :gb)
|
23
|
+
assert h.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_north_american_parent_region_lookup
|
27
|
+
assert_equal :ca, Holidays::PARENT_REGION_LOOKUP[:ca]
|
28
|
+
assert_equal :ca, Holidays::PARENT_REGION_LOOKUP[:ca_qc]
|
29
|
+
assert_equal :mx, Holidays::PARENT_REGION_LOOKUP[:mx]
|
30
|
+
assert_equal :mx, Holidays::PARENT_REGION_LOOKUP[:mx_pue]
|
31
|
+
assert_equal :us, Holidays::PARENT_REGION_LOOKUP[:us]
|
32
|
+
assert_equal :us, Holidays::PARENT_REGION_LOOKUP[:us_fl]
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_north_american_subregion_caching
|
36
|
+
{ ca: :ca_qc, mx: :mx_pue, us: :us_fl }.each do |region, subregion|
|
37
|
+
module_name = region.upcase
|
38
|
+
|
39
|
+
reset_cache
|
40
|
+
Holidays.on(Date.new(2018, 1, 1), region) # Test check on regional holidays
|
41
|
+
assert_equal [region], Holidays::Factory::Definition.regions_repository.all_loaded, "Only Holidays::#{module_name} should be loaded"
|
42
|
+
holiday_regions = Holidays::Factory::Definition.holidays_by_month_repository.all.values.flatten.map { |h| h[:regions] }.uniq.flatten
|
43
|
+
assert_includes holiday_regions, region, 'Region holidays should be loaded'
|
44
|
+
assert_includes holiday_regions, subregion, 'Subregion holidays should be loaded'
|
45
|
+
|
46
|
+
reset_cache
|
47
|
+
Holidays.on(Date.new(2018, 1, 1), subregion) # Test check on subregional holidays
|
48
|
+
assert_equal [region], Holidays::Factory::Definition.regions_repository.all_loaded, "Only Holidays::#{module_name} should be loaded"
|
49
|
+
holiday_regions = Holidays::Factory::Definition.holidays_by_month_repository.all.values.flatten.map { |h| h[:regions] }.uniq.flatten
|
50
|
+
assert_includes holiday_regions, region, 'Region holidays should be loaded'
|
51
|
+
assert_includes holiday_regions, subregion, 'Subregion holidays should be loaded'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_north_american_cross_region_caching
|
56
|
+
reset_cache
|
57
|
+
Holidays.on(Date.new(2018, 1, 1), :us)
|
58
|
+
assert_equal [:us], Holidays::Factory::Definition.regions_repository.all_loaded, 'Only Holidays::US should be loaded'
|
59
|
+
holiday_regions = Holidays::Factory::Definition.holidays_by_month_repository.all.values.flatten.map { |h| h[:regions] }.uniq.flatten
|
60
|
+
assert_includes holiday_regions, :us, 'Region holidays should be loaded'
|
61
|
+
assert_includes holiday_regions, :us_fl, 'Subregion holidays should be loaded'
|
62
|
+
|
63
|
+
Holidays.on(Date.new(2018, 1, 1), :ca)
|
64
|
+
assert_equal [:us, :ca], Holidays::Factory::Definition.regions_repository.all_loaded, 'Only Holidays::US and Holidays::CA should be loaded'
|
65
|
+
holiday_regions = Holidays::Factory::Definition.holidays_by_month_repository.all.values.flatten.map { |h| h[:regions] }.uniq.flatten
|
66
|
+
assert_includes holiday_regions, :us, 'Region holidays should be loaded'
|
67
|
+
assert_includes holiday_regions, :ca, 'Region holidays should be loaded'
|
68
|
+
assert_includes holiday_regions, :us_fl, 'Subregion holidays should be loaded'
|
69
|
+
assert_includes holiday_regions, :ca_qc, 'Subregion holidays should be loaded'
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
2
|
+
|
3
|
+
# See https://github.com/holidays/holidays/issues/344 for more info on why
|
4
|
+
# these tests exist.
|
5
|
+
class MultipleRegionsWithConflictsTests < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_corpus_christi_returns_correctly_for_co_even_if_br_is_loaded_first
|
8
|
+
result = Holidays.on(Date.new(2014, 6, 19), :br)
|
9
|
+
assert_equal 1, result.count
|
10
|
+
assert_equal 'Corpus Christi', result.first[:name]
|
11
|
+
|
12
|
+
result = Holidays.on(Date.new(2014, 6, 23), :co)
|
13
|
+
assert_equal 1, result.count
|
14
|
+
assert_equal 'Corpus Christi', result.first[:name]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_custom_loaded_region_returns_correct_value_with_function_modifier_conflict_even_if_conflict_definition_is_loaded_first
|
18
|
+
Holidays.load_custom('test/data/test_multiple_regions_with_conflicts_region_1.yaml')
|
19
|
+
result = Holidays.on(Date.new(2019, 6, 20), :multiple_with_conflict_1)
|
20
|
+
assert_equal 1, result.count
|
21
|
+
assert_equal 'With Function Modifier', result.first[:name]
|
22
|
+
|
23
|
+
Holidays.load_custom('test/data/test_multiple_regions_with_conflicts_region_2.yaml')
|
24
|
+
result = Holidays.on(Date.new(2019, 6, 24), :multiple_with_conflict_2)
|
25
|
+
assert_equal 1, result.count
|
26
|
+
assert_equal 'With Function Modifier', result.first[:name]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
3
|
+
|
4
|
+
class NonstandardRegionsHolidaysTests < Test::Unit::TestCase
|
5
|
+
def test_ecbtarget_christmas_day
|
6
|
+
h = Holidays.on(Date.new(2018,12,25), :ecbtarget)
|
7
|
+
assert_equal 'Christmas Day', h[0][:name]
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_federalreserve_memorial_day
|
11
|
+
h = Holidays.on(Date.new(2018,5,28), :federalreserve)
|
12
|
+
assert_equal 'Memorial Day', h[0][:name]
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_federalreservebanks_independence_day
|
17
|
+
h = Holidays.on(Date.new(2019,7,4), :federalreservebanks, :observed)
|
18
|
+
assert_equal 'Independence Day', h[0][:name]
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_unitednations_international_day_of_families
|
22
|
+
h = Holidays.on(Date.new(2021,5,15), :unitednations)
|
23
|
+
assert_equal 'International Day of Families', h[0][:name]
|
24
|
+
end
|
25
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
Coveralls.wear!
|
1
|
+
require File.dirname(__FILE__) + '/coverage_report'
|
3
2
|
|
4
3
|
$:.unshift(File.expand_path(File.dirname(__FILE__) + '../../lib/'))
|
5
4
|
|
@@ -11,12 +10,17 @@ require 'mocha/test_unit'
|
|
11
10
|
require 'date'
|
12
11
|
require 'holidays'
|
13
12
|
require 'holidays/core_extensions/date'
|
13
|
+
require 'holidays/core_extensions/time'
|
14
14
|
|
15
15
|
# Loads core extension for use in various definition tests as necessary
|
16
16
|
class Date
|
17
17
|
include Holidays::CoreExtensions::Date
|
18
18
|
end
|
19
19
|
|
20
|
+
class Time
|
21
|
+
include Holidays::CoreExtensions::Time
|
22
|
+
end
|
23
|
+
|
20
24
|
module Holidays
|
21
25
|
# Test region used for generating a holiday on Date.today
|
22
26
|
module Test # :nodoc:
|
@@ -30,4 +34,4 @@ module Holidays
|
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
33
|
-
Holidays::
|
37
|
+
Holidays::Factory::Definition.merger.call(Holidays::Test::DEFINED_REGIONS, Holidays::Test::HOLIDAYS_BY_MONTH, Holidays::Test::CUSTOM_METHODS)
|