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,96 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
2
|
-
|
|
3
|
-
require 'holidays/definition/decorator/custom_method_source'
|
|
4
|
-
require 'holidays/definition/entity/custom_method'
|
|
5
|
-
|
|
6
|
-
class DecoratorCustomMethodSourceTests < Test::Unit::TestCase
|
|
7
|
-
def setup
|
|
8
|
-
@decorator = Holidays::Definition::Decorator::CustomMethodSource.new
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def test_call_generates_source_from_entity
|
|
12
|
-
entity = Holidays::Definition::Entity::CustomMethod.new(
|
|
13
|
-
name: "test",
|
|
14
|
-
arguments: ["year"],
|
|
15
|
-
source: "Date.civil(year, 1, 1)"
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
source = @decorator.call(entity)
|
|
19
|
-
expected_source = "\"#{entity.name}(#{entity.arguments[0]})\" => Proc.new { |year|\n#{entity.source}}"
|
|
20
|
-
|
|
21
|
-
assert_equal expected_source, source
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def test_call_generates_source_from_entity_with_multiple_arguments
|
|
25
|
-
entity = Holidays::Definition::Entity::CustomMethod.new(
|
|
26
|
-
name: "test",
|
|
27
|
-
arguments: ["year", "month"],
|
|
28
|
-
source: "Date.civil(year, month, 1)"
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
source = @decorator.call(entity)
|
|
32
|
-
expected_args = "#{entity.arguments[0]}, #{entity.arguments[1]}"
|
|
33
|
-
|
|
34
|
-
expected_source = "\"#{entity.name}(#{expected_args})\" => Proc.new { |#{expected_args}|\n#{entity.source}}"
|
|
35
|
-
|
|
36
|
-
assert_equal expected_source, source
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_call_generates_source_from_entity_when_source_is_multiple_lines
|
|
40
|
-
entity = Holidays::Definition::Entity::CustomMethod.new(
|
|
41
|
-
name: "test",
|
|
42
|
-
arguments: ["year"],
|
|
43
|
-
source: "d = Date.civil(year, 1, 1)\nd + 2"
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
source = @decorator.call(entity)
|
|
47
|
-
expected_source = "\"#{entity.name}(#{entity.arguments[0]})\" => Proc.new { |year|\n#{entity.source}}"
|
|
48
|
-
|
|
49
|
-
assert_equal expected_source, source
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def test_call_raises_error_if_missing_name
|
|
53
|
-
entity = Holidays::Definition::Entity::CustomMethod.new(
|
|
54
|
-
arguments: ["year", "month"],
|
|
55
|
-
source: "Date.civil(year, month, 1)"
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
assert_raises ArgumentError do
|
|
59
|
-
@decorator.call(entity)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def test_call_raises_error_if_missing_arguments
|
|
64
|
-
entity = Holidays::Definition::Entity::CustomMethod.new(
|
|
65
|
-
name: "test",
|
|
66
|
-
source: "Date.civil(year, month, 1)"
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
assert_raises ArgumentError do
|
|
70
|
-
@decorator.call(entity)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def test_call_raises_error_if_arguments_is_not_an_array
|
|
75
|
-
entity = Holidays::Definition::Entity::CustomMethod.new(
|
|
76
|
-
name: "test",
|
|
77
|
-
arguments: "test",
|
|
78
|
-
source: "Date.civil(year, month, 1)"
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
assert_raises ArgumentError do
|
|
82
|
-
@decorator.call(entity)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def test_call_raises_error_if_missing_source
|
|
87
|
-
entity = Holidays::Definition::Entity::CustomMethod.new(
|
|
88
|
-
name: "test",
|
|
89
|
-
arguments: ["year", "month"],
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
assert_raises ArgumentError do
|
|
93
|
-
@decorator.call(entity)
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
@@ -1,123 +0,0 @@
|
|
|
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
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
2
|
-
|
|
3
|
-
require 'holidays/definition/generator/module'
|
|
4
|
-
|
|
5
|
-
class GeneratorModuleTests < Test::Unit::TestCase
|
|
6
|
-
def setup
|
|
7
|
-
@generator = Holidays::Definition::Generator::Module.new
|
|
8
|
-
|
|
9
|
-
@module_name = "TEST"
|
|
10
|
-
@files = ["file1.rb", "file2.rb"]
|
|
11
|
-
@regions = [:test, :test2]
|
|
12
|
-
@month_strings = ["first-string", "second-string"]
|
|
13
|
-
@custom_methods = "custom-methods"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def subject
|
|
17
|
-
@generator.call(
|
|
18
|
-
@module_name,
|
|
19
|
-
@files,
|
|
20
|
-
@regions,
|
|
21
|
-
@month_strings,
|
|
22
|
-
@custom_methods,
|
|
23
|
-
)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def test_generates_source
|
|
27
|
-
expected = <<-EOF
|
|
28
|
-
# encoding: utf-8
|
|
29
|
-
module Holidays
|
|
30
|
-
# This file is generated by the Ruby Holidays gem.
|
|
31
|
-
#
|
|
32
|
-
# Definitions loaded: file1.rb, file2.rb
|
|
33
|
-
#
|
|
34
|
-
# All the definitions are available at https://github.com/holidays/holidays
|
|
35
|
-
module TEST # :nodoc:
|
|
36
|
-
def self.defined_regions
|
|
37
|
-
[:test, :test2]
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def self.holidays_by_month
|
|
41
|
-
{
|
|
42
|
-
first-string,
|
|
43
|
-
second-string
|
|
44
|
-
}
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def self.custom_methods
|
|
48
|
-
{
|
|
49
|
-
custom-methods
|
|
50
|
-
}
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
EOF
|
|
55
|
-
|
|
56
|
-
assert_equal expected, subject
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def test_module_name_more_than_one_word
|
|
60
|
-
@module_name = "TESTWITHHYPHEN"
|
|
61
|
-
|
|
62
|
-
expected = <<-EOF
|
|
63
|
-
# encoding: utf-8
|
|
64
|
-
module Holidays
|
|
65
|
-
# This file is generated by the Ruby Holidays gem.
|
|
66
|
-
#
|
|
67
|
-
# Definitions loaded: file1.rb, file2.rb
|
|
68
|
-
#
|
|
69
|
-
# All the definitions are available at https://github.com/holidays/holidays
|
|
70
|
-
module TESTWITHHYPHEN # :nodoc:
|
|
71
|
-
def self.defined_regions
|
|
72
|
-
[:test, :test2]
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def self.holidays_by_month
|
|
76
|
-
{
|
|
77
|
-
first-string,
|
|
78
|
-
second-string
|
|
79
|
-
}
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def self.custom_methods
|
|
83
|
-
{
|
|
84
|
-
custom-methods
|
|
85
|
-
}
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
EOF
|
|
90
|
-
|
|
91
|
-
assert_equal expected, subject
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def test_generates_source_with_blank_custom_methods
|
|
95
|
-
@custom_methods = ""
|
|
96
|
-
|
|
97
|
-
expected = <<-EOF
|
|
98
|
-
# encoding: utf-8
|
|
99
|
-
module Holidays
|
|
100
|
-
# This file is generated by the Ruby Holidays gem.
|
|
101
|
-
#
|
|
102
|
-
# Definitions loaded: file1.rb, file2.rb
|
|
103
|
-
#
|
|
104
|
-
# All the definitions are available at https://github.com/holidays/holidays
|
|
105
|
-
module TEST # :nodoc:
|
|
106
|
-
def self.defined_regions
|
|
107
|
-
[:test, :test2]
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def self.holidays_by_month
|
|
111
|
-
{
|
|
112
|
-
first-string,
|
|
113
|
-
second-string
|
|
114
|
-
}
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def self.custom_methods
|
|
118
|
-
{
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
EOF
|
|
125
|
-
|
|
126
|
-
assert_equal expected, subject
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def test_generates_source_with_nil_custom_methods
|
|
130
|
-
@custom_methods = nil
|
|
131
|
-
|
|
132
|
-
expected = <<-EOF
|
|
133
|
-
# encoding: utf-8
|
|
134
|
-
module Holidays
|
|
135
|
-
# This file is generated by the Ruby Holidays gem.
|
|
136
|
-
#
|
|
137
|
-
# Definitions loaded: file1.rb, file2.rb
|
|
138
|
-
#
|
|
139
|
-
# All the definitions are available at https://github.com/holidays/holidays
|
|
140
|
-
module TEST # :nodoc:
|
|
141
|
-
def self.defined_regions
|
|
142
|
-
[:test, :test2]
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def self.holidays_by_month
|
|
146
|
-
{
|
|
147
|
-
first-string,
|
|
148
|
-
second-string
|
|
149
|
-
}
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def self.custom_methods
|
|
153
|
-
{
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
EOF
|
|
160
|
-
|
|
161
|
-
assert_equal expected, subject
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def test_generates_source_with_symbol_module_name
|
|
165
|
-
@module_name = :test
|
|
166
|
-
|
|
167
|
-
expected = <<-EOF
|
|
168
|
-
# encoding: utf-8
|
|
169
|
-
module Holidays
|
|
170
|
-
# This file is generated by the Ruby Holidays gem.
|
|
171
|
-
#
|
|
172
|
-
# Definitions loaded: file1.rb, file2.rb
|
|
173
|
-
#
|
|
174
|
-
# All the definitions are available at https://github.com/holidays/holidays
|
|
175
|
-
module TEST # :nodoc:
|
|
176
|
-
def self.defined_regions
|
|
177
|
-
[:test, :test2]
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
def self.holidays_by_month
|
|
181
|
-
{
|
|
182
|
-
first-string,
|
|
183
|
-
second-string
|
|
184
|
-
}
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
def self.custom_methods
|
|
188
|
-
{
|
|
189
|
-
custom-methods
|
|
190
|
-
}
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
EOF
|
|
195
|
-
|
|
196
|
-
assert_equal expected, subject
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
def test_raise_error_if_module_name_is_blank
|
|
200
|
-
@module_name = ""
|
|
201
|
-
assert_raises ArgumentError do
|
|
202
|
-
subject
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
def test_raise_error_if_module_name_is_nil
|
|
207
|
-
@module_name = nil
|
|
208
|
-
assert_raises ArgumentError do
|
|
209
|
-
subject
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
def test_raise_error_if_files_are_empty
|
|
214
|
-
@files = []
|
|
215
|
-
|
|
216
|
-
assert_raises ArgumentError do
|
|
217
|
-
subject
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
def test_raise_error_if_files_are_not_all_strings
|
|
222
|
-
@files = [:test, 1]
|
|
223
|
-
|
|
224
|
-
assert_raises ArgumentError do
|
|
225
|
-
subject
|
|
226
|
-
end
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
def test_raise_error_if_files_is_nil
|
|
230
|
-
@files = nil
|
|
231
|
-
|
|
232
|
-
assert_raises ArgumentError do
|
|
233
|
-
subject
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
def test_raise_error_if_regions_are_empty
|
|
238
|
-
@regions = []
|
|
239
|
-
|
|
240
|
-
assert_raises ArgumentError do
|
|
241
|
-
subject
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
def test_raise_error_if_regions_is_nil
|
|
246
|
-
@regions = nil
|
|
247
|
-
|
|
248
|
-
assert_raises ArgumentError do
|
|
249
|
-
subject
|
|
250
|
-
end
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
def test_raise_error_if_month_strings_are_empty
|
|
254
|
-
@month_strings = []
|
|
255
|
-
|
|
256
|
-
assert_raises ArgumentError do
|
|
257
|
-
subject
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
|
|
261
|
-
def test_raise_error_if_month_strings_is_nil
|
|
262
|
-
@month_strings = nil
|
|
263
|
-
|
|
264
|
-
assert_raises ArgumentError do
|
|
265
|
-
subject
|
|
266
|
-
end
|
|
267
|
-
end
|
|
268
|
-
end
|
|
@@ -1,97 +0,0 @@
|
|
|
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
|
|
@@ -1,113 +0,0 @@
|
|
|
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
|