holidays 5.4.0 → 5.5.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 +15 -0
- data/Makefile +1 -1
- data/README.md +6 -6
- data/Rakefile +7 -8
- data/lib/generated_definitions/REGIONS.rb +3 -1
- data/lib/generated_definitions/ar.rb +0 -6
- data/lib/generated_definitions/at.rb +0 -6
- data/lib/generated_definitions/au.rb +6 -9
- data/lib/generated_definitions/be_fr.rb +0 -6
- data/lib/generated_definitions/be_nl.rb +0 -6
- data/lib/generated_definitions/bg.rb +0 -6
- data/lib/generated_definitions/br.rb +0 -6
- data/lib/generated_definitions/ca.rb +0 -6
- data/lib/generated_definitions/ch.rb +0 -6
- data/lib/generated_definitions/cl.rb +0 -6
- data/lib/generated_definitions/cr.rb +0 -6
- data/lib/generated_definitions/cz.rb +0 -6
- data/lib/generated_definitions/de.rb +0 -6
- data/lib/generated_definitions/dk.rb +0 -6
- data/lib/generated_definitions/ecb_target.rb +0 -6
- data/lib/generated_definitions/el.rb +0 -6
- data/lib/generated_definitions/es.rb +0 -6
- data/lib/generated_definitions/europe.rb +0 -6
- data/lib/generated_definitions/federal_reserve.rb +0 -6
- data/lib/generated_definitions/fedex.rb +0 -6
- data/lib/generated_definitions/fi.rb +0 -6
- data/lib/generated_definitions/fr.rb +0 -6
- data/lib/generated_definitions/gb.rb +0 -6
- data/lib/generated_definitions/hk.rb +0 -6
- data/lib/generated_definitions/hr.rb +0 -6
- data/lib/generated_definitions/hu.rb +0 -6
- data/lib/generated_definitions/ie.rb +0 -6
- data/lib/generated_definitions/is.rb +0 -6
- data/lib/generated_definitions/it.rb +0 -6
- data/lib/generated_definitions/jp.rb +0 -6
- data/lib/generated_definitions/kr.rb +15 -225
- data/lib/generated_definitions/li.rb +0 -6
- data/lib/generated_definitions/lt.rb +0 -6
- data/lib/generated_definitions/lu.rb +0 -6
- data/lib/generated_definitions/ma.rb +0 -6
- data/lib/generated_definitions/mx.rb +0 -6
- data/lib/generated_definitions/my.rb +0 -6
- data/lib/generated_definitions/nerc.rb +0 -6
- data/lib/generated_definitions/nl.rb +0 -6
- data/lib/generated_definitions/no.rb +0 -6
- data/lib/generated_definitions/north_america.rb +0 -6
- data/lib/generated_definitions/nyse.rb +1 -7
- data/lib/generated_definitions/nz.rb +0 -6
- data/lib/generated_definitions/pe.rb +0 -6
- data/lib/generated_definitions/ph.rb +0 -6
- data/lib/generated_definitions/pl.rb +0 -6
- data/lib/generated_definitions/pt.rb +0 -6
- data/lib/generated_definitions/ro.rb +0 -6
- data/lib/generated_definitions/scandinavia.rb +0 -6
- data/lib/generated_definitions/se.rb +0 -6
- data/lib/generated_definitions/sg.rb +0 -6
- data/lib/generated_definitions/si.rb +0 -6
- data/lib/generated_definitions/sk.rb +0 -6
- data/lib/generated_definitions/tn.rb +0 -6
- data/lib/generated_definitions/united_nations.rb +0 -6
- data/lib/generated_definitions/ups.rb +0 -6
- data/lib/generated_definitions/us.rb +0 -6
- data/lib/generated_definitions/ve.rb +0 -6
- data/lib/generated_definitions/vi.rb +5 -10
- data/lib/generated_definitions/za.rb +0 -6
- data/lib/holidays.rb +0 -1
- data/lib/holidays/date_calculator/lunar_date.rb +371 -0
- data/lib/holidays/definition/context/function_processor.rb +20 -15
- data/lib/holidays/definition/context/generator.rb +0 -6
- data/lib/holidays/definition/context/load.rb +29 -0
- data/lib/holidays/definition/context/merger.rb +0 -4
- data/lib/holidays/definition/generator/regions.rb +50 -0
- data/lib/holidays/definition/repository/cache.rb +20 -7
- 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 -9
- data/lib/holidays/factory/date_calculator.rb +5 -0
- data/lib/holidays/factory/definition.rb +17 -1
- data/lib/holidays/factory/finder.rb +1 -1
- data/lib/holidays/finder/context/between.rb +3 -0
- data/lib/holidays/finder/context/parse_options.rb +53 -52
- data/lib/holidays/finder/context/search.rb +23 -6
- data/lib/holidays/finder/rules/in_region.rb +1 -1
- data/lib/holidays/load_all_definitions.rb +9 -0
- data/lib/holidays/version.rb +1 -1
- data/test/data/test_invalid_region.rb +15 -0
- data/test/data/test_region.rb +15 -0
- data/test/defs/test_defs_au.rb +11 -1
- data/test/defs/test_defs_kr.rb +15 -12
- data/test/defs/test_defs_nyse.rb +5 -0
- data/test/defs/test_defs_vi.rb +6 -4
- data/test/holidays/date_calculator/test_lunar_date.rb +89 -0
- data/test/holidays/definition/context/test_function_processor.rb +47 -23
- data/test/holidays/definition/context/test_generator.rb +3 -3
- data/test/holidays/definition/context/test_load.rb +37 -0
- data/test/holidays/definition/generator/test_regions.rb +97 -0
- data/test/holidays/definition/repository/test_cache.rb +47 -6
- data/test/holidays/definition/repository/test_proc_result_cache.rb +7 -0
- 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 +7 -12
- data/test/holidays/factory/test_date_calculator.rb +5 -0
- data/test/holidays/factory/test_definition.rb +9 -0
- data/test/holidays/finder/context/test_parse_options.rb +102 -33
- data/test/holidays/finder/context/test_search.rb +45 -16
- data/test/integration/test_available_regions.rb +1 -1
- data/test/integration/test_custom_year_range_holidays.rb +0 -1
- data/test/integration/test_holidays.rb +3 -3
- data/test/integration/test_multiple_regions.rb +0 -1
- metadata +16 -3
|
@@ -91,7 +91,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
|
91
91
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
|
92
92
|
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
|
93
93
|
|
|
94
|
-
expected_module_src = "# encoding: utf-8\nmodule Holidays\n # This file is generated by the Ruby Holidays gem.\n #\n # Definitions loaded: test/data/test_single_custom_holiday_defs.yaml\n #\n #
|
|
94
|
+
expected_module_src = "# encoding: utf-8\nmodule Holidays\n # This file is generated by the Ruby Holidays gem.\n #\n # Definitions loaded: test/data/test_single_custom_holiday_defs.yaml\n #\n # All the definitions are available at https://github.com/holidays/holidays\n module TEST # :nodoc:\n def self.defined_regions\n [:custom_single_file]\n end\n\n def self.holidays_by_month\n {\n 6 => [{:mday => 20, :name => \"Company Founding\", :regions => [:custom_single_file]}]\n }\n end\n\n def self.custom_methods\n {\n \n }\n end\n end\nend\n"
|
|
95
95
|
|
|
96
96
|
assert_equal expected_module_src, module_src
|
|
97
97
|
end
|
|
@@ -158,7 +158,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
|
158
158
|
|
|
159
159
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
|
160
160
|
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
|
161
|
-
expected_module_src = "# encoding: utf-8\nmodule Holidays\n # This file is generated by the Ruby Holidays gem.\n #\n # Definitions loaded: test/data/test_custom_year_range_holiday_defs.yaml\n #\n #
|
|
161
|
+
expected_module_src = "# encoding: utf-8\nmodule Holidays\n # This file is generated by the Ruby Holidays gem.\n #\n # Definitions loaded: test/data/test_custom_year_range_holiday_defs.yaml\n #\n # All the definitions are available at https://github.com/holidays/holidays\n module TEST # :nodoc:\n def self.defined_regions\n [:custom_year_range_file]\n end\n\n def self.holidays_by_month\n {\n 6 => [{:mday => 1, :year_ranges => [{:after => 2016}],:name => \"after_year\", :regions => [:custom_year_range_file]},\n {:mday => 2, :year_ranges => [{:before => 2017}],:name => \"before_year\", :regions => [:custom_year_range_file]},\n {:mday => 3, :year_ranges => [{:between => 2016..2018}],:name => \"between_year\", :regions => [:custom_year_range_file]},\n {:mday => 4, :year_ranges => [{:limited => [2016, 2018, 2019]}],:name => \"limited_year\", :regions => [:custom_year_range_file]},\n {:mday => 5, :year_ranges => [{:before => 2015},{:after => 2017}],:name => \"multiple_conditions\", :regions => [:custom_year_range_file]}]\n }\n end\n\n def self.custom_methods\n {\n \n }\n end\n end\nend\n"
|
|
162
162
|
|
|
163
163
|
assert_equal expected_module_src, module_src
|
|
164
164
|
end
|
|
@@ -173,7 +173,7 @@ class GeneratorTests < Test::Unit::TestCase
|
|
|
173
173
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
|
174
174
|
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
|
175
175
|
|
|
176
|
-
expected_module_src = "# encoding: utf-8\nmodule Holidays\n # This file is generated by the Ruby Holidays gem.\n #\n # Definitions loaded: test/data/test_single_custom_holiday_with_custom_procs.yaml\n #\n #
|
|
176
|
+
expected_module_src = "# encoding: utf-8\nmodule Holidays\n # This file is generated by the Ruby Holidays gem.\n #\n # Definitions loaded: test/data/test_single_custom_holiday_with_custom_procs.yaml\n #\n # All the definitions are available at https://github.com/holidays/holidays\n module TEST # :nodoc:\n def self.defined_regions\n [:custom_single_file]\n end\n\n def self.holidays_by_month\n {\n 0 => [{:function => \"custom_method(year, month)\", :function_arguments => [:year, :month], :function_modifier => 5, :name => \"Custom Holiday\", :regions => [:custom_single_file]}],\n 6 => [{:mday => 20, :name => \"Company Founding\", :regions => [:custom_single_file]}]\n }\n end\n\n def self.custom_methods\n {\n \"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n},\n\n\n }\n end\n end\nend\n"
|
|
177
177
|
|
|
178
178
|
assert_equal expected_module_src, module_src
|
|
179
179
|
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
2
|
+
|
|
3
|
+
require 'holidays/definition/context/load'
|
|
4
|
+
|
|
5
|
+
class LoadTests < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
@definition_merger = mock()
|
|
8
|
+
full_definitions_path = File.expand_path(File.dirname(__FILE__)) + '/../../../data'
|
|
9
|
+
|
|
10
|
+
@subject = Holidays::Definition::Context::Load.new(
|
|
11
|
+
@definition_merger,
|
|
12
|
+
full_definitions_path,
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_region_is_found_and_loaded_and_merged
|
|
17
|
+
@definition_merger.expects(:call).with([:test_region, :test_region2], {}, {})
|
|
18
|
+
@subject.call(:test_region)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_region_file_not_found
|
|
22
|
+
assert_raises Holidays::UnknownRegionError do
|
|
23
|
+
@subject.call(:unknown)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_region_can_be_loaded_but_file_is_invalid
|
|
28
|
+
assert_raises Holidays::UnknownRegionError do
|
|
29
|
+
@subject.call(:test_invalid_region)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_returns_list_of_loaded_regions
|
|
34
|
+
@definition_merger.expects(:call).with([:test_region, :test_region2], {}, {})
|
|
35
|
+
assert_equal([:test_region, :test_region2], @subject.call(:test_region))
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
2
|
+
|
|
3
|
+
require 'holidays/definition/generator/regions'
|
|
4
|
+
|
|
5
|
+
class GeneratorRegionsTests < Test::Unit::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
@generator = Holidays::Definition::Generator::Regions.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_generates_regions_single_region_multiple_subregions
|
|
11
|
+
regions = {:region1 => [:test, :test2]}
|
|
12
|
+
expected = <<-EOE
|
|
13
|
+
# encoding: utf-8
|
|
14
|
+
module Holidays
|
|
15
|
+
REGIONS = [:test, :test2]
|
|
16
|
+
|
|
17
|
+
PARENT_REGION_LOOKUP = {:test=>:region1, :test2=>:region1}
|
|
18
|
+
end
|
|
19
|
+
EOE
|
|
20
|
+
|
|
21
|
+
assert_equal expected, @generator.call(regions)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_generates_regions_multiple_regions_single_unique_subregions
|
|
25
|
+
regions = {:region1 => [:test], :region2 => [:test2]}
|
|
26
|
+
expected = <<-EOE
|
|
27
|
+
# encoding: utf-8
|
|
28
|
+
module Holidays
|
|
29
|
+
REGIONS = [:test, :test2]
|
|
30
|
+
|
|
31
|
+
PARENT_REGION_LOOKUP = {:test=>:region1, :test2=>:region2}
|
|
32
|
+
end
|
|
33
|
+
EOE
|
|
34
|
+
|
|
35
|
+
assert_equal expected, @generator.call(regions)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_generates_regions_multiple_regions_multiple_overlapping_subregions
|
|
39
|
+
regions = {:region1 => [:test], :region2 => [:test, :test2], :region3 => [:test3, :test]}
|
|
40
|
+
expected = <<-EOE
|
|
41
|
+
# encoding: utf-8
|
|
42
|
+
module Holidays
|
|
43
|
+
REGIONS = [:test, :test2, :test3]
|
|
44
|
+
|
|
45
|
+
PARENT_REGION_LOOKUP = {:test=>:region1, :test2=>:region2, :test3=>:region3}
|
|
46
|
+
end
|
|
47
|
+
EOE
|
|
48
|
+
|
|
49
|
+
assert_equal expected, @generator.call(regions)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_generates_regions_multiple_regions_multiple_overlapping_subregions_complex
|
|
53
|
+
regions = {
|
|
54
|
+
:region1 => [:test],
|
|
55
|
+
:region2 => [:test, :test2],
|
|
56
|
+
:region3 => [:test3, :test],
|
|
57
|
+
:region4 => [:test4, :test2],
|
|
58
|
+
:region5 => [:test4, :test5, :test3],
|
|
59
|
+
:region6 => [:test4, :test6, :test],
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
expected = <<-EOE
|
|
63
|
+
# encoding: utf-8
|
|
64
|
+
module Holidays
|
|
65
|
+
REGIONS = [:test, :test2, :test3, :test4, :test5, :test6]
|
|
66
|
+
|
|
67
|
+
PARENT_REGION_LOOKUP = {:test=>:region1, :test2=>:region2, :test3=>:region3, :test4=>:region4, :test5=>:region5, :test6=>:region6}
|
|
68
|
+
end
|
|
69
|
+
EOE
|
|
70
|
+
|
|
71
|
+
assert_equal expected, @generator.call(regions)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_returns_error_if_regions_is_empty
|
|
75
|
+
regions = {}
|
|
76
|
+
|
|
77
|
+
assert_raises ArgumentError do
|
|
78
|
+
@generator.call(regions)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_returns_error_if_regions_is_not_a_hash
|
|
83
|
+
regions = "invalid"
|
|
84
|
+
|
|
85
|
+
assert_raises ArgumentError do
|
|
86
|
+
@generator.call(regions)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_returns_error_if_regions_is_nil
|
|
91
|
+
regions = nil
|
|
92
|
+
|
|
93
|
+
assert_raises ArgumentError do
|
|
94
|
+
@generator.call(regions)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -7,30 +7,71 @@ class CacheRepoTests < Test::Unit::TestCase
|
|
|
7
7
|
@subject = Holidays::Definition::Repository::Cache.new
|
|
8
8
|
end
|
|
9
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
|
+
|
|
10
49
|
def test_find_returns_correct_cache_data
|
|
11
50
|
start_date = Date.civil(2015, 1, 1)
|
|
12
|
-
end_date = Date.civil(2015,
|
|
13
|
-
cache_data =
|
|
51
|
+
end_date = Date.civil(2015, 7, 1)
|
|
52
|
+
cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
|
|
14
53
|
options = :us
|
|
15
54
|
@subject.cache_between(start_date, end_date, cache_data, options)
|
|
16
55
|
|
|
56
|
+
assert_equal(cache_data, @subject.find(start_date, start_date, options))
|
|
17
57
|
assert_equal(cache_data, @subject.find(start_date, end_date, options))
|
|
18
58
|
end
|
|
19
59
|
|
|
20
60
|
def test_find_returns_nil_if_no_match_is_found
|
|
21
61
|
start_date = Date.civil(2015, 1, 1)
|
|
22
62
|
end_date = Date.civil(2015, 1, 1)
|
|
23
|
-
cache_data =
|
|
63
|
+
cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
|
|
24
64
|
options = :us
|
|
25
65
|
@subject.cache_between(start_date, end_date, cache_data, options)
|
|
26
66
|
|
|
27
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))
|
|
28
69
|
end
|
|
29
70
|
|
|
30
71
|
def test_cache_between_returns_error_if_dates_are_missing
|
|
31
72
|
start_date = Date.civil(2015, 1, 1)
|
|
32
73
|
end_date = Date.civil(2015, 1, 1)
|
|
33
|
-
cache_data =
|
|
74
|
+
cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
|
|
34
75
|
options = :us
|
|
35
76
|
|
|
36
77
|
assert_raise ArgumentError do
|
|
@@ -45,7 +86,7 @@ class CacheRepoTests < Test::Unit::TestCase
|
|
|
45
86
|
def test_cache_between_returns_error_if_dates_are_invalid
|
|
46
87
|
start_date = Date.civil(2015, 1, 1)
|
|
47
88
|
end_date = Date.civil(2015, 1, 1)
|
|
48
|
-
cache_data =
|
|
89
|
+
cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
|
|
49
90
|
options = :us
|
|
50
91
|
|
|
51
92
|
assert_raise ArgumentError do
|
|
@@ -70,7 +111,7 @@ class CacheRepoTests < Test::Unit::TestCase
|
|
|
70
111
|
def test_reset_clears_cache
|
|
71
112
|
start_date = Date.civil(2015, 1, 1)
|
|
72
113
|
end_date = Date.civil(2015, 1, 1)
|
|
73
|
-
cache_data =
|
|
114
|
+
cache_data = [{:date=>Date.civil(2015, 1, 1), :name=>"New Year's Day", :regions=>[:us]}]
|
|
74
115
|
options = :us
|
|
75
116
|
@subject.cache_between(start_date, end_date, cache_data, options)
|
|
76
117
|
|
|
@@ -40,6 +40,13 @@ class ProcResultCacheRepoTests < Test::Unit::TestCase
|
|
|
40
40
|
assert_equal(Date.civil(2015, 1, 31), @subject.lookup(function, function_argument))
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
def test_lookup_accepts_symbol_as_function_argument
|
|
44
|
+
function = lambda { |symbol| symbol }
|
|
45
|
+
function_argument = :test
|
|
46
|
+
|
|
47
|
+
assert_equal(:test, @subject.lookup(function, function_argument))
|
|
48
|
+
end
|
|
49
|
+
|
|
43
50
|
def test_accepts_multiple_arguments_for_functions
|
|
44
51
|
function = lambda { |year, month, day| Date.civil(year, month, day) + 1 }
|
|
45
52
|
year = 2016
|
|
@@ -4,16 +4,22 @@ require 'holidays/definition/repository/regions'
|
|
|
4
4
|
|
|
5
5
|
class RegionsRepoTests < Test::Unit::TestCase
|
|
6
6
|
def setup
|
|
7
|
-
@
|
|
7
|
+
@all_generated_regions = [:parent, :subregion, :subregion_with_underscores, :region1, :region2]
|
|
8
|
+
@parent_region_lookup = {
|
|
9
|
+
:subregion => :parent,
|
|
10
|
+
:subregion_with_underscores => :parent,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@subject = Holidays::Definition::Repository::Regions.new(@all_generated_regions, @parent_region_lookup)
|
|
8
14
|
end
|
|
9
15
|
|
|
10
|
-
def
|
|
11
|
-
assert_equal([], @subject.
|
|
16
|
+
def test_all_loaded_returns_an_empty_array_if_just_initialize
|
|
17
|
+
assert_equal([], @subject.all_loaded)
|
|
12
18
|
end
|
|
13
19
|
|
|
14
20
|
def test_add_successfully_adds_a_region
|
|
15
21
|
@subject.add(:test)
|
|
16
|
-
assert_equal([:test], @subject.
|
|
22
|
+
assert_equal([:test], @subject.all_loaded)
|
|
17
23
|
end
|
|
18
24
|
|
|
19
25
|
def test_add_raises_error_if_symbol_not_provided
|
|
@@ -37,50 +43,62 @@ class RegionsRepoTests < Test::Unit::TestCase
|
|
|
37
43
|
def test_add_does_not_add_if_the_region_already_exists
|
|
38
44
|
@subject.add(:test)
|
|
39
45
|
@subject.add(:test)
|
|
40
|
-
assert_equal([:test], @subject.
|
|
46
|
+
assert_equal([:test], @subject.all_loaded)
|
|
41
47
|
end
|
|
42
48
|
|
|
43
49
|
def test_add_accepts_array_of_regions
|
|
44
50
|
@subject.add([:test, :test2])
|
|
45
|
-
assert_equal([:test, :test2], @subject.
|
|
51
|
+
assert_equal([:test, :test2], @subject.all_loaded)
|
|
46
52
|
end
|
|
47
53
|
|
|
48
54
|
def test_exists_returns_true_if_region_is_present
|
|
49
55
|
@subject.add(:test)
|
|
50
|
-
assert @subject.
|
|
56
|
+
assert @subject.loaded?(:test)
|
|
51
57
|
end
|
|
52
58
|
|
|
53
59
|
def tests_exists_returns_false_if_region_is_not_present
|
|
54
|
-
assert_equal(false, @subject.
|
|
60
|
+
assert_equal(false, @subject.loaded?(:something))
|
|
55
61
|
end
|
|
56
62
|
|
|
57
63
|
def test_exists_raises_error_if_invalid_argument
|
|
58
64
|
assert_raises ArgumentError do
|
|
59
|
-
@subject.
|
|
65
|
+
@subject.loaded?(nil)
|
|
60
66
|
end
|
|
61
67
|
end
|
|
62
68
|
|
|
63
69
|
def test_search_returns_empty_array_if_no_matches_found
|
|
64
|
-
assert_equal([], @subject.search(
|
|
70
|
+
assert_equal([], @subject.search(:something))
|
|
65
71
|
end
|
|
66
72
|
|
|
67
73
|
def test_search_returns_matches_on_prefix
|
|
68
74
|
@subject.add([:another_region, :test_region])
|
|
69
|
-
assert_equal([:test_region], @subject.search(
|
|
75
|
+
assert_equal([:test_region], @subject.search(:test_))
|
|
70
76
|
end
|
|
71
77
|
|
|
72
78
|
def test_search_returns_multiple_matches_on_prefix
|
|
73
79
|
@subject.add([:another_region, :test_region, :test_region2])
|
|
74
|
-
assert_equal([:test_region, :test_region2], @subject.search(
|
|
80
|
+
assert_equal([:test_region, :test_region2], @subject.search(:test_))
|
|
75
81
|
end
|
|
76
82
|
|
|
77
83
|
def test_search_raises_error_if_prefix_is_not_a_string
|
|
78
84
|
assert_raises ArgumentError do
|
|
79
|
-
@subject.search(
|
|
85
|
+
@subject.search("string")
|
|
80
86
|
end
|
|
81
87
|
|
|
82
88
|
assert_raises ArgumentError do
|
|
83
89
|
@subject.search(nil)
|
|
84
90
|
end
|
|
85
91
|
end
|
|
92
|
+
|
|
93
|
+
def test_all_generated_returns_value_from_initializer
|
|
94
|
+
assert_equal(@all_generated_regions, @subject.all_generated)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_parent_region_lookup_returns_region_if_it_exists
|
|
98
|
+
assert_equal(@parent_region_lookup[:subregion], @subject.parent_region_lookup(:subregion))
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def test_parent_region_lookup_returns_nil_if_does_not_exist_in_lookup
|
|
102
|
+
assert_nil(@subject.parent_region_lookup(:parent))
|
|
103
|
+
end
|
|
86
104
|
end
|
|
@@ -37,6 +37,11 @@ class CustomMethodValidatorTests < Test::Unit::TestCase
|
|
|
37
37
|
assert @subject.valid?(m)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
def test_valid_returns_true_with_region_argument
|
|
41
|
+
m = {:name => "good_method", :arguments => "region", :source => "source"}
|
|
42
|
+
assert @subject.valid?(m)
|
|
43
|
+
end
|
|
44
|
+
|
|
40
45
|
def test_valid_returns_true_multiple_arguments_with_whitespace
|
|
41
46
|
m = {:name => "good_method", :arguments => "year , month", :source => "source"}
|
|
42
47
|
assert @subject.valid?(m)
|
|
@@ -5,26 +5,24 @@ require 'holidays/definition/validator/region'
|
|
|
5
5
|
class RegionValidatorTests < Test::Unit::TestCase
|
|
6
6
|
def setup
|
|
7
7
|
@regions_repo = mock()
|
|
8
|
-
@regions_repo.stubs(:
|
|
8
|
+
@regions_repo.stubs(:loaded?).returns(false)
|
|
9
|
+
@regions_repo.stubs(:all_generated).returns([])
|
|
9
10
|
|
|
10
11
|
@subject = Holidays::Definition::Validator::Region.new(@regions_repo)
|
|
11
12
|
end
|
|
12
13
|
|
|
13
|
-
def
|
|
14
|
+
def test_returns_true_if_region_loaded_in_generated_files
|
|
15
|
+
@regions_repo.expects(:all_generated).returns([:us])
|
|
14
16
|
assert(@subject.valid?(:us))
|
|
15
|
-
assert(@subject.valid?(:federal_reserve))
|
|
16
|
-
assert(@subject.valid?(:ecb_target))
|
|
17
|
-
assert(@subject.valid?(:gb))
|
|
18
|
-
assert(@subject.valid?(:jp))
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
def test_returns_true_if_region_is_in_regions_repository
|
|
22
|
-
@regions_repo.expects(:
|
|
20
|
+
@regions_repo.expects(:loaded?).with(:custom).returns(true)
|
|
23
21
|
assert(@subject.valid?(:custom))
|
|
24
22
|
end
|
|
25
23
|
|
|
26
24
|
def test_returns_false_if_region_does_not_exist_in_generated_files_or_regions_repo
|
|
27
|
-
@regions_repo.expects(:
|
|
25
|
+
@regions_repo.expects(:loaded?).with(:unknown_region).returns(false)
|
|
28
26
|
assert_equal(false, @subject.valid?(:unknown_region))
|
|
29
27
|
end
|
|
30
28
|
|
|
@@ -32,15 +30,12 @@ class RegionValidatorTests < Test::Unit::TestCase
|
|
|
32
30
|
assert_equal(false, @subject.valid?('not-a-symbol'))
|
|
33
31
|
end
|
|
34
32
|
|
|
35
|
-
def test_returns_true_if_subregion
|
|
36
|
-
assert(@subject.valid?(:ca_qc))
|
|
37
|
-
end
|
|
38
|
-
|
|
39
33
|
def test_returns_true_if_region_is_any
|
|
40
34
|
assert(@subject.valid?(:any))
|
|
41
35
|
end
|
|
42
36
|
|
|
43
37
|
def test_returns_true_if_wildcard_region_is_valid
|
|
38
|
+
@regions_repo.expects(:all_generated).returns([:gb])
|
|
44
39
|
assert(@subject.valid?(:gb_))
|
|
45
40
|
end
|
|
46
41
|
|
|
@@ -24,4 +24,9 @@ class DateCalculatorFactoryTests < Test::Unit::TestCase
|
|
|
24
24
|
@subject = @subject::Easter::Julian
|
|
25
25
|
assert @subject.easter_calculator.is_a?(Holidays::DateCalculator::Easter::Julian)
|
|
26
26
|
end
|
|
27
|
+
|
|
28
|
+
def test_lunar_date
|
|
29
|
+
assert @subject.lunar_date.is_a?(Holidays::DateCalculator::LunarDate)
|
|
30
|
+
assert @subject.lunar_date.respond_to?('to_solar')
|
|
31
|
+
end
|
|
27
32
|
end
|
|
@@ -50,4 +50,13 @@ class DefinitionFactoryTests < Test::Unit::TestCase
|
|
|
50
50
|
def test_function_processor
|
|
51
51
|
assert Holidays::Factory::Definition.function_processor.is_a?(Holidays::Definition::Context::FunctionProcessor)
|
|
52
52
|
end
|
|
53
|
+
|
|
54
|
+
def test_regions_generator
|
|
55
|
+
assert Holidays::Factory::Definition.regions_generator.is_a?(Holidays::Definition::Generator::Regions)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_definitions_loader
|
|
59
|
+
assert Holidays::Factory::Definition.loader.is_a?(Holidays::Definition::Context::Load)
|
|
60
|
+
end
|
|
61
|
+
|
|
53
62
|
end
|