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
@@ -0,0 +1,166 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
2
|
+
|
3
|
+
require 'holidays/finder/rules/year_range'
|
4
|
+
|
5
|
+
class FinderRulesYearRangeTests < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@year = 2015
|
8
|
+
@year_ranges = {between: 1996..2002}
|
9
|
+
@subject = Holidays::Finder::Rules::YearRange
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_returns_error_if_target_year_is_missing
|
13
|
+
assert_raises ArgumentError do
|
14
|
+
@subject.call(nil, @year_ranges)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_returns_error_if_target_year_is_not_a_number
|
19
|
+
assert_raises ArgumentError do
|
20
|
+
@subject.call("test", @year_ranges)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_returns_error_if_year_ranges_if_nil
|
25
|
+
@year_ranges = []
|
26
|
+
assert_raises ArgumentError do
|
27
|
+
@subject.call(@year, nil)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_returns_error_if_year_ranges_contains_only_non_hash
|
32
|
+
@year_ranges = :test
|
33
|
+
assert_raises ArgumentError do
|
34
|
+
@subject.call(@year, @year_ranges)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_returns_error_if_year_ranges_is_empty
|
39
|
+
@year_ranges = [{}, {}]
|
40
|
+
assert_raises ArgumentError do
|
41
|
+
@subject.call(@year, @year_ranges)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_returns_error_if_year_range_contains_a_hash_with_multiple_entries
|
46
|
+
@year_ranges = {:between => 1996..2002, :after => 2002}
|
47
|
+
assert_raises ArgumentError do
|
48
|
+
@subject.call(@year, @year_ranges)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_returns_error_if_year_range_contains_unrecognized_operator
|
53
|
+
@year_ranges = {:what => 2002}
|
54
|
+
assert_raises ArgumentError do
|
55
|
+
@subject.call(@year, @year_ranges)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_returns_error_if_until_operator_and_value_is_not_a_number
|
60
|
+
@year_ranges = {until: "bad"}
|
61
|
+
assert_raises ArgumentError do
|
62
|
+
@subject.call(@year, @year_ranges)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_returns_true_if_until_operator_and_target_is_until
|
67
|
+
@year_ranges = {until: 2000}
|
68
|
+
assert_equal(true, @subject.call(1999, @year_ranges))
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_returns_true_if_until_operator_and_target_is_equal
|
72
|
+
@year_ranges = {until: 2000}
|
73
|
+
assert_equal(true, @subject.call(2000, @year_ranges))
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_returns_false_if_until_operator_and_target_is_after
|
77
|
+
@year_ranges = {until: 2000}
|
78
|
+
assert_equal(false, @subject.call(2001, @year_ranges))
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_returns_error_if_from_operator_with_bad_value
|
82
|
+
@year_ranges = {from: "bad"}
|
83
|
+
assert_raises ArgumentError do
|
84
|
+
@subject.call(@year, @year_ranges)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_returns_false_if_from_operator_and_target_is_before
|
89
|
+
@year_ranges = {from: 2000}
|
90
|
+
assert_equal(false, @subject.call(1999, @year_ranges))
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_returns_true_if_from_operator_and_target_is_equal
|
94
|
+
@year_ranges = {from: 2000}
|
95
|
+
assert_equal(true, @subject.call(2000, @year_ranges))
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_returns_true_if_from_operator_and_target_is_after
|
99
|
+
@year_ranges = {from: 2000}
|
100
|
+
assert_equal(true, @subject.call(2001, @year_ranges))
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_returns_error_if_limited_operator_and_bad_value
|
104
|
+
@year_ranges = {limited: "bad"}
|
105
|
+
assert_raises ArgumentError do
|
106
|
+
@subject.call(@year, @year_ranges)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_returns_error_if_limited_operator_with_empty_array
|
111
|
+
@year_ranges = {limited: []}
|
112
|
+
assert_raises ArgumentError do
|
113
|
+
@subject.call(@year, @year_ranges)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_returns_error_if_limited_operator_with_array_containing_non_integer_value
|
118
|
+
@year_ranges = {limited: ["bad"]}
|
119
|
+
assert_raises ArgumentError do
|
120
|
+
@subject.call(@year, @year_ranges)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_returns_true_if_limited_operator_and_value_is_number_that_matches_target
|
125
|
+
@year_ranges = {limited: [2002]}
|
126
|
+
assert_equal(true, @subject.call(2002, @year_ranges))
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_returns_false_if_limited_operator_and_target_is_not_included
|
130
|
+
@year_ranges = {limited: [1998,2000]}
|
131
|
+
assert_equal(false, @subject.call(1997, @year_ranges))
|
132
|
+
assert_equal(false, @subject.call(1999, @year_ranges))
|
133
|
+
assert_equal(false, @subject.call(2002, @year_ranges))
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_returns_true_if_limited_operator_and_target_is_included
|
137
|
+
@year_ranges = {limited: [1998, 2000, 2002]}
|
138
|
+
assert_equal(true, @subject.call(1998, @year_ranges))
|
139
|
+
assert_equal(true, @subject.call(2000, @year_ranges))
|
140
|
+
assert_equal(true, @subject.call(2002, @year_ranges))
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_returns_error_if_between_operator_and_value_not_a_range
|
144
|
+
@year_ranges = {between: 2000}
|
145
|
+
assert_raises ArgumentError do
|
146
|
+
@subject.call(2003, @year_ranges)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_returns_false_if_between_operator_and_target_is_before
|
151
|
+
@year_ranges = {between: 1998..2002}
|
152
|
+
assert_equal(false, @subject.call(1997, @year_ranges))
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_returns_true_if_between_operator_and_target_is_covered
|
156
|
+
@year_ranges = {between: 1998..2002}
|
157
|
+
assert_equal(true, @subject.call(1998, @year_ranges))
|
158
|
+
assert_equal(true, @subject.call(2000, @year_ranges))
|
159
|
+
assert_equal(true, @subject.call(2002, @year_ranges))
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_returns_false_if_between_operator_and_target_is_after
|
163
|
+
@year_ranges = {between: 1998..2002}
|
164
|
+
assert_equal(false, @subject.call(2003, @year_ranges))
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Integration tests
|
2
|
+
|
3
|
+
These tests are dependent on the files in /definitions (and, by proxy, /lib/generated_definitions).
|
4
|
+
It is possible that these tests will break because of 'unrelated' definition changes. The code
|
5
|
+
behind these changes could still be good but since the definitions changed we could see failures.
|
6
|
+
|
7
|
+
These are not unit tests. This is not testing whether specific internal code is working. These are
|
8
|
+
tests from the consumer perspective. You must recognize that this could fail because of code
|
9
|
+
changes unrelated to definition changes.
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class AllRegionsTests < Test::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
Holidays::LoadAllDefinitions.call
|
6
6
|
end
|
@@ -19,16 +19,30 @@ class MultipleRegionsTests < Test::Unit::TestCase
|
|
19
19
|
def test_load_subregion
|
20
20
|
holidays = Holidays.on(Date.civil(2014, 1, 1), :de_bb)
|
21
21
|
assert holidays.any? { |h| h[:name] == 'Neujahrstag' }
|
22
|
+
|
23
|
+
holidays = Holidays.on(Date.civil(2020, 1, 1), :de_bb)
|
24
|
+
assert holidays.any? { |h| h[:name] == 'Neujahrstag' }
|
25
|
+
|
26
|
+
holidays = Holidays.on(Date.civil(2027, 1, 1), :de_bb)
|
27
|
+
assert holidays.any? { |h| h[:name] == 'Neujahrstag' }
|
22
28
|
end
|
23
29
|
|
24
30
|
def test_unknown_region_raises_exception
|
25
|
-
assert_raise Holidays::
|
31
|
+
assert_raise Holidays::InvalidRegion do
|
26
32
|
Holidays.on(Date.civil(2014, 1, 1), :something_we_do_not_recognize)
|
27
33
|
end
|
34
|
+
|
35
|
+
assert_raise Holidays::InvalidRegion do
|
36
|
+
Holidays.on(Date.civil(2020, 1, 1), :something_we_do_not_recognize)
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_raise Holidays::InvalidRegion do
|
40
|
+
Holidays.on(Date.civil(2030, 1, 1), :something_we_do_not_recognize)
|
41
|
+
end
|
28
42
|
end
|
29
43
|
|
30
44
|
def test_malicious_load_attempt_raises_exception
|
31
|
-
assert_raise Holidays::
|
45
|
+
assert_raise Holidays::InvalidRegion do
|
32
46
|
Holidays.between(Date.civil(2014, 1, 1), Date.civil(2016, 1, 1), '../../../../../../../../../../../../tmp/profile_pic.jpg')
|
33
47
|
end
|
34
48
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
2
|
+
|
3
|
+
class AnyHolidaysDuringWorkWeekTests < Test::Unit::TestCase
|
4
|
+
def subject
|
5
|
+
Holidays.method(:any_holidays_during_work_week?)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_returns_true_when_single_holiday_exists_during_week
|
9
|
+
assert subject.call(Date.new(2018, 1, 1), :us)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_returns_true_when_multiple_holidays_exist_during_week
|
13
|
+
assert subject.call(Date.new(2018, 12, 26), :gb)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_returns_true_if_informal_flag_set_and_informal_holiday_exists_during_week
|
17
|
+
assert subject.call(Date.new(2018, 10, 31), :us, :informal)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_returns_true_when_no_region_specified_and_single_holiday_exists_during_week
|
21
|
+
assert subject.call(Date.new(2018, 1, 1))
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_returns_true_if_both_informal_and_observed_flags_set_and_informal_holiday_observed_during_week
|
25
|
+
assert subject.call(Date.new(2008, 11, 30), :gb_sct, :informal, :observed)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_returns_true_when_observed_flag_set_and_holiday_is_observed_during_week
|
29
|
+
assert subject.call(Date.new(2012,9,5), :us, :observed)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_returns_true_when_observed_flag_set_and_holiday_is_observed_on_monday
|
33
|
+
assert subject.call(Date.new(2018,11,12), :us, :observed)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_returns_true_with_multiple_regions_and_holiday_occurs_during_week
|
37
|
+
assert subject.call(Date.new(2018,1,1), [:us, :gb])
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_returns_true_when_observed_flag_set_and_holiday_on_saturday_but_observed_on_friday
|
41
|
+
assert subject.call(Date.new(2018,7,3), [:us], :observed)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_returns_false_when_no_holiday_exists_during_week
|
45
|
+
assert_equal false, subject.call(Date.new(2018,7,30), :us)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_returns_false_when_holiday_on_sunday
|
49
|
+
assert_equal false, subject.call(Date.new(2018,11,11), :us)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_returns_false_when_holiday_on_saturday
|
53
|
+
assert_equal false, subject.call(Date.new(2017,11,11), :us)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_returns_false_when_observed_flag_not_set_and_holiday_occurs_on_sunday_but_observed_on_monday
|
57
|
+
assert_equal false, subject.call(Date.new(2017,1,1), :us)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_returns_false_if_informal_and_observed_flags_both_set_and_no_holiday_exists_during_week
|
61
|
+
assert_equal false, subject.call(Date.new(2018,7,30), :us, :informal, :observed)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_returns_false_when_informal_flag_set_and_informal_holiday_occurs_on_weekend
|
65
|
+
assert_equal false, subject.call(Date.new(2018,4,14), :us, :informal)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_returns_false_when_informal_flag_set_but_observed_is_not_and_informal_holiday_is_observed_on_monday
|
69
|
+
assert_equal false, subject.call(Date.new(2008, 11, 30), :gb_sct, :informal)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_verify_count_of_weeks_without_any_holidays_for_2012
|
73
|
+
weeks_in_2012 = Date.commercial(2013, -1).cweek
|
74
|
+
holidays_in_2012 = weeks_in_2012.times.count { |week| subject.call(Date.commercial(2012,week+1), :us) == false }
|
75
|
+
assert_equal 45, holidays_in_2012
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_returns_true_for_new_years_in_any_region
|
79
|
+
assert subject.call(Date.civil(2016, 1, 1))
|
80
|
+
end
|
81
|
+
|
82
|
+
# These are in response to https://github.com/holidays/holidays/issues/264, just to be completely sure it's fixed.
|
83
|
+
def returns_true_for_various_holidays_in_poland
|
84
|
+
assert subject.call(Date.civil(2018, 1, 1), :pl)
|
85
|
+
assert subject.call(Date.civil(2018, 1, 2), :pl)
|
86
|
+
assert subject.call(Date.civil(2018, 5, 2), :pl)
|
87
|
+
assert subject.call(Date.civil(2018, 5, 3), :pl)
|
88
|
+
assert subject.call(Date.today, Date.today + 365*2, :pl, :observed)
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
2
|
+
|
3
|
+
class AvailableRegionsTests < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@date = Date.civil(2008,1,1)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_available_regions_returns_array
|
9
|
+
assert Holidays.available_regions.is_a?(Array)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_available_regions_returns_array_of_symbols
|
13
|
+
Holidays.available_regions.each do |r|
|
14
|
+
assert r.is_a?(Symbol)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# This test might fail if we add new regions. Since this is an integration test
|
19
|
+
# I am fine with that!
|
20
|
+
def test_available_regions_returns_correct_number_of_regions
|
21
|
+
assert_equal 258, Holidays.available_regions.count
|
22
|
+
end
|
23
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
2
2
|
|
3
3
|
class CustomHolidaysTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_custom_region_present_after_single_file_parsing
|
6
|
-
assert_raises Holidays::
|
6
|
+
assert_raises Holidays::InvalidRegion do
|
7
7
|
Holidays.on(Date.civil(2013,6,20), :custom_single_file)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
Holidays.load_custom('test/data/test_single_custom_holiday_defs.yaml')
|
11
11
|
|
12
12
|
assert_not_equal [], Holidays.on(Date.civil(2013,6,20), :custom_single_file)
|
13
13
|
end
|
@@ -19,15 +19,15 @@ class CustomHolidaysTest < Test::Unit::TestCase
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_custom_holidays_present_after_multiple_file_parsing
|
22
|
-
assert_raises Holidays::
|
22
|
+
assert_raises Holidays::InvalidRegion do
|
23
23
|
Holidays.on(Date.civil(2013, 10,5), :custom_multiple_files)
|
24
24
|
end
|
25
25
|
|
26
|
-
assert_raises Holidays::
|
26
|
+
assert_raises Holidays::InvalidRegion do
|
27
27
|
Holidays.on(Date.civil(2013,3,1), :custom_multiple_files)
|
28
28
|
end
|
29
29
|
|
30
|
-
assert_raises Holidays::
|
30
|
+
assert_raises Holidays::InvalidRegion do
|
31
31
|
Holidays.on(Date.civil(2013,3,1), :custom_multiple_files_govt)
|
32
32
|
end
|
33
33
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
2
|
+
|
3
|
+
class CustomHolidaysTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_custom_region_informal_day_parsing
|
6
|
+
Holidays.load_custom('test/data/test_custom_informal_holidays_defs.yaml')
|
7
|
+
|
8
|
+
assert_not_equal [], Holidays.on(Date.new(2018,1,1), :custom_informal, :informal)
|
9
|
+
assert_equal [], Holidays.on(Date.new(2018,1,1), :custom_informal, :observed)
|
10
|
+
|
11
|
+
assert_not_equal [], Holidays.on(Date.new(2018,1,5), :custom_informal, :informal)
|
12
|
+
assert_equal [], Holidays.on(Date.new(2018,1,5), :custom_informal, :observed)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/test/{test_custom_year_range_holidays.rb → integration/test_custom_year_range_holidays.rb}
RENAMED
@@ -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
|
class CustomYearRangeHolidaysTest < Test::Unit::TestCase
|
4
4
|
|
@@ -32,12 +32,4 @@ class CustomYearRangeHolidaysTest < Test::Unit::TestCase
|
|
32
32
|
assert_not_equal [], Holidays.on(Date.civil(2019,6,4), :custom_year_range_file)
|
33
33
|
assert_equal [], Holidays.on(Date.civil(2020,6,4), :custom_year_range_file)
|
34
34
|
end
|
35
|
-
|
36
|
-
def test_multiple_condition
|
37
|
-
Holidays.load_custom('test/data/test_custom_year_range_holiday_defs.yaml')
|
38
|
-
assert_not_equal [], Holidays.on(Date.civil(2015,6,5), :custom_year_range_file)
|
39
|
-
assert_equal [], Holidays.on(Date.civil(2016,6,5), :custom_year_range_file)
|
40
|
-
assert_not_equal [], Holidays.on(Date.civil(2017,6,5), :custom_year_range_file)
|
41
|
-
end
|
42
|
-
|
43
35
|
end
|
@@ -1,14 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.expand_path(File.dirname(__FILE__)) + '
|
2
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
3
3
|
|
4
|
-
require "#{Holidays::DEFINITIONS_PATH}/ca"
|
5
|
-
|
6
|
-
# Re-include CA defs via holidays/north_america to ensure that individual
|
7
|
-
# defs aren't duplicated.
|
8
|
-
require "#{Holidays::DEFINITIONS_PATH}/north_america"
|
9
|
-
|
10
|
-
# These are effectively integration tests. We plan on making this explicit somehow
|
11
|
-
# in the future.
|
12
4
|
class HolidaysTests < Test::Unit::TestCase
|
13
5
|
def setup
|
14
6
|
@date = Date.civil(2008,1,1)
|
@@ -22,55 +14,31 @@ class HolidaysTests < Test::Unit::TestCase
|
|
22
14
|
assert_equal 0, holidays.length
|
23
15
|
end
|
24
16
|
|
25
|
-
def test_any_holidays_during_work_week
|
26
|
-
## Full weeks:
|
27
|
-
# Try with a Monday
|
28
|
-
assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,23), :us)
|
29
|
-
# Try with a Wednesday
|
30
|
-
assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,25), :us)
|
31
|
-
# Try Sunday on a week going into a new month
|
32
|
-
assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,29), :us)
|
33
|
-
# Try Wednesday on a week going into a new month
|
34
|
-
assert Holidays.any_holidays_during_work_week?(Date.civil(2012,2,1), :us)
|
35
|
-
|
36
|
-
## Weeks with holidays:
|
37
|
-
# New Year's 2012 (on Sunday, observed Monday). Test from a Wednesday.
|
38
|
-
assert_equal(false, Holidays.any_holidays_during_work_week?(Date.civil(2012,1,4), :us))
|
39
|
-
# Ignore observed holidays with :no_observed
|
40
|
-
assert Holidays.any_holidays_during_work_week?(Date.civil(2012,1,4), :us, :no_observed)
|
41
|
-
# Labor Day 2012 should be Sept 3
|
42
|
-
assert_equal(false, Holidays.any_holidays_during_work_week?(Date.civil(2012,9,5), :us))
|
43
|
-
# Should be 10 non-full weeks in the year (in the US)
|
44
|
-
weeks_in_2012 = Date.commercial(2013, -1).cweek
|
45
|
-
holidays_in_2012 = weeks_in_2012.times.count { |week| Holidays.any_holidays_during_work_week?(Date.commercial(2012,week+1), :us) == false }
|
46
|
-
assert_equal 10, holidays_in_2012
|
47
|
-
end
|
48
|
-
|
49
17
|
def test_requires_valid_regions
|
50
|
-
assert_raises Holidays::
|
18
|
+
assert_raises Holidays::InvalidRegion do
|
51
19
|
Holidays.on(Date.civil(2008,1,1), :xx)
|
52
20
|
end
|
53
21
|
|
54
|
-
assert_raises Holidays::
|
22
|
+
assert_raises Holidays::InvalidRegion do
|
55
23
|
Holidays.on(Date.civil(2008,1,1), [:ca,:xx])
|
56
24
|
end
|
57
25
|
|
58
|
-
assert_raises Holidays::
|
26
|
+
assert_raises Holidays::InvalidRegion do
|
59
27
|
Holidays.between(Date.civil(2008,1,1), Date.civil(2008,12,31), [:ca,:xx])
|
60
28
|
end
|
61
29
|
end
|
62
30
|
|
63
31
|
def test_requires_valid_regions_holiday_next
|
64
|
-
assert_raises Holidays::
|
32
|
+
assert_raises Holidays::InvalidRegion do
|
65
33
|
Holidays.next_holidays(1, [:xx], Date.civil(2008,1,1))
|
66
34
|
end
|
67
35
|
|
68
|
-
assert_raises Holidays::
|
36
|
+
assert_raises Holidays::InvalidRegion do
|
69
37
|
Holidays.next_holidays(1, [:ca,:xx], Date.civil(2008,1,1))
|
70
38
|
Holidays.on(Date.civil(2008,1,1), [:ca,:xx])
|
71
39
|
end
|
72
40
|
|
73
|
-
assert_raises Holidays::
|
41
|
+
assert_raises Holidays::InvalidRegion do
|
74
42
|
Holidays.next_holidays(1, [:ca,:xx])
|
75
43
|
end
|
76
44
|
end
|
@@ -92,9 +60,9 @@ class HolidaysTests < Test::Unit::TestCase
|
|
92
60
|
end
|
93
61
|
|
94
62
|
def test_any_region
|
95
|
-
# Should return Victoria Day
|
63
|
+
# Should return nothing(Victoria Day is not celebrated :ca wide anymore)
|
96
64
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca)
|
97
|
-
assert_equal
|
65
|
+
assert_equal 0, holidays.length
|
98
66
|
|
99
67
|
# Should return Victoria Day and National Patriotes Day.
|
100
68
|
#
|
@@ -112,13 +80,10 @@ class HolidaysTests < Test::Unit::TestCase
|
|
112
80
|
# Should return Victoria Day.
|
113
81
|
holidays = Holidays.next_holidays(1, [:ca], Date.civil(2008,5,1))
|
114
82
|
assert_equal 1, holidays.length
|
115
|
-
assert_equal ['2008-
|
83
|
+
assert_equal ['2008-07-01','Canada Day'] , [holidays.first[:date].to_s, holidays.first[:name].to_s]
|
116
84
|
|
117
85
|
# Should return 2 holidays.
|
118
|
-
|
119
|
-
# Should be 2 in the CA region but other regional files are loaded during the
|
120
|
-
# unit tests add to the :any count.
|
121
|
-
holidays = Holidays.next_holidays(2, [:any], Date.civil(2008,5,1))
|
86
|
+
holidays = Holidays.next_holidays(2, [:ca], Date.civil(2008,5,1))
|
122
87
|
assert_equal 2, holidays.length
|
123
88
|
|
124
89
|
# Should return 1 holiday in July
|
@@ -139,37 +104,97 @@ class HolidaysTests < Test::Unit::TestCase
|
|
139
104
|
end
|
140
105
|
end
|
141
106
|
|
107
|
+
def test_year_holidays
|
108
|
+
# Should return 7 holidays from February 23 to December 31
|
109
|
+
holidays = Holidays.year_holidays([:ca_on], Date.civil(2016, 2, 23))
|
110
|
+
assert_equal 7, holidays.length
|
111
|
+
|
112
|
+
# Must have options (Regions)
|
113
|
+
assert_raises ArgumentError do
|
114
|
+
Holidays.year_holidays([], Date.civil(2016, 2, 23))
|
115
|
+
end
|
116
|
+
|
117
|
+
# Options must be in the form of an array.
|
118
|
+
assert_raises ArgumentError do
|
119
|
+
Holidays.year_holidays(:ca_on, Date.civil(2016, 2, 23))
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_year_holidays_with_specified_year
|
124
|
+
# Should return all 11 holidays for 2016 in Ontario, Canada
|
125
|
+
holidays = Holidays.year_holidays([:ca_on], Date.civil(2016, 1, 1))
|
126
|
+
assert_equal 9, holidays.length
|
127
|
+
|
128
|
+
# Should return all 5 holidays for 2016 in Australia
|
129
|
+
holidays = Holidays.year_holidays([:au], Date.civil(2016, 1, 1))
|
130
|
+
assert_equal 5, holidays.length
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_year_holidays_without_specified_year
|
134
|
+
# Gets holidays for current year from today's date
|
135
|
+
holidays = Holidays.year_holidays([:de])
|
136
|
+
assert_equal holidays.first[:date].year, Date.today.year
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_year_holidays_empty
|
140
|
+
# if remain holidays is nothing , method will return empty.
|
141
|
+
holidays = Holidays.year_holidays([:ca_on], Date.civil(2016, 12, 27))
|
142
|
+
assert_empty holidays
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_year_holidays_random_years
|
146
|
+
# Should be 1 less holiday, as Family day didn't exist in Ontario in 1990
|
147
|
+
holidays = Holidays.year_holidays([:ca_on], Date.civil(1990, 1, 1))
|
148
|
+
assert_equal 8, holidays.length
|
149
|
+
|
150
|
+
# Family day still didn't exist in 2000
|
151
|
+
holidays = Holidays.year_holidays([:ca_on], Date.civil(2000, 1, 1))
|
152
|
+
assert_equal 8, holidays.length
|
153
|
+
|
154
|
+
holidays = Holidays.year_holidays([:ca_on], Date.civil(2020, 1, 1))
|
155
|
+
assert_equal 9, holidays.length
|
156
|
+
|
157
|
+
holidays = Holidays.year_holidays([:ca_on], Date.civil(2050, 1, 1))
|
158
|
+
assert_equal 9, holidays.length
|
159
|
+
|
160
|
+
holidays = Holidays.year_holidays([:jp], Date.civil(2070, 1, 1))
|
161
|
+
assert_equal 19, holidays.length
|
162
|
+
end
|
163
|
+
|
142
164
|
def test_sub_regions
|
143
|
-
# Should return Victoria Day
|
165
|
+
# Should return nothing (Victoria Day is no longer :ca wide)
|
144
166
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca)
|
145
|
-
assert_equal
|
167
|
+
assert_equal 0, holidays.length
|
146
168
|
|
147
|
-
|
169
|
+
## Should return National Patriotes Day.
|
148
170
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca_qc)
|
149
|
-
assert_equal
|
171
|
+
assert_equal 1, holidays.length
|
150
172
|
|
151
173
|
# Should return Victoria Day and National Patriotes Day.
|
152
174
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca_)
|
153
|
-
assert_equal
|
175
|
+
assert_equal 3, holidays.length
|
154
176
|
end
|
155
177
|
|
156
178
|
def test_sub_regions_holiday_next
|
157
179
|
# Should return Victoria Day.
|
158
|
-
holidays = Holidays.next_holidays(2, [:
|
180
|
+
holidays = Holidays.next_holidays(2, [:ca_bc], Date.civil(2008,5,1))
|
159
181
|
assert_equal 2, holidays.length
|
160
182
|
assert_equal ['2008-05-19','Victoria Day'] , [holidays.first[:date].to_s, holidays.first[:name].to_s]
|
161
183
|
|
162
184
|
# Should return Victoria Da and National Patriotes Day.
|
163
185
|
holidays = Holidays.next_holidays(2, [:ca_qc], Date.civil(2008,5,1))
|
164
186
|
assert_equal 2, holidays.length
|
165
|
-
assert_equal ['2008-
|
166
|
-
assert_equal ['2008-05-19','National Patriotes Day'] , [holidays.last[:date].to_s, holidays.last[:name].to_s]
|
187
|
+
assert_equal ['2008-06-24','Fête Nationale'] , [holidays.last[:date].to_s, holidays.last[:name].to_s]
|
167
188
|
|
168
189
|
# Should return Victoria Day and National Patriotes Day.
|
169
190
|
holidays = Holidays.next_holidays(2, [:ca_], Date.civil(2008,5,1))
|
170
191
|
assert_equal 2, holidays.length
|
171
|
-
|
172
|
-
|
192
|
+
|
193
|
+
# Aparently something in jruby doesn't sort the same way as other rubies so....we'll just do it ourselves so
|
194
|
+
# we don't flap.
|
195
|
+
sorted_holidays = holidays.sort_by { |h| h[:name] }
|
196
|
+
assert_equal ['2008-05-19','National Patriotes Day'] , [sorted_holidays.first[:date].to_s, sorted_holidays.first[:name].to_s]
|
197
|
+
assert_equal ['2008-05-19','Victoria Day'] , [sorted_holidays.last[:date].to_s, sorted_holidays.last[:name].to_s]
|
173
198
|
end
|
174
199
|
|
175
200
|
def test_easter_lambda
|
@@ -195,24 +220,30 @@ class HolidaysTests < Test::Unit::TestCase
|
|
195
220
|
}
|
196
221
|
end
|
197
222
|
|
198
|
-
#FIXME - I am not a huge fan of this test as it is written. It depends on the definitions not changing.
|
199
|
-
# I think that this is fine for an integration test but I think it should be labeled as such.
|
200
223
|
def test_caching
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
options = [:ca, :informal]
|
224
|
+
good_friday = Date.civil(2008, 3, 21)
|
225
|
+
easter_monday = Date.civil(2008, 3, 24)
|
226
|
+
cache_end_date = Date.civil(2008, 3, 25)
|
205
227
|
|
206
|
-
Holidays
|
228
|
+
Holidays.cache_between(good_friday, cache_end_date, :ca, :informal)
|
207
229
|
|
208
|
-
|
230
|
+
# Test that correct results are returned outside the
|
231
|
+
# cache range, and with no caching
|
232
|
+
assert_equal 1, Holidays.on(Date.civil(2035, 1, 1), :ca, :informal).length
|
233
|
+
assert_equal 1, Holidays.on(Date.civil(2035, 1, 1), :us).length
|
234
|
+
|
235
|
+
# Make sure cache is hit for all successive calls
|
236
|
+
Holidays::Factory::Finder.expects(:between).never
|
209
237
|
|
210
238
|
# Test that cache has been set and it returns the same as before
|
211
|
-
assert_equal 1, Holidays.on(
|
212
|
-
assert_equal 1, Holidays.on(
|
239
|
+
assert_equal 1, Holidays.on(good_friday, :ca, :informal).length
|
240
|
+
assert_equal 1, Holidays.on(easter_monday, :ca, :informal).length
|
241
|
+
assert_equal 1, easter_monday.holidays(:ca, :informal).length
|
242
|
+
assert_equal true, easter_monday.holiday?(:ca, :informal)
|
243
|
+
end
|
213
244
|
|
214
|
-
|
215
|
-
|
216
|
-
assert_equal
|
245
|
+
def test_load_all
|
246
|
+
Holidays.load_all
|
247
|
+
assert_equal 258, Holidays.available_regions.count
|
217
248
|
end
|
218
249
|
end
|