holidays 5.7.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +1 -1
- data/CHANGELOG.md +11 -0
- data/lib/generated_definitions/north_america.rb +1 -1
- data/lib/generated_definitions/tr.rb +1 -0
- data/lib/generated_definitions/us.rb +1 -1
- data/lib/holidays/definition/context/generator.rb +5 -36
- data/lib/holidays/definition/decorator/test.rb +37 -0
- data/lib/holidays/definition/entity/test.rb +11 -0
- data/lib/holidays/definition/generator/test.rb +51 -0
- data/lib/holidays/definition/parser/test.rb +86 -0
- data/lib/holidays/definition/validator/test.rb +71 -0
- data/lib/holidays/errors.rb +3 -0
- data/lib/holidays/factory/definition.rb +24 -0
- data/lib/holidays/version.rb +1 -1
- data/test/coverage_report.rb +1 -0
- data/test/data/test_custom_year_range_holiday_defs.yaml +7 -0
- data/test/data/test_multiple_custom_holiday_defs.yaml +7 -4
- 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 +33 -19
- data/test/defs/test_defs_at.rb +14 -11
- data/test/defs/test_defs_au.rb +172 -141
- data/test/defs/test_defs_be_fr.rb +23 -14
- data/test/defs/test_defs_be_nl.rb +23 -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 +175 -176
- data/test/defs/test_defs_ch.rb +29 -23
- data/test/defs/test_defs_cl.rb +49 -27
- 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 +52 -61
- data/test/defs/test_defs_dk.rb +31 -19
- data/test/defs/test_defs_ecb_target.rb +14 -10
- data/test/defs/test_defs_ee.rb +28 -20
- data/test/defs/test_defs_el.rb +29 -17
- data/test/defs/test_defs_es.rb +114 -52
- data/test/defs/test_defs_europe.rb +1154 -715
- data/test/defs/test_defs_federal_reserve.rb +99 -57
- 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 +29 -24
- data/test/defs/test_defs_gb.rb +90 -51
- data/test/defs/test_defs_ge.rb +40 -28
- data/test/defs/test_defs_hk.rb +47 -26
- data/test/defs/test_defs_hr.rb +32 -18
- data/test/defs/test_defs_hu.rb +26 -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 +23 -14
- data/test/defs/test_defs_jp.rb +112 -59
- data/test/defs/test_defs_kr.rb +25 -17
- 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 +17 -12
- data/test/defs/test_defs_ma.rb +17 -11
- data/test/defs/test_defs_mt_en.rb +28 -19
- data/test/defs/test_defs_mt_mt.rb +28 -19
- data/test/defs/test_defs_mx.rb +33 -22
- data/test/defs/test_defs_my.rb +11 -8
- data/test/defs/test_defs_nerc.rb +17 -11
- data/test/defs/test_defs_nl.rb +21 -13
- data/test/defs/test_defs_no.rb +31 -18
- data/test/defs/test_defs_north_america.rb +507 -393
- data/test/defs/test_defs_nyse.rb +26 -15
- data/test/defs/test_defs_nz.rb +47 -28
- data/test/defs/test_defs_pe.rb +35 -20
- data/test/defs/test_defs_ph.rb +17 -11
- data/test/defs/test_defs_pl.rb +200 -119
- data/test/defs/test_defs_pt.rb +33 -24
- data/test/defs/test_defs_ro.rb +39 -24
- data/test/defs/test_defs_rs_cyrl.rb +33 -26
- data/test/defs/test_defs_rs_la.rb +33 -26
- data/test/defs/test_defs_ru.rb +22 -16
- 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_tn.rb +15 -10
- data/test/defs/test_defs_tr.rb +39 -30
- data/test/defs/test_defs_united_nations.rb +0 -1
- data/test/defs/test_defs_ups.rb +19 -12
- data/test/defs/test_defs_us.rb +333 -217
- data/test/defs/test_defs_ve.rb +23 -16
- data/test/defs/test_defs_vi.rb +10 -8
- data/test/defs/test_defs_za.rb +23 -14
- data/test/holidays/definition/context/test_generator.rb +40 -13
- data/test/holidays/definition/decorator/test_test.rb +123 -0
- data/test/holidays/definition/generator/test_test.rb +113 -0
- data/test/holidays/definition/parser/test_test.rb +142 -0
- data/test/holidays/definition/validator/test_region.rb +5 -0
- data/test/holidays/definition/validator/test_test.rb +60 -0
- metadata +15 -8
- data/test/holidays/factory/test_date_calculator.rb +0 -32
- data/test/holidays/factory/test_definition.rb +0 -62
- data/test/holidays/factory/test_finder.rb +0 -25
data/test/defs/test_defs_ve.rb
CHANGED
@@ -7,22 +7,29 @@ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
|
7
7
|
class VeDefinitionTests < Test::Unit::TestCase # :nodoc:
|
8
8
|
|
9
9
|
def test_ve
|
10
|
-
{
|
11
|
-
|
12
|
-
Date.civil(2013, 2, 11)
|
13
|
-
|
14
|
-
Date.civil(2013,
|
15
|
-
|
16
|
-
Date.civil(2013,
|
17
|
-
|
18
|
-
Date.civil(2013,
|
19
|
-
|
20
|
-
Date.civil(2013,
|
21
|
-
|
22
|
-
Date.civil(2013,
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
assert_equal "Año Nuevo", (Holidays.on(Date.civil(2013, 1, 1), [:ve])[0] || {})[:name]
|
11
|
+
|
12
|
+
assert_equal "Lunes Carnaval", (Holidays.on(Date.civil(2013, 2, 11), [:ve])[0] || {})[:name]
|
13
|
+
|
14
|
+
assert_equal "Martes Carnaval", (Holidays.on(Date.civil(2013, 2, 12), [:ve])[0] || {})[:name]
|
15
|
+
|
16
|
+
assert_equal "Jueves Santo", (Holidays.on(Date.civil(2013, 3, 28), [:ve])[0] || {})[:name]
|
17
|
+
|
18
|
+
assert_equal "Viernes Santo", (Holidays.on(Date.civil(2013, 3, 29), [:ve])[0] || {})[:name]
|
19
|
+
|
20
|
+
assert_equal "Declaración Independencia", (Holidays.on(Date.civil(2013, 4, 19), [:ve])[0] || {})[:name]
|
21
|
+
|
22
|
+
assert_equal "Día del Trabajador", (Holidays.on(Date.civil(2013, 5, 1), [:ve])[0] || {})[:name]
|
23
|
+
|
24
|
+
assert_equal "Aniversario Batalla de Carabobo", (Holidays.on(Date.civil(2013, 6, 24), [:ve])[0] || {})[:name]
|
25
|
+
|
26
|
+
assert_equal "Día de la Independencia", (Holidays.on(Date.civil(2013, 7, 5), [:ve])[0] || {})[:name]
|
27
|
+
|
28
|
+
assert_equal "Natalicio de Simón Bolívar", (Holidays.on(Date.civil(2013, 7, 24), [:ve])[0] || {})[:name]
|
29
|
+
|
30
|
+
assert_equal "Día de la Resistencia Indígena", (Holidays.on(Date.civil(2013, 10, 12), [:ve])[0] || {})[:name]
|
31
|
+
|
32
|
+
assert_equal "Día de Navidad", (Holidays.on(Date.civil(2013, 12, 25), [:ve])[0] || {})[:name]
|
26
33
|
|
27
34
|
end
|
28
35
|
end
|
data/test/defs/test_defs_vi.rb
CHANGED
@@ -7,14 +7,16 @@ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
|
7
7
|
class ViDefinitionTests < Test::Unit::TestCase # :nodoc:
|
8
8
|
|
9
9
|
def test_vi
|
10
|
-
|
11
|
-
|
12
|
-
Date.civil(2014,
|
13
|
-
|
14
|
-
Date.civil(
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
assert_equal "Tết dương lịch", (Holidays.on(Date.civil(2014, 1, 1), [:vi])[0] || {})[:name]
|
11
|
+
|
12
|
+
assert_equal "Ngày Giải phóng miền Nam, thống nhất đất nước", (Holidays.on(Date.civil(2014, 4, 30), [:vi])[0] || {})[:name]
|
13
|
+
|
14
|
+
assert_equal "Ngày Quốc tế Lao động", (Holidays.on(Date.civil(2014, 5, 1), [:vi])[0] || {})[:name]
|
15
|
+
|
16
|
+
assert_equal "Quốc khánh", (Holidays.on(Date.civil(2014, 9, 2), [:vi])[0] || {})[:name]
|
17
|
+
|
18
|
+
assert_equal "Giỗ tổ Hùng Vương", (Holidays.on(Date.civil(2017, 4, 6), [:vi])[0] || {})[:name]
|
19
|
+
assert_equal "Giỗ tổ Hùng Vương", (Holidays.on(Date.civil(2018, 3, 27), [:vi])[0] || {})[:name]
|
18
20
|
|
19
21
|
end
|
20
22
|
end
|
data/test/defs/test_defs_za.rb
CHANGED
@@ -7,20 +7,29 @@ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
|
7
7
|
class ZaDefinitionTests < Test::Unit::TestCase # :nodoc:
|
8
8
|
|
9
9
|
def test_za
|
10
|
-
|
11
|
-
|
12
|
-
Date.civil(2007,
|
13
|
-
|
14
|
-
Date.civil(2007,4,
|
15
|
-
|
16
|
-
Date.civil(2007,
|
17
|
-
|
18
|
-
Date.civil(2007,
|
19
|
-
|
20
|
-
Date.civil(2007,
|
21
|
-
|
22
|
-
|
23
|
-
|
10
|
+
assert_equal "New Year's Day", (Holidays.on(Date.civil(2007, 1, 1), [:za], [:informal])[0] || {})[:name]
|
11
|
+
|
12
|
+
assert_equal "Human Rights Day", (Holidays.on(Date.civil(2007, 3, 21), [:za], [:informal])[0] || {})[:name]
|
13
|
+
|
14
|
+
assert_equal "Good Friday", (Holidays.on(Date.civil(2007, 4, 6), [:za], [:informal])[0] || {})[:name]
|
15
|
+
|
16
|
+
assert_equal "Family Day", (Holidays.on(Date.civil(2007, 4, 9), [:za], [:informal])[0] || {})[:name]
|
17
|
+
|
18
|
+
assert_equal "Freedom Day", (Holidays.on(Date.civil(2007, 4, 27), [:za], [:informal])[0] || {})[:name]
|
19
|
+
|
20
|
+
assert_equal "Workers Day", (Holidays.on(Date.civil(2007, 5, 1), [:za], [:informal])[0] || {})[:name]
|
21
|
+
|
22
|
+
assert_equal "Youth Day", (Holidays.on(Date.civil(2007, 6, 16), [:za], [:informal])[0] || {})[:name]
|
23
|
+
|
24
|
+
assert_equal "National Women's Day", (Holidays.on(Date.civil(2007, 8, 9), [:za], [:informal])[0] || {})[:name]
|
25
|
+
|
26
|
+
assert_equal "Heritage Day", (Holidays.on(Date.civil(2007, 9, 24), [:za], [:informal])[0] || {})[:name]
|
27
|
+
|
28
|
+
assert_equal "Day of Reconciliation", (Holidays.on(Date.civil(2007, 12, 16), [:za], [:informal])[0] || {})[:name]
|
29
|
+
|
30
|
+
assert_equal "Christmas Day", (Holidays.on(Date.civil(2007, 12, 25), [:za], [:informal])[0] || {})[:name]
|
31
|
+
|
32
|
+
assert_equal "Day of Goodwill", (Holidays.on(Date.civil(2007, 12, 26), [:za], [:informal])[0] || {})[:name]
|
24
33
|
|
25
34
|
end
|
26
35
|
end
|
@@ -14,10 +14,15 @@ class GeneratorTests < Test::Unit::TestCase
|
|
14
14
|
source: "some source",
|
15
15
|
)
|
16
16
|
|
17
|
+
@test_parser = mock()
|
18
|
+
@test_source_generator = mock()
|
19
|
+
|
17
20
|
@generator = Holidays::Definition::Context::Generator.new(
|
18
21
|
@custom_method_parser,
|
19
22
|
@custom_method_source_decorator,
|
20
23
|
@custom_methods_repository,
|
24
|
+
@test_parser,
|
25
|
+
@test_source_generator,
|
21
26
|
)
|
22
27
|
end
|
23
28
|
|
@@ -37,6 +42,8 @@ class GeneratorTests < Test::Unit::TestCase
|
|
37
42
|
files = ['test/data/test_single_custom_holiday_defs.yaml']
|
38
43
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
39
44
|
|
45
|
+
@test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
|
46
|
+
|
40
47
|
regions = @generator.parse_definition_files(files)[0]
|
41
48
|
|
42
49
|
assert_equal [:custom_single_file], regions
|
@@ -46,6 +53,8 @@ class GeneratorTests < Test::Unit::TestCase
|
|
46
53
|
files = ['test/data/test_single_custom_holiday_defs.yaml']
|
47
54
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
48
55
|
|
56
|
+
@test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
|
57
|
+
|
49
58
|
rules_by_month = @generator.parse_definition_files(files)[1]
|
50
59
|
|
51
60
|
expected_rules_by_month = {
|
@@ -65,6 +74,8 @@ class GeneratorTests < Test::Unit::TestCase
|
|
65
74
|
files = ['test/data/test_single_custom_holiday_defs.yaml']
|
66
75
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
67
76
|
|
77
|
+
@test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
|
78
|
+
|
68
79
|
custom_methods = @generator.parse_definition_files(files)[2]
|
69
80
|
|
70
81
|
expected_custom_methods = {}
|
@@ -75,19 +86,21 @@ class GeneratorTests < Test::Unit::TestCase
|
|
75
86
|
files = ['test/data/test_single_custom_holiday_defs.yaml']
|
76
87
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
77
88
|
|
78
|
-
|
89
|
+
@test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
|
79
90
|
|
80
|
-
|
81
|
-
"{Date.civil(2013,6,20) => 'Company Founding'}.each do |date, name|\n assert_equal name, (Holidays.on(date, :custom_single_file)[0] || {})[:name]\nend"
|
82
|
-
]]
|
91
|
+
parsed_tests = @generator.parse_definition_files(files)[3]
|
83
92
|
|
84
|
-
assert_equal
|
93
|
+
assert_equal ["parsed tests"], parsed_tests
|
85
94
|
end
|
86
95
|
|
87
96
|
def test_generate_definition_source_correctly_generate_module_src
|
88
97
|
files = ['test/data/test_single_custom_holiday_defs.yaml']
|
89
98
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
90
99
|
|
100
|
+
@test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
|
101
|
+
|
102
|
+
@test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_defs.yaml'], ['parsed tests']).returns("test source")
|
103
|
+
|
91
104
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
92
105
|
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
93
106
|
|
@@ -100,18 +113,22 @@ class GeneratorTests < Test::Unit::TestCase
|
|
100
113
|
files = ['test/data/test_single_custom_holiday_defs.yaml']
|
101
114
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
102
115
|
|
116
|
+
@test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}]).returns(['parsed tests'])
|
117
|
+
|
118
|
+
@test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_defs.yaml'], ['parsed tests']).returns("test source")
|
119
|
+
|
103
120
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
104
121
|
test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[1]
|
105
122
|
|
106
|
-
|
107
|
-
|
108
|
-
assert_equal expected_test_src, test_src
|
123
|
+
assert_equal 'test source', test_src
|
109
124
|
end
|
110
125
|
|
111
126
|
def test_parse_definitions_files_correctly_parse_year_range_by_month
|
112
127
|
files = ['test/data/test_custom_year_range_holiday_defs.yaml']
|
113
128
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
114
129
|
|
130
|
+
@test_parser.expects(:call).with([{'given' => {'date' => '2017-01-01', 'regions' => ['custom_year_range_file']}, 'expect' => {'name' => 'after_year'}}]).returns(['parsed tests'])
|
131
|
+
|
115
132
|
rules_by_month = @generator.parse_definition_files(files)[1]
|
116
133
|
|
117
134
|
expected_rules_by_month = {
|
@@ -156,6 +173,10 @@ class GeneratorTests < Test::Unit::TestCase
|
|
156
173
|
files = ['test/data/test_custom_year_range_holiday_defs.yaml']
|
157
174
|
@custom_method_parser.expects(:call).with(nil).returns({})
|
158
175
|
|
176
|
+
@test_parser.expects(:call).with([{'given' => {'date' => '2017-01-01', 'regions' => ['custom_year_range_file']}, 'expect' => {'name' => 'after_year'}}]).returns(['parsed tests'])
|
177
|
+
|
178
|
+
@test_source_generator.expects(:call).with('test', ['test/data/test_custom_year_range_holiday_defs.yaml'], ['parsed tests']).returns('test source')
|
179
|
+
|
159
180
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
160
181
|
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
161
182
|
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"
|
@@ -170,6 +191,10 @@ class GeneratorTests < Test::Unit::TestCase
|
|
170
191
|
@custom_methods_repository.expects(:find).twice.with('custom_method(year, month)').returns(nil)
|
171
192
|
@custom_method_source_decorator.expects(:call).once.with(@parsed_custom_method).returns("\"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n}")
|
172
193
|
|
194
|
+
@test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}, {'given' => {'date' => '2015-01-01', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Custom Holiday'}}]).returns(['parsed tests'])
|
195
|
+
|
196
|
+
@test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_with_custom_procs.yaml'], ['parsed tests']).returns('test source')
|
197
|
+
|
173
198
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
174
199
|
module_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[0]
|
175
200
|
|
@@ -181,16 +206,18 @@ class GeneratorTests < Test::Unit::TestCase
|
|
181
206
|
def test_generate_definition_source_correctly_generate_test_src_with_custom_methods
|
182
207
|
files = ['test/data/test_single_custom_holiday_with_custom_procs.yaml']
|
183
208
|
|
184
|
-
@custom_method_parser.expects(:call).with('custom_method' => {'arguments' => 'year, month', 'source' => "d = Date.civil(year, month, 1)\nd + 2\n"}).returns({
|
209
|
+
@custom_method_parser.expects(:call).with('custom_method' => {'arguments' => 'year, month', 'source' => "d = Date.civil(year, month, 1)\nd + 2\n"}).returns({"custom_method(year, month)" => @parsed_custom_method})
|
185
210
|
@custom_methods_repository.expects(:find).twice.with('custom_method(year, month)').returns(nil)
|
186
|
-
@custom_method_source_decorator.expects(:call).once.with(
|
211
|
+
@custom_method_source_decorator.expects(:call).once.with(@parsed_custom_method).returns("\"custom_method(year, month)\" => Proc.new { |year, month|\nsource_stuff\n}")
|
212
|
+
|
213
|
+
@test_parser.expects(:call).with([{'given' => {'date' => '2013-06-20', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Company Founding'}}, {'given' => {'date' => '2015-01-01', 'regions' => ['custom_single_file']}, 'expect' => {'name' => 'Custom Holiday'}}]).returns(['parsed tests'])
|
214
|
+
|
215
|
+
@test_source_generator.expects(:call).with('test', ['test/data/test_single_custom_holiday_with_custom_procs.yaml'], ['parsed tests']).returns('test source')
|
187
216
|
|
188
217
|
regions, rules_by_month, custom_methods, tests = @generator.parse_definition_files(files)
|
189
218
|
test_src = @generator.generate_definition_source("test", files, regions, rules_by_month, custom_methods, tests)[1]
|
190
219
|
|
191
|
-
|
192
|
-
|
193
|
-
assert_equal expected_test_src, test_src
|
220
|
+
assert_equal 'test source', test_src
|
194
221
|
end
|
195
222
|
|
196
223
|
#TODO Missing test scenarios. Adding here so I don't forget when I split this
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# Heh at this file name
|
2
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
3
|
+
|
4
|
+
require 'holidays/definition/decorator/test'
|
5
|
+
require 'holidays/definition/entity/test'
|
6
|
+
|
7
|
+
class DecoratorTestTests < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@decorator = Holidays::Definition::Decorator::Test.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_call_generates_source_from_entity_single_date
|
13
|
+
entity = Holidays::Definition::Entity::Test.new(
|
14
|
+
:dates => [DateTime.parse('2016-01-01')],
|
15
|
+
:regions => [:us],
|
16
|
+
:name => 'Test Holiday',
|
17
|
+
:holiday? => true,
|
18
|
+
)
|
19
|
+
|
20
|
+
source = @decorator.call(entity)
|
21
|
+
expected_source = "assert_equal \"Test Holiday\", (Holidays.on(Date.civil(2016, 1, 1), [:us])[0] || {})[:name]\n"
|
22
|
+
|
23
|
+
assert_equal expected_source, source
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_call_generates_source_from_entity_multiple_dates
|
27
|
+
entity = Holidays::Definition::Entity::Test.new(
|
28
|
+
:dates => [DateTime.parse('2016-01-01'), DateTime.parse('2017-01-01')],
|
29
|
+
:regions => [:us],
|
30
|
+
:name => 'Test Holiday',
|
31
|
+
:holiday? => true
|
32
|
+
)
|
33
|
+
|
34
|
+
source = @decorator.call(entity)
|
35
|
+
expected_source = "assert_equal \"Test Holiday\", (Holidays.on(Date.civil(2016, 1, 1), [:us])[0] || {})[:name]\nassert_equal \"Test Holiday\", (Holidays.on(Date.civil(2017, 1, 1), [:us])[0] || {})[:name]\n"
|
36
|
+
|
37
|
+
assert_equal expected_source, source
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_call_generates_source_from_entity_single_date_with_options
|
41
|
+
entity = Holidays::Definition::Entity::Test.new(
|
42
|
+
:dates => [DateTime.parse('2016-01-01')],
|
43
|
+
:regions => [:us],
|
44
|
+
:options => ['option1'],
|
45
|
+
:name => 'Test Holiday',
|
46
|
+
:holiday? => true,
|
47
|
+
)
|
48
|
+
|
49
|
+
source = @decorator.call(entity)
|
50
|
+
expected_source = "assert_equal \"Test Holiday\", (Holidays.on(Date.civil(2016, 1, 1), [:us], [:option1])[0] || {})[:name]\n"
|
51
|
+
|
52
|
+
assert_equal expected_source, source
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_call_generates_source_from_entity_single_date_with_holiday_flag
|
56
|
+
entity = Holidays::Definition::Entity::Test.new(
|
57
|
+
:dates => [DateTime.parse('2016-01-01')],
|
58
|
+
:regions => [:us],
|
59
|
+
:holiday? => false,
|
60
|
+
)
|
61
|
+
|
62
|
+
source = @decorator.call(entity)
|
63
|
+
expected_source = "assert_nil (Holidays.on(Date.civil(2016, 1, 1), [:us])[0] || {})[:name]\n"
|
64
|
+
|
65
|
+
assert_equal expected_source, source
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_call_generates_source_from_entity_single_date_multiple_regions
|
69
|
+
entity = Holidays::Definition::Entity::Test.new(
|
70
|
+
:dates => [DateTime.parse('2016-01-01')],
|
71
|
+
:regions => [:us, :us_ca, :ca],
|
72
|
+
:name => 'Test Holiday',
|
73
|
+
:holiday? => true,
|
74
|
+
)
|
75
|
+
|
76
|
+
source = @decorator.call(entity)
|
77
|
+
expected_source = "assert_equal \"Test Holiday\", (Holidays.on(Date.civil(2016, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\n"
|
78
|
+
|
79
|
+
assert_equal expected_source, source
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_call_generates_source_from_entity_multiple_dates_multiple_regions
|
83
|
+
entity = Holidays::Definition::Entity::Test.new(
|
84
|
+
:dates => [DateTime.parse('2016-01-01'), DateTime.parse('2017-01-01')],
|
85
|
+
:regions => [:us, :us_ca, :ca],
|
86
|
+
:name => 'Test Holiday',
|
87
|
+
:holiday? => true,
|
88
|
+
)
|
89
|
+
|
90
|
+
source = @decorator.call(entity)
|
91
|
+
expected_source = "assert_equal \"Test Holiday\", (Holidays.on(Date.civil(2016, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\nassert_equal \"Test Holiday\", (Holidays.on(Date.civil(2017, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\n"
|
92
|
+
|
93
|
+
assert_equal expected_source, source
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_call_generates_source_from_entity_multiple_dates_multiple_regions_holiday_flag_false
|
97
|
+
entity = Holidays::Definition::Entity::Test.new(
|
98
|
+
:dates => [DateTime.parse('2016-01-01'), DateTime.parse('2017-01-01')],
|
99
|
+
:regions => [:us, :us_ca, :ca],
|
100
|
+
:name => 'Test Holiday',
|
101
|
+
:holiday? => false,
|
102
|
+
)
|
103
|
+
|
104
|
+
source = @decorator.call(entity)
|
105
|
+
expected_source = "assert_nil (Holidays.on(Date.civil(2016, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\nassert_nil (Holidays.on(Date.civil(2017, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\n"
|
106
|
+
|
107
|
+
assert_equal expected_source, source
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_call_generates_source_from_entity_single_date_multiple_regions_holiday_flag_false
|
111
|
+
entity = Holidays::Definition::Entity::Test.new(
|
112
|
+
:dates => [DateTime.parse('2016-01-01')],
|
113
|
+
:regions => [:us, :us_ca, :ca],
|
114
|
+
:name => 'Test Holiday',
|
115
|
+
:holiday? => false,
|
116
|
+
)
|
117
|
+
|
118
|
+
source = @decorator.call(entity)
|
119
|
+
expected_source = "assert_nil (Holidays.on(Date.civil(2016, 1, 1), [:us, :us_ca, :ca])[0] || {})[:name]\n"
|
120
|
+
|
121
|
+
assert_equal expected_source, source
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# Heh at this file name
|
2
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
3
|
+
|
4
|
+
require 'holidays/definition/generator/test'
|
5
|
+
require 'holidays/definition/entity/test'
|
6
|
+
|
7
|
+
class TestGeneratorTests < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@module_name = "Test"
|
10
|
+
@files = ["file1.rb"]
|
11
|
+
@tests = [
|
12
|
+
Holidays::Definition::Entity::Test.new(
|
13
|
+
:dates => [DateTime.parse("2016-01-01")],
|
14
|
+
:regions => [:test],
|
15
|
+
:name => "Test Holiday",
|
16
|
+
),
|
17
|
+
]
|
18
|
+
|
19
|
+
@decorator = mock()
|
20
|
+
|
21
|
+
@generator = Holidays::Definition::Generator::Test.new(@decorator)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_generate_tests_raises_error_if_module_name_is_invalid
|
25
|
+
assert_raises ArgumentError do
|
26
|
+
@generator.call(nil, @files, @tests)
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_raises ArgumentError do
|
30
|
+
@generator.call("", @files, @tests)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_generate_tests_raises_error_if_files_is_invalid
|
35
|
+
assert_raises ArgumentError do
|
36
|
+
@generator.call(@module_name, nil, @tests)
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_raises ArgumentError do
|
40
|
+
@generator.call(@module_name, "", @tests)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_generate_tests_raises_error_if_tests_are_missing
|
45
|
+
assert_raises ArgumentError do
|
46
|
+
@generator.call(@module_name, @files, nil)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_generate_source_from_single_test
|
51
|
+
@decorator.expects(:call).with(@tests.first).returns("test")
|
52
|
+
|
53
|
+
expected = <<-EOT
|
54
|
+
# encoding: utf-8
|
55
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
56
|
+
|
57
|
+
# This file is generated by the Ruby Holiday gem.
|
58
|
+
#
|
59
|
+
# Definitions loaded: #{@files.join(', ')}
|
60
|
+
class #{@module_name.to_s.capitalize}DefinitionTests < Test::Unit::TestCase # :nodoc:
|
61
|
+
|
62
|
+
def test_#{@module_name.to_s.downcase}
|
63
|
+
test
|
64
|
+
end
|
65
|
+
end
|
66
|
+
EOT
|
67
|
+
|
68
|
+
assert_equal(expected, @generator.call(@module_name, @files, @tests))
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_generate_source_from_multiple_tests
|
72
|
+
@tests = [
|
73
|
+
Holidays::Definition::Entity::Test.new(
|
74
|
+
:dates => [DateTime.parse("2016-01-01")],
|
75
|
+
:regions => [:test],
|
76
|
+
:name => "Test Holiday",
|
77
|
+
),
|
78
|
+
Holidays::Definition::Entity::Test.new(
|
79
|
+
:dates => [DateTime.parse("2016-02-01")],
|
80
|
+
:regions => [:test2],
|
81
|
+
:name => "Test Holiday2",
|
82
|
+
),
|
83
|
+
Holidays::Definition::Entity::Test.new(
|
84
|
+
:dates => [DateTime.parse("2016-03-01")],
|
85
|
+
:regions => [:test3],
|
86
|
+
:name => "Test Holiday3",
|
87
|
+
),
|
88
|
+
]
|
89
|
+
|
90
|
+
@decorator.expects(:call).with(@tests[0]).returns("test")
|
91
|
+
@decorator.expects(:call).with(@tests[1]).returns("test2")
|
92
|
+
@decorator.expects(:call).with(@tests[2]).returns("test3")
|
93
|
+
|
94
|
+
expected = <<-EOT
|
95
|
+
# encoding: utf-8
|
96
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
|
97
|
+
|
98
|
+
# This file is generated by the Ruby Holiday gem.
|
99
|
+
#
|
100
|
+
# Definitions loaded: #{@files.join(', ')}
|
101
|
+
class #{@module_name.to_s.capitalize}DefinitionTests < Test::Unit::TestCase # :nodoc:
|
102
|
+
|
103
|
+
def test_#{@module_name.to_s.downcase}
|
104
|
+
test
|
105
|
+
test2
|
106
|
+
test3
|
107
|
+
end
|
108
|
+
end
|
109
|
+
EOT
|
110
|
+
|
111
|
+
assert_equal(expected, @generator.call(@module_name, @files, @tests))
|
112
|
+
end
|
113
|
+
end
|