holidays 9.2.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +38 -2
- data/lib/generated_definitions/au.rb +16 -42
- data/lib/generated_definitions/europe.rb +2 -10
- data/lib/generated_definitions/lu.rb +1 -1
- data/lib/generated_definitions/nz.rb +9 -1
- data/lib/generated_definitions/pl.rb +3 -11
- data/lib/holidays/definition/context/function_processor.rb +4 -5
- data/lib/holidays/definition/context/generator.rb +3 -1
- data/lib/holidays/version.rb +1 -1
- metadata +3 -313
- data/.github/workflows/changelog-check.yml +0 -47
- data/.github/workflows/release.yml +0 -46
- data/.github/workflows/ruby.yml +0 -26
- data/.gitmodules +0 -3
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -8
- data/Makefile +0 -60
- data/Rakefile +0 -137
- data/bin/console +0 -7
- data/bin/setup +0 -6
- data/doc/CONTRIBUTING.md +0 -72
- data/doc/MAINTAINERS.md +0 -79
- data/doc/REFERENCES +0 -19
- data/holidays.gemspec +0 -31
- data/test/coverage_report.rb +0 -24
- data/test/data/test_custom_year_range_holiday_defs.yaml +0 -31
- data/test/data/test_date_transform_conflict_region_1.yaml +0 -14
- data/test/data/test_date_transform_conflict_region_2.yaml +0 -14
- data/test/data/test_invalid_region.rb +0 -15
- data/test/data/test_region.rb +0 -15
- data/test/data/test_single_custom_holiday_defs.yaml +0 -12
- data/test/data/test_single_custom_holiday_with_custom_procs.yaml +0 -28
- data/test/defs/test_defs_ar.rb +0 -69
- data/test/defs/test_defs_at.rb +0 -31
- data/test/defs/test_defs_au.rb +0 -233
- data/test/defs/test_defs_be_fr.rb +0 -45
- data/test/defs/test_defs_be_nl.rb +0 -45
- data/test/defs/test_defs_bg.rb +0 -41
- data/test/defs/test_defs_br.rb +0 -49
- data/test/defs/test_defs_ca.rb +0 -289
- data/test/defs/test_defs_ch.rb +0 -51
- data/test/defs/test_defs_cl.rb +0 -69
- data/test/defs/test_defs_co.rb +0 -113
- data/test/defs/test_defs_cr.rb +0 -29
- data/test/defs/test_defs_cy.rb +0 -41
- data/test/defs/test_defs_cz.rb +0 -37
- data/test/defs/test_defs_de.rb +0 -91
- data/test/defs/test_defs_dk.rb +0 -47
- data/test/defs/test_defs_ecbtarget.rb +0 -27
- data/test/defs/test_defs_ee.rb +0 -41
- data/test/defs/test_defs_es.rb +0 -137
- data/test/defs/test_defs_europe.rb +0 -1530
- data/test/defs/test_defs_fed_ex.rb +0 -24
- data/test/defs/test_defs_federalreserve.rb +0 -119
- data/test/defs/test_defs_federalreservebanks.rb +0 -251
- data/test/defs/test_defs_fedex.rb +0 -31
- data/test/defs/test_defs_fi.rb +0 -59
- data/test/defs/test_defs_fr.rb +0 -43
- data/test/defs/test_defs_gb.rb +0 -163
- data/test/defs/test_defs_ge.rb +0 -53
- data/test/defs/test_defs_gr.rb +0 -41
- data/test/defs/test_defs_hk.rb +0 -93
- data/test/defs/test_defs_hr.rb +0 -45
- data/test/defs/test_defs_hu.rb +0 -47
- data/test/defs/test_defs_ie.rb +0 -53
- data/test/defs/test_defs_il.rb +0 -35
- data/test/defs/test_defs_in.rb +0 -94
- data/test/defs/test_defs_is.rb +0 -51
- data/test/defs/test_defs_it.rb +0 -57
- data/test/defs/test_defs_jp.rb +0 -159
- data/test/defs/test_defs_ke.rb +0 -31
- data/test/defs/test_defs_kr.rb +0 -37
- data/test/defs/test_defs_kz.rb +0 -39
- data/test/defs/test_defs_li.rb +0 -35
- data/test/defs/test_defs_lt.rb +0 -65
- data/test/defs/test_defs_lu.rb +0 -35
- data/test/defs/test_defs_lv.rb +0 -98
- data/test/defs/test_defs_ma.rb +0 -29
- data/test/defs/test_defs_mc.rb +0 -43
- data/test/defs/test_defs_mt_en.rb +0 -41
- data/test/defs/test_defs_mt_mt.rb +0 -41
- data/test/defs/test_defs_mx.rb +0 -49
- data/test/defs/test_defs_my.rb +0 -23
- data/test/defs/test_defs_nerc.rb +0 -29
- data/test/defs/test_defs_ng.rb +0 -29
- data/test/defs/test_defs_nl.rb +0 -33
- data/test/defs/test_defs_no.rb +0 -43
- data/test/defs/test_defs_northamerica.rb +0 -679
- data/test/defs/test_defs_nyse.rb +0 -46
- data/test/defs/test_defs_nz.rb +0 -67
- data/test/defs/test_defs_pe.rb +0 -47
- data/test/defs/test_defs_ph.rb +0 -29
- data/test/defs/test_defs_pl.rb +0 -229
- data/test/defs/test_defs_pt.rb +0 -47
- data/test/defs/test_defs_ro.rb +0 -69
- data/test/defs/test_defs_rs_cyrl.rb +0 -46
- data/test/defs/test_defs_rs_la.rb +0 -46
- data/test/defs/test_defs_ru.rb +0 -34
- data/test/defs/test_defs_scandinavia.rb +0 -215
- data/test/defs/test_defs_se.rb +0 -59
- data/test/defs/test_defs_sg.rb +0 -25
- data/test/defs/test_defs_si.rb +0 -105
- data/test/defs/test_defs_sk.rb +0 -37
- data/test/defs/test_defs_southamerica.rb +0 -327
- data/test/defs/test_defs_th.rb +0 -33
- data/test/defs/test_defs_tn.rb +0 -27
- data/test/defs/test_defs_tr.rb +0 -60
- data/test/defs/test_defs_tsx.rb +0 -70
- data/test/defs/test_defs_ua.rb +0 -41
- data/test/defs/test_defs_unitednations.rb +0 -11
- data/test/defs/test_defs_ups.rb +0 -31
- data/test/defs/test_defs_us.rb +0 -399
- data/test/defs/test_defs_ve.rb +0 -35
- data/test/defs/test_defs_vi.rb +0 -22
- data/test/defs/test_defs_za.rb +0 -35
- data/test/e2e/README.md +0 -52
- data/test/e2e/data/test_multiple_regions_with_conflicts_region_1.yaml +0 -38
- data/test/e2e/data/test_multiple_regions_with_conflicts_region_2.yaml +0 -38
- data/test/e2e/data/test_multiple_regions_with_conflicts_region_3.yaml +0 -38
- data/test/e2e/test_all_regions.rb +0 -49
- data/test/e2e/test_any_holidays_during_work_week.rb +0 -90
- data/test/e2e/test_holidays.rb +0 -244
- data/test/e2e/test_holidays_between.rb +0 -87
- data/test/e2e/test_multiple_regions.rb +0 -71
- data/test/e2e/test_multiple_regions_with_conflict.rb +0 -228
- data/test/e2e/test_nonstandard_regions.rb +0 -25
- data/test/holidays/core_extensions/test_date.rb +0 -122
- data/test/holidays/core_extensions/test_date_time.rb +0 -60
- data/test/holidays/date_calculator/test_day_of_month.rb +0 -27
- data/test/holidays/date_calculator/test_easter_gregorian.rb +0 -30
- data/test/holidays/date_calculator/test_easter_julian.rb +0 -36
- data/test/holidays/date_calculator/test_lunar_date.rb +0 -89
- data/test/holidays/date_calculator/test_weekend_modifier.rb +0 -54
- data/test/holidays/definition/context/test_function_processor.rb +0 -199
- data/test/holidays/definition/context/test_generator.rb +0 -226
- data/test/holidays/definition/context/test_load.rb +0 -37
- data/test/holidays/definition/context/test_merger.rb +0 -25
- data/test/holidays/definition/decorator/test_custom_method_proc.rb +0 -113
- data/test/holidays/definition/decorator/test_custom_method_source.rb +0 -96
- data/test/holidays/definition/decorator/test_test.rb +0 -123
- data/test/holidays/definition/generator/test_module.rb +0 -268
- data/test/holidays/definition/generator/test_regions.rb +0 -97
- data/test/holidays/definition/generator/test_test.rb +0 -113
- data/test/holidays/definition/parser/test_custom_method.rb +0 -79
- data/test/holidays/definition/parser/test_test.rb +0 -142
- data/test/holidays/definition/repository/test_cache.rb +0 -123
- data/test/holidays/definition/repository/test_custom_methods.rb +0 -43
- data/test/holidays/definition/repository/test_holidays_by_month.rb +0 -275
- data/test/holidays/definition/repository/test_proc_result_cache.rb +0 -91
- data/test/holidays/definition/repository/test_regions.rb +0 -104
- data/test/holidays/definition/validator/test_custom_method.rb +0 -94
- data/test/holidays/definition/validator/test_region.rb +0 -54
- data/test/holidays/definition/validator/test_test.rb +0 -60
- data/test/holidays/finder/context/test_between.rb +0 -172
- data/test/holidays/finder/context/test_dates_driver_builder.rb +0 -91
- data/test/holidays/finder/context/test_next_holiday.rb +0 -156
- data/test/holidays/finder/context/test_parse_options.rb +0 -141
- data/test/holidays/finder/context/test_search.rb +0 -290
- data/test/holidays/finder/context/test_year_holiday.rb +0 -202
- data/test/holidays/finder/rules/test_in_region.rb +0 -42
- data/test/holidays/finder/rules/test_year_range.rb +0 -166
- data/test/integration/README.md +0 -48
- data/test/integration/data/test_custom_govt_holiday_defs.yaml +0 -5
- data/test/integration/data/test_custom_informal_holidays_defs.yaml +0 -11
- data/test/integration/data/test_multiple_custom_holiday_defs.yaml +0 -12
- data/test/integration/test_custom_holidays.rb +0 -41
- data/test/integration/test_custom_informal_holidays.rb +0 -15
- data/test/integration/test_custom_year_range_holidays.rb +0 -35
- data/test/smoke/README.md +0 -31
- data/test/smoke/test_available_regions.rb +0 -18
- data/test/smoke/test_smoke.rb +0 -74
- data/test/test_helper.rb +0 -37
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
2
|
-
|
|
3
|
-
require 'holidays/definition/parser/custom_method'
|
|
4
|
-
require 'holidays/definition/entity/custom_method'
|
|
5
|
-
|
|
6
|
-
class ParserCustomMethodTests < Test::Unit::TestCase
|
|
7
|
-
def setup
|
|
8
|
-
@validator = mock()
|
|
9
|
-
|
|
10
|
-
@parser = Holidays::Definition::Parser::CustomMethod.new(@validator)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def test_parse_happy_single_method
|
|
14
|
-
input = {"custom_method"=>{"arguments"=>"year", "ruby"=>"d = Date.civil(year, 1, 1)\nd + 2\n"}}
|
|
15
|
-
@validator.expects(:valid?).with({:name => "custom_method", :arguments => "year", :source => "d = Date.civil(year, 1, 1)\nd + 2\n"}).returns(true)
|
|
16
|
-
|
|
17
|
-
result = @parser.call(input)
|
|
18
|
-
|
|
19
|
-
assert_equal(1, result.size)
|
|
20
|
-
|
|
21
|
-
custom_method = result["custom_method(year)"]
|
|
22
|
-
assert(custom_method)
|
|
23
|
-
|
|
24
|
-
assert(custom_method.is_a?(Holidays::Definition::Entity::CustomMethod))
|
|
25
|
-
assert_equal("custom_method", custom_method.name)
|
|
26
|
-
assert_equal(["year"], custom_method.arguments)
|
|
27
|
-
assert_equal("d = Date.civil(year, 1, 1)\nd + 2\n", custom_method.source)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def test_call_happy_with_multiple_methods
|
|
31
|
-
input = {"custom_method"=>{"arguments"=>"year", "ruby"=>"d = Date.civil(year, 1, 1)\nd + 2\n"}, "second_method"=>{"arguments"=>"month","ruby"=>"source"}}
|
|
32
|
-
@validator.expects(:valid?).with({:name => "custom_method", :arguments => "year", :source => "d = Date.civil(year, 1, 1)\nd + 2\n"}).returns(true)
|
|
33
|
-
@validator.expects(:valid?).with({:name => "second_method", :arguments => "month", :source => "source"}).returns(true)
|
|
34
|
-
|
|
35
|
-
result = @parser.call(input)
|
|
36
|
-
|
|
37
|
-
assert_equal(2, result.size)
|
|
38
|
-
|
|
39
|
-
custom_method = result["custom_method(year)"]
|
|
40
|
-
assert(custom_method)
|
|
41
|
-
|
|
42
|
-
assert(custom_method.is_a?(Holidays::Definition::Entity::CustomMethod))
|
|
43
|
-
assert_equal("custom_method", custom_method.name)
|
|
44
|
-
assert_equal(["year"], custom_method.arguments)
|
|
45
|
-
assert_equal("d = Date.civil(year, 1, 1)\nd + 2\n", custom_method.source)
|
|
46
|
-
|
|
47
|
-
second_method= result["second_method(month)"]
|
|
48
|
-
assert(second_method)
|
|
49
|
-
|
|
50
|
-
assert(second_method.is_a?(Holidays::Definition::Entity::CustomMethod))
|
|
51
|
-
assert_equal("second_method", second_method.name)
|
|
52
|
-
assert_equal(["month"], second_method.arguments)
|
|
53
|
-
assert_equal("source", second_method.source)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_call_returns_empty_hash_if_methods_are_missing
|
|
57
|
-
assert_equal({}, @parser.call(nil))
|
|
58
|
-
assert_equal({}, @parser.call({}))
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def test_call_raises_error_if_validator_returns_false_for_single_method
|
|
62
|
-
input = {"custom_method"=>{"arguments"=>"year", "ruby"=>"d = Date.civil(year, 1, 1)\nd + 2\n"}}
|
|
63
|
-
@validator.expects(:valid?).with({:name => "custom_method", :arguments => "year", :source => "d = Date.civil(year, 1, 1)\nd + 2\n"}).returns(false)
|
|
64
|
-
|
|
65
|
-
assert_raises ArgumentError do
|
|
66
|
-
@parser.call(input)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def test_call_raises_error_if_validator_returns_false_for_one_of_multiple_methods
|
|
71
|
-
input = {"custom_method"=>{"arguments"=>"year", "ruby"=>"d = Date.civil(year, 1, 1)\nd + 2\n"}, "second_method"=>{"arguments"=>"month","ruby"=>"source"}}
|
|
72
|
-
@validator.expects(:valid?).with({:name => "custom_method", :arguments => "year", :source => "d = Date.civil(year, 1, 1)\nd + 2\n"}).returns(true)
|
|
73
|
-
@validator.expects(:valid?).with({:name => "second_method", :arguments => "month", :source => "source"}).returns(false)
|
|
74
|
-
|
|
75
|
-
assert_raises ArgumentError do
|
|
76
|
-
@parser.call(input)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
# Heh at this file name
|
|
2
|
-
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
3
|
-
|
|
4
|
-
require 'holidays/definition/parser/test'
|
|
5
|
-
require 'holidays/definition/entity/test'
|
|
6
|
-
|
|
7
|
-
class ParserTestTests < Test::Unit::TestCase
|
|
8
|
-
def setup
|
|
9
|
-
@validator = mock()
|
|
10
|
-
|
|
11
|
-
@parser = Holidays::Definition::Parser::Test.new(@validator)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def test_parse_no_tests
|
|
15
|
-
input = nil
|
|
16
|
-
result = @parser.call(input)
|
|
17
|
-
|
|
18
|
-
assert_equal(0, result.size)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def test_parse_single_test_happy
|
|
22
|
-
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us'] }, "expect" => { "name" => "Test Holiday" } } ]
|
|
23
|
-
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :options => nil, :name => "Test Holiday", :holiday => nil}).returns(true)
|
|
24
|
-
|
|
25
|
-
result = @parser.call(input)
|
|
26
|
-
|
|
27
|
-
assert_equal(1, result.size)
|
|
28
|
-
|
|
29
|
-
test = result.first
|
|
30
|
-
assert(test)
|
|
31
|
-
|
|
32
|
-
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
33
|
-
assert_equal([DateTime.parse('2016-01-01')], test.dates)
|
|
34
|
-
assert_equal([:us], test.regions)
|
|
35
|
-
assert_equal("Test Holiday", test.name)
|
|
36
|
-
assert(test.holiday?)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_parse_single_test_with_options
|
|
40
|
-
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us'], "options" => ['option1']}, "expect" => { "name" => "Test Holiday" } } ]
|
|
41
|
-
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :name => "Test Holiday", :options => ['option1'], :holiday => nil}).returns(true)
|
|
42
|
-
|
|
43
|
-
result = @parser.call(input)
|
|
44
|
-
|
|
45
|
-
assert_equal(1, result.size)
|
|
46
|
-
|
|
47
|
-
test = result.first
|
|
48
|
-
assert(test)
|
|
49
|
-
|
|
50
|
-
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
51
|
-
assert_equal([DateTime.parse('2016-01-01')], test.dates)
|
|
52
|
-
assert_equal([:us], test.regions)
|
|
53
|
-
assert_equal([:option1], test.options)
|
|
54
|
-
assert_equal("Test Holiday", test.name)
|
|
55
|
-
assert(test.holiday?)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def test_parse_single_test_with_single_option_as_string
|
|
59
|
-
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us'], "options" => 'option1'}, "expect" => { "name" => "Test Holiday" } } ]
|
|
60
|
-
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :name => "Test Holiday", :options => 'option1', :holiday => nil}).returns(true)
|
|
61
|
-
|
|
62
|
-
result = @parser.call(input)
|
|
63
|
-
|
|
64
|
-
assert_equal(1, result.size)
|
|
65
|
-
|
|
66
|
-
test = result.first
|
|
67
|
-
assert(test)
|
|
68
|
-
|
|
69
|
-
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
70
|
-
assert_equal([DateTime.parse('2016-01-01')], test.dates)
|
|
71
|
-
assert_equal([:us], test.regions)
|
|
72
|
-
assert_equal([:option1], test.options)
|
|
73
|
-
assert_equal("Test Holiday", test.name)
|
|
74
|
-
assert(test.holiday?)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def test_parse_single_test_no_name_no_holiday
|
|
78
|
-
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us']}, "expect" => { "holiday" => false } } ]
|
|
79
|
-
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :name => nil, :options => nil, :holiday => false}).returns(true)
|
|
80
|
-
|
|
81
|
-
result = @parser.call(input)
|
|
82
|
-
|
|
83
|
-
assert_equal(1, result.size)
|
|
84
|
-
|
|
85
|
-
test = result.first
|
|
86
|
-
assert(test)
|
|
87
|
-
|
|
88
|
-
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
89
|
-
assert_equal([DateTime.parse('2016-01-01')], test.dates)
|
|
90
|
-
assert_equal([:us], test.regions)
|
|
91
|
-
assert_nil(test.options)
|
|
92
|
-
assert_nil(test.name)
|
|
93
|
-
assert_equal(false, test.holiday?)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def test_parse_single_test_with_options_no_name_no_holiday
|
|
97
|
-
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us'], "options" => ['option1']}, "expect" => { "holiday" => false } } ]
|
|
98
|
-
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :name => nil, :options => ['option1'], :holiday => false}).returns(true)
|
|
99
|
-
|
|
100
|
-
result = @parser.call(input)
|
|
101
|
-
|
|
102
|
-
assert_equal(1, result.size)
|
|
103
|
-
|
|
104
|
-
test = result.first
|
|
105
|
-
assert(test)
|
|
106
|
-
|
|
107
|
-
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
108
|
-
assert_equal([DateTime.parse('2016-01-01')], test.dates)
|
|
109
|
-
assert_equal([:us], test.regions)
|
|
110
|
-
assert_equal([:option1], test.options)
|
|
111
|
-
assert_nil(test.name)
|
|
112
|
-
assert_equal(false, test.holiday?)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def test_parse_single_test_multiple_dates
|
|
116
|
-
input = [ { "given" => { "date" => ["2016-01-01", "2017-01-01"], "regions" => ['us']}, "expect" => { "name" => "Test Holiday"} } ]
|
|
117
|
-
@validator.expects(:valid?).with({:dates => ["2016-01-01", "2017-01-01"], :regions=> ['us'], :name => "Test Holiday", :options => nil, :holiday => nil}).returns(true)
|
|
118
|
-
|
|
119
|
-
result = @parser.call(input)
|
|
120
|
-
|
|
121
|
-
assert_equal(1, result.size)
|
|
122
|
-
|
|
123
|
-
test = result.first
|
|
124
|
-
assert(test)
|
|
125
|
-
|
|
126
|
-
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
127
|
-
assert_equal([DateTime.parse('2016-01-01'), DateTime.parse('2017-01-01')], test.dates)
|
|
128
|
-
assert_equal([:us], test.regions)
|
|
129
|
-
assert_nil(test.options)
|
|
130
|
-
assert_equal("Test Holiday", test.name)
|
|
131
|
-
assert(test.holiday?)
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def test_parse_single_test_fail_validation
|
|
135
|
-
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us']}, "expect" => { "name" => "Test Holiday"} } ]
|
|
136
|
-
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :name => "Test Holiday", :options => nil, :holiday => nil}).returns(false)
|
|
137
|
-
|
|
138
|
-
assert_raises ArgumentError do
|
|
139
|
-
@parser.call(input)
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
2
|
-
|
|
3
|
-
require 'holidays/definition/repository/cache'
|
|
4
|
-
|
|
5
|
-
class CacheRepoTests < Test::Unit::TestCase
|
|
6
|
-
def setup
|
|
7
|
-
@subject = Holidays::Definition::Repository::Cache.new
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def test_find_supports_overlapping_holidays
|
|
11
|
-
start_date = Date.civil(2015, 1, 1)
|
|
12
|
-
end_date = Date.civil(2015, 7, 1)
|
|
13
|
-
cache_data = [
|
|
14
|
-
{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day A", :regions=>[:us]},
|
|
15
|
-
{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day B", :regions=>[:us]}
|
|
16
|
-
]
|
|
17
|
-
options = :us
|
|
18
|
-
|
|
19
|
-
@subject.cache_between(start_date, end_date, cache_data, options)
|
|
20
|
-
|
|
21
|
-
assert_equal(cache_data, @subject.find(start_date, start_date, options))
|
|
22
|
-
assert_equal(cache_data, @subject.find(start_date, end_date, options))
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_cache_returns_empty_array_no_holidays_are_found
|
|
26
|
-
start_date = Date.civil(2015, 1, 1)
|
|
27
|
-
end_date = Date.civil(2015, 7, 1)
|
|
28
|
-
cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
|
|
29
|
-
options = :us
|
|
30
|
-
|
|
31
|
-
@subject.cache_between(start_date, end_date, cache_data, options)
|
|
32
|
-
|
|
33
|
-
assert_empty(@subject.find(Date.civil(2015, 1, 2), Date.civil(2015, 1, 2), options))
|
|
34
|
-
assert_empty(@subject.find(Date.civil(2015, 1, 2), Date.civil(2015, 1, 3), options))
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def test_cache_returns_empty_array_when_cache_is_empty
|
|
38
|
-
start_date = Date.civil(2015, 1, 1)
|
|
39
|
-
end_date = Date.civil(2015, 7, 1)
|
|
40
|
-
cache_data = []
|
|
41
|
-
options = :us
|
|
42
|
-
|
|
43
|
-
@subject.cache_between(start_date, end_date, cache_data, options)
|
|
44
|
-
|
|
45
|
-
assert_empty(@subject.find(Date.civil(2015, 1, 2), Date.civil(2015, 1, 2), options))
|
|
46
|
-
assert_empty(@subject.find(Date.civil(2015, 1, 2), Date.civil(2015, 1, 3), options))
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def test_find_returns_correct_cache_data
|
|
50
|
-
start_date = Date.civil(2015, 1, 1)
|
|
51
|
-
end_date = Date.civil(2015, 7, 1)
|
|
52
|
-
cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
|
|
53
|
-
options = :us
|
|
54
|
-
@subject.cache_between(start_date, end_date, cache_data, options)
|
|
55
|
-
|
|
56
|
-
assert_equal(cache_data, @subject.find(start_date, start_date, options))
|
|
57
|
-
assert_equal(cache_data, @subject.find(start_date, end_date, options))
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def test_find_returns_nil_if_no_match_is_found
|
|
61
|
-
start_date = Date.civil(2015, 1, 1)
|
|
62
|
-
end_date = Date.civil(2015, 1, 1)
|
|
63
|
-
cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
|
|
64
|
-
options = :us
|
|
65
|
-
@subject.cache_between(start_date, end_date, cache_data, options)
|
|
66
|
-
|
|
67
|
-
assert_nil(@subject.find(Date.civil(2015, 7, 1), Date.civil(2015, 12, 1), options))
|
|
68
|
-
assert_nil(@subject.find(Date.civil(2015, 7, 1), Date.civil(2015, 12, 1), options))
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def test_cache_between_returns_error_if_dates_are_missing
|
|
72
|
-
start_date = Date.civil(2015, 1, 1)
|
|
73
|
-
end_date = Date.civil(2015, 1, 1)
|
|
74
|
-
cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
|
|
75
|
-
options = :us
|
|
76
|
-
|
|
77
|
-
assert_raise ArgumentError do
|
|
78
|
-
@subject.cache_between(nil, end_date, cache_data, options)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
assert_raise ArgumentError do
|
|
82
|
-
@subject.cache_between(start_date, nil, cache_data, options)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def test_cache_between_returns_error_if_dates_are_invalid
|
|
87
|
-
start_date = Date.civil(2015, 1, 1)
|
|
88
|
-
end_date = Date.civil(2015, 1, 1)
|
|
89
|
-
cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
|
|
90
|
-
options = :us
|
|
91
|
-
|
|
92
|
-
assert_raise ArgumentError do
|
|
93
|
-
@subject.cache_between("invalid-date", end_date, cache_data, options)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
assert_raise ArgumentError do
|
|
97
|
-
@subject.cache_between(start_date, "invalid-date", cache_data, options)
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def test_cache_between_returns_error_if_cached_data_is_not_present
|
|
102
|
-
start_date = Date.civil(2015, 1, 1)
|
|
103
|
-
end_date = Date.civil(2015, 1, 1)
|
|
104
|
-
options = :us
|
|
105
|
-
|
|
106
|
-
assert_raise ArgumentError do
|
|
107
|
-
@subject.cache_between(start_date, end_date, nil, options)
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def test_reset_clears_cache
|
|
112
|
-
start_date = Date.civil(2015, 1, 1)
|
|
113
|
-
end_date = Date.civil(2015, 1, 1)
|
|
114
|
-
cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
|
|
115
|
-
options = :us
|
|
116
|
-
@subject.cache_between(start_date, end_date, cache_data, options)
|
|
117
|
-
|
|
118
|
-
assert_equal(cache_data, @subject.find(start_date, end_date, options))
|
|
119
|
-
|
|
120
|
-
@subject.reset!
|
|
121
|
-
assert_nil(@subject.find(start_date, end_date, options))
|
|
122
|
-
end
|
|
123
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
2
|
-
|
|
3
|
-
require 'holidays/definition/repository/custom_methods'
|
|
4
|
-
|
|
5
|
-
class CustomMethodsRepoTests < Test::Unit::TestCase
|
|
6
|
-
def setup
|
|
7
|
-
@subject = Holidays::Definition::Repository::CustomMethods.new
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def test_add_raises_error_if_input_is_nil
|
|
11
|
-
assert_raise ArgumentError do
|
|
12
|
-
@subject.add(nil)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_find_returns_nil_if_method_id_does_not_exist
|
|
17
|
-
assert_nil @subject.find("some-method-id")
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_add_successfully_adds_new_custom_methods
|
|
21
|
-
new_custom_methods = {
|
|
22
|
-
"some-method-id" => Proc.new { |year|
|
|
23
|
-
Date.civil(year, 1, 1)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@subject.add(new_custom_methods)
|
|
28
|
-
|
|
29
|
-
target_method = @subject.find("some-method-id")
|
|
30
|
-
|
|
31
|
-
assert_equal new_custom_methods["some-method-id"], target_method
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def test_find_raises_error_if_target_method_id_is_nil_or_empty
|
|
35
|
-
assert_raise ArgumentError do
|
|
36
|
-
@subject.find(nil)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
assert_raise ArgumentError do
|
|
40
|
-
@subject.find("")
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
2
|
-
|
|
3
|
-
require 'holidays/definition/repository/holidays_by_month'
|
|
4
|
-
|
|
5
|
-
class HolidaysByMonthRepoTests < Test::Unit::TestCase
|
|
6
|
-
def setup
|
|
7
|
-
@existing_holidays_by_month = {0 => [:mday => 1, :name => "Test", :regions => [:test]]}
|
|
8
|
-
|
|
9
|
-
@subject = Holidays::Definition::Repository::HolidaysByMonth.new
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def test_all_returns_empty_hash_if_no_holidays_have_been_added
|
|
13
|
-
assert_equal({}, @subject.all)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_all_returns_existing_holidays
|
|
17
|
-
@subject.add(@existing_holidays_by_month)
|
|
18
|
-
assert_equal(@existing_holidays_by_month, @subject.all)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def test_add_does_not_change_data_if_it_already_exists
|
|
22
|
-
target_holidays = {0 => [:mday => 1, :name => "Test", :regions => [:test]]}
|
|
23
|
-
|
|
24
|
-
@subject.add(@existing_holidays_by_month)
|
|
25
|
-
@subject.add(target_holidays)
|
|
26
|
-
|
|
27
|
-
expected = @existing_holidays_by_month
|
|
28
|
-
|
|
29
|
-
assert_equal(expected, @subject.all)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_add_is_successful_if_name_is_different
|
|
33
|
-
target_holidays = {0 => [:mday => 1, :name => "Different", :regions => [:test]]}
|
|
34
|
-
|
|
35
|
-
@subject.add(@existing_holidays_by_month)
|
|
36
|
-
@subject.add(target_holidays)
|
|
37
|
-
|
|
38
|
-
expected = {
|
|
39
|
-
0 => [
|
|
40
|
-
{:mday=>1, :name=>"Test", :regions=>[:test]},
|
|
41
|
-
{:mday=>1, :name=>"Different", :regions=>[:test]}
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
assert_equal(expected, @subject.all)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_add_is_successful_if_wday_is_different
|
|
49
|
-
target_holidays = {0 => [:mday => 1, :name => "Test", :wday => 1, :regions => [:test]]}
|
|
50
|
-
|
|
51
|
-
@subject.add(@existing_holidays_by_month)
|
|
52
|
-
@subject.add(target_holidays)
|
|
53
|
-
|
|
54
|
-
expected = {
|
|
55
|
-
0 => [
|
|
56
|
-
{:mday=>1, :name=>"Test", :regions=>[:test]},
|
|
57
|
-
{:mday=>1, :name=>"Test", :wday => 1, :regions=>[:test]}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
assert_equal(expected, @subject.all)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def test_add_is_successful_if_mday_is_different
|
|
65
|
-
target_holidays = {0 => [:mday => 2, :name => "Test", :regions => [:test]]}
|
|
66
|
-
|
|
67
|
-
@subject.add(@existing_holidays_by_month)
|
|
68
|
-
@subject.add(target_holidays)
|
|
69
|
-
|
|
70
|
-
expected = {
|
|
71
|
-
0 => [
|
|
72
|
-
{:mday=>1, :name=>"Test", :regions=>[:test]},
|
|
73
|
-
{:mday=>2, :name=>"Test", :regions=>[:test]}
|
|
74
|
-
]
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
assert_equal(expected, @subject.all)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def test_add_is_successful_if_week_is_different
|
|
81
|
-
target_holidays = {0 => [:mday => 1, :name => "Test", :week => :first, :regions => [:test]]}
|
|
82
|
-
|
|
83
|
-
@subject.add(@existing_holidays_by_month)
|
|
84
|
-
@subject.add(target_holidays)
|
|
85
|
-
|
|
86
|
-
expected = {
|
|
87
|
-
0 => [
|
|
88
|
-
{:mday=>1, :name=>"Test", :regions=>[:test]},
|
|
89
|
-
{:mday=>1, :name=>"Test", :week => :first, :regions=>[:test]}
|
|
90
|
-
]
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
assert_equal(expected, @subject.all)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def test_add_is_successful_if_type_is_different
|
|
97
|
-
target_holidays = {0 => [:mday => 1, :name => "Test", :type => :informal, :regions => [:test]]}
|
|
98
|
-
|
|
99
|
-
@subject.add(@existing_holidays_by_month)
|
|
100
|
-
@subject.add(target_holidays)
|
|
101
|
-
|
|
102
|
-
expected = {
|
|
103
|
-
0 => [
|
|
104
|
-
{:mday=>1, :name=>"Test", :regions=>[:test]},
|
|
105
|
-
{:mday=>1, :name=>"Test", :type => :informal, :regions=>[:test]}
|
|
106
|
-
]
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
assert_equal(expected, @subject.all)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def test_add_is_successful_if_only_region_is_different_and_updates_regions_to_existing_matching_definitions
|
|
113
|
-
target_holidays = {0 => [:mday => 1, :name => "Test", :regions => [:test2]]}
|
|
114
|
-
|
|
115
|
-
@subject.add(@existing_holidays_by_month)
|
|
116
|
-
@subject.add(target_holidays)
|
|
117
|
-
|
|
118
|
-
expected = { 0 => [ {:mday=>1, :name=>"Test", :regions=>[:test, :test2]} ] }
|
|
119
|
-
|
|
120
|
-
assert_equal(expected, @subject.all)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def test_add_is_successful_and_updates_regions_to_existing_matching_definitions_and_deduped_correctly
|
|
124
|
-
target_holidays = {0 => [:mday => 1, :name => "Test", :regions => [:test2, :test]]}
|
|
125
|
-
|
|
126
|
-
@subject.add(@existing_holidays_by_month)
|
|
127
|
-
@subject.add(target_holidays)
|
|
128
|
-
|
|
129
|
-
expected = { 0 => [ {:mday=>1, :name=>"Test", :regions=>[:test, :test2]} ] }
|
|
130
|
-
|
|
131
|
-
assert_equal(expected, @subject.all)
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def test_find_by_month_returns_nil_if_none_found
|
|
135
|
-
@subject.add(@existing_holidays_by_month)
|
|
136
|
-
|
|
137
|
-
holidays_for_month = @subject.find_by_month(12)
|
|
138
|
-
assert_equal(nil, holidays_for_month)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def test_find_by_month_returns_array_if_found
|
|
142
|
-
@subject.add(@existing_holidays_by_month)
|
|
143
|
-
|
|
144
|
-
holidays_for_month = @subject.find_by_month(0)
|
|
145
|
-
assert_equal(@existing_holidays_by_month[0], holidays_for_month)
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def test_find_by_month_raises_error_if_month_is_not_valid
|
|
149
|
-
@subject.add(@existing_holidays_by_month)
|
|
150
|
-
|
|
151
|
-
assert_raise ArgumentError do
|
|
152
|
-
@subject.find_by_month(-1)
|
|
153
|
-
end
|
|
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
|
|
275
|
-
end
|