holidays 5.4.0 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/Makefile +1 -1
  4. data/README.md +6 -6
  5. data/Rakefile +7 -8
  6. data/lib/generated_definitions/REGIONS.rb +3 -1
  7. data/lib/generated_definitions/ar.rb +0 -6
  8. data/lib/generated_definitions/at.rb +0 -6
  9. data/lib/generated_definitions/au.rb +6 -9
  10. data/lib/generated_definitions/be_fr.rb +0 -6
  11. data/lib/generated_definitions/be_nl.rb +0 -6
  12. data/lib/generated_definitions/bg.rb +0 -6
  13. data/lib/generated_definitions/br.rb +0 -6
  14. data/lib/generated_definitions/ca.rb +0 -6
  15. data/lib/generated_definitions/ch.rb +0 -6
  16. data/lib/generated_definitions/cl.rb +0 -6
  17. data/lib/generated_definitions/cr.rb +0 -6
  18. data/lib/generated_definitions/cz.rb +0 -6
  19. data/lib/generated_definitions/de.rb +0 -6
  20. data/lib/generated_definitions/dk.rb +0 -6
  21. data/lib/generated_definitions/ecb_target.rb +0 -6
  22. data/lib/generated_definitions/el.rb +0 -6
  23. data/lib/generated_definitions/es.rb +0 -6
  24. data/lib/generated_definitions/europe.rb +0 -6
  25. data/lib/generated_definitions/federal_reserve.rb +0 -6
  26. data/lib/generated_definitions/fedex.rb +0 -6
  27. data/lib/generated_definitions/fi.rb +0 -6
  28. data/lib/generated_definitions/fr.rb +0 -6
  29. data/lib/generated_definitions/gb.rb +0 -6
  30. data/lib/generated_definitions/hk.rb +0 -6
  31. data/lib/generated_definitions/hr.rb +0 -6
  32. data/lib/generated_definitions/hu.rb +0 -6
  33. data/lib/generated_definitions/ie.rb +0 -6
  34. data/lib/generated_definitions/is.rb +0 -6
  35. data/lib/generated_definitions/it.rb +0 -6
  36. data/lib/generated_definitions/jp.rb +0 -6
  37. data/lib/generated_definitions/kr.rb +15 -225
  38. data/lib/generated_definitions/li.rb +0 -6
  39. data/lib/generated_definitions/lt.rb +0 -6
  40. data/lib/generated_definitions/lu.rb +0 -6
  41. data/lib/generated_definitions/ma.rb +0 -6
  42. data/lib/generated_definitions/mx.rb +0 -6
  43. data/lib/generated_definitions/my.rb +0 -6
  44. data/lib/generated_definitions/nerc.rb +0 -6
  45. data/lib/generated_definitions/nl.rb +0 -6
  46. data/lib/generated_definitions/no.rb +0 -6
  47. data/lib/generated_definitions/north_america.rb +0 -6
  48. data/lib/generated_definitions/nyse.rb +1 -7
  49. data/lib/generated_definitions/nz.rb +0 -6
  50. data/lib/generated_definitions/pe.rb +0 -6
  51. data/lib/generated_definitions/ph.rb +0 -6
  52. data/lib/generated_definitions/pl.rb +0 -6
  53. data/lib/generated_definitions/pt.rb +0 -6
  54. data/lib/generated_definitions/ro.rb +0 -6
  55. data/lib/generated_definitions/scandinavia.rb +0 -6
  56. data/lib/generated_definitions/se.rb +0 -6
  57. data/lib/generated_definitions/sg.rb +0 -6
  58. data/lib/generated_definitions/si.rb +0 -6
  59. data/lib/generated_definitions/sk.rb +0 -6
  60. data/lib/generated_definitions/tn.rb +0 -6
  61. data/lib/generated_definitions/united_nations.rb +0 -6
  62. data/lib/generated_definitions/ups.rb +0 -6
  63. data/lib/generated_definitions/us.rb +0 -6
  64. data/lib/generated_definitions/ve.rb +0 -6
  65. data/lib/generated_definitions/vi.rb +5 -10
  66. data/lib/generated_definitions/za.rb +0 -6
  67. data/lib/holidays.rb +0 -1
  68. data/lib/holidays/date_calculator/lunar_date.rb +371 -0
  69. data/lib/holidays/definition/context/function_processor.rb +20 -15
  70. data/lib/holidays/definition/context/generator.rb +0 -6
  71. data/lib/holidays/definition/context/load.rb +29 -0
  72. data/lib/holidays/definition/context/merger.rb +0 -4
  73. data/lib/holidays/definition/generator/regions.rb +50 -0
  74. data/lib/holidays/definition/repository/cache.rb +20 -7
  75. data/lib/holidays/definition/repository/proc_result_cache.rb +1 -1
  76. data/lib/holidays/definition/repository/regions.rb +23 -13
  77. data/lib/holidays/definition/validator/custom_method.rb +1 -1
  78. data/lib/holidays/definition/validator/region.rb +2 -9
  79. data/lib/holidays/factory/date_calculator.rb +5 -0
  80. data/lib/holidays/factory/definition.rb +17 -1
  81. data/lib/holidays/factory/finder.rb +1 -1
  82. data/lib/holidays/finder/context/between.rb +3 -0
  83. data/lib/holidays/finder/context/parse_options.rb +53 -52
  84. data/lib/holidays/finder/context/search.rb +23 -6
  85. data/lib/holidays/finder/rules/in_region.rb +1 -1
  86. data/lib/holidays/load_all_definitions.rb +9 -0
  87. data/lib/holidays/version.rb +1 -1
  88. data/test/data/test_invalid_region.rb +15 -0
  89. data/test/data/test_region.rb +15 -0
  90. data/test/defs/test_defs_au.rb +11 -1
  91. data/test/defs/test_defs_kr.rb +15 -12
  92. data/test/defs/test_defs_nyse.rb +5 -0
  93. data/test/defs/test_defs_vi.rb +6 -4
  94. data/test/holidays/date_calculator/test_lunar_date.rb +89 -0
  95. data/test/holidays/definition/context/test_function_processor.rb +47 -23
  96. data/test/holidays/definition/context/test_generator.rb +3 -3
  97. data/test/holidays/definition/context/test_load.rb +37 -0
  98. data/test/holidays/definition/generator/test_regions.rb +97 -0
  99. data/test/holidays/definition/repository/test_cache.rb +47 -6
  100. data/test/holidays/definition/repository/test_proc_result_cache.rb +7 -0
  101. data/test/holidays/definition/repository/test_regions.rb +31 -13
  102. data/test/holidays/definition/validator/test_custom_method.rb +5 -0
  103. data/test/holidays/definition/validator/test_region.rb +7 -12
  104. data/test/holidays/factory/test_date_calculator.rb +5 -0
  105. data/test/holidays/factory/test_definition.rb +9 -0
  106. data/test/holidays/finder/context/test_parse_options.rb +102 -33
  107. data/test/holidays/finder/context/test_search.rb +45 -16
  108. data/test/integration/test_available_regions.rb +1 -1
  109. data/test/integration/test_custom_year_range_holidays.rb +0 -1
  110. data/test/integration/test_holidays.rb +3 -3
  111. data/test/integration/test_multiple_regions.rb +0 -1
  112. metadata +16 -3
@@ -24,30 +24,36 @@ module Holidays
24
24
  next unless @rules[:year_range].call(year, h[:year_ranges])
25
25
  end
26
26
 
27
+ current_month = month
28
+ current_day = h[:mday]
29
+
27
30
  if h[:function]
28
31
  result = @custom_method_processor.call(
29
- year, month, h[:mday],
32
+ build_custom_method_input(year, current_month, current_day, h[:regions]),
30
33
  h[:function], h[:function_arguments], h[:function_modifier],
31
34
  )
32
35
 
33
36
  #FIXME The result should always be present, see https://github.com/holidays/holidays/issues/204 for more information
34
37
  if result
35
- month = result.month
36
- mday = result.mday
38
+ current_month = result.month
39
+ current_day = result.mday
40
+ else
41
+ current_month = nil
42
+ current_day = nil
37
43
  end
38
44
  else
39
- mday = h[:mday] || @day_of_month_calculator.call(year, month, h[:week], h[:wday])
45
+ current_day = h[:mday] || @day_of_month_calculator.call(year, current_month, h[:week], h[:wday])
40
46
  end
41
47
 
42
48
  # Silently skip bad mdays
43
49
  #TODO Should we be doing something different here? We have no concept of logging right now. Maybe we should add it?
44
50
  begin
45
- date = Date.civil(year, month, mday)
51
+ date = Date.civil(year, current_month, current_day)
46
52
  rescue; next; end
47
53
 
48
54
  if observed_set?(options) && h[:observed]
49
55
  date = @custom_method_processor.call(
50
- date.year, date.month, date.day,
56
+ build_custom_method_input(date.year, date.month, date.day, regions),
51
57
  h[:observed],
52
58
  [:date],
53
59
  )
@@ -64,6 +70,8 @@ module Holidays
64
70
  private
65
71
 
66
72
  def validate!(dates_driver)
73
+ #FIXME This should give some kind of error message that indicates the
74
+ # problem.
67
75
  raise ArgumentError if dates_driver.nil? || dates_driver.empty?
68
76
 
69
77
  dates_driver.each do |year, months|
@@ -80,6 +88,15 @@ module Holidays
80
88
  def observed_set?(options)
81
89
  options && options.include?(:observed) == true
82
90
  end
91
+
92
+ def build_custom_method_input(year, month, day, regions)
93
+ {
94
+ year: year,
95
+ month: month,
96
+ day: day,
97
+ region: regions.first, #FIXME This isn't ideal but will work for our current use case...
98
+ }
99
+ end
83
100
  end
84
101
  end
85
102
  end
@@ -11,7 +11,7 @@ module Holidays
11
11
  requested = requested.collect do |r|
12
12
  if r.to_s =~ /_/
13
13
  chunks = r.to_s.split('_')
14
-
14
+
15
15
  chunks.length.downto(1).map do |num|
16
16
  chunks[0..-num].join('_').to_sym
17
17
  end
@@ -1,4 +1,5 @@
1
1
  module Holidays
2
+ #TODO This file should be renamed. It's no longer about definitions, really.
2
3
  class LoadAllDefinitions
3
4
  class << self
4
5
  def call
@@ -20,9 +21,13 @@ module Holidays
20
21
  "calculate_day_of_month(year, month, day, wday)" => day_of_month_calculator.method(:call).to_proc,
21
22
  "to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday(year)" => weekend_modifier.method(:to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday).to_proc,
22
23
  "to_tuesday_if_sunday_or_monday_if_saturday(date)" => weekend_modifier.method(:to_tuesday_if_sunday_or_monday_if_saturday).to_proc,
24
+ "lunar_to_solar(year, month, day, region)" => lunar_date.method(:to_solar).to_proc,
23
25
  }
24
26
 
25
27
  Factory::Definition.custom_methods_repository.add(global_methods)
28
+
29
+ static_regions_definition = "#{Holidays::DEFINITIONS_PATH}/REGIONS.rb"
30
+ require static_regions_definition
26
31
  end
27
32
 
28
33
  private
@@ -42,6 +47,10 @@ module Holidays
42
47
  def day_of_month_calculator
43
48
  Factory::DateCalculator.day_of_month_calculator
44
49
  end
50
+
51
+ def lunar_date
52
+ Factory::DateCalculator.lunar_date
53
+ end
45
54
  end
46
55
  end
47
56
  end
@@ -1,3 +1,3 @@
1
1
  module Holidays
2
- VERSION = '5.4.0'
2
+ VERSION = '5.5.0'
3
3
  end
@@ -0,0 +1,15 @@
1
+ module Holidays
2
+ module BAD_REGION_NAME
3
+ def self.defined_regions
4
+ [:test_region]
5
+ end
6
+
7
+ def self.holidays_by_month
8
+ {}
9
+ end
10
+
11
+ def self.custom_methods
12
+ {}
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Holidays
2
+ module TEST_REGION
3
+ def self.defined_regions
4
+ [:test_region, :test_region2]
5
+ end
6
+
7
+ def self.holidays_by_month
8
+ {}
9
+ end
10
+
11
+ def self.custom_methods
12
+ {}
13
+ end
14
+ end
15
+ end
@@ -139,10 +139,20 @@ assert_equal "Christmas Day", Date.civil(2016, 12, 27).holidays(:au_vic, :observ
139
139
  assert_equal "Christmas Day", Date.civil(2016, 12, 27).holidays(:au_nt, :observed)[0][:name]
140
140
 
141
141
  # NEW YEAR'S DAY - observed on both 1st and 2nd of Jan for 2017
142
- regions = [:au_qld, :au_nsw, :au_act, :au_vic, :au_tas, :au_sa, :au_wa, :au_nt]
142
+ regions = [:au, :au_qld, :au_nsw, :au_act, :au_vic, :au_sa, :au_wa, :au_nt]
143
143
  regions.each do |r|
144
144
  assert_equal "New Year's Day", Date.civil(2017, 1, 1).holidays(r)[0][:name]
145
145
  assert_equal "New Year's Day", Date.civil(2017, 1, 2).holidays(r, :observed)[0][:name]
146
146
  end
147
+
148
+ # Tasmania is different
149
+ #FIXME This commented test is valid but the current code in the ruby repo won't allow it
150
+ # to work. We need to discuss potential solutions but in the meantime I'm taking it out.
151
+ #assert_equal [], Date.civil(2017,1,1).holidays(:au_tas)
152
+ assert_equal "New Year's Day", Date.civil(2017, 1, 2).holidays(:au_tas)[0][:name]
153
+
154
+ #QLD now celebrates Easter Sunday
155
+ assert_equal "Easter Sunday", Date.civil(2017, 4, 16).holidays(:au_qld)[0][:name]
156
+
147
157
  end
148
158
  end
@@ -7,18 +7,21 @@ require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
7
7
  class KrDefinitionTests < Test::Unit::TestCase # :nodoc:
8
8
 
9
9
  def test_kr
10
- {Date.civil(2016,2,8) => "Korean New Year",
11
- Date.civil(2016,5,14) => "Buddah\'s Birthday",
12
- Date.civil(2016,9,12) => "Korean Thanksgiving",
13
- Date.civil(2016,1,1) => "New Year\'s Day",
14
- Date.civil(2016,3,1) => "Independence Movement Day",
15
- Date.civil(2016,5,5) => "Children\'s Day",
16
- Date.civil(2016,6,6) => "Memorial Day",
17
- Date.civil(2016,7,17) => "Constitution Day",
18
- Date.civil(2016,8,15) => "Liberation Day",
19
- Date.civil(2016,10,3) => "National Foundation Day",
20
- Date.civil(2016,10,9) => "Hangul Day",
21
- Date.civil(2016,12,25) => "Christmas Day"}.each do |date, name|
10
+ {Date.civil(2016,2,8) => "설날",
11
+ Date.civil(2017,1,29) => "설날 연휴",
12
+ Date.civil(2016,5,14) => "석가탄신일",
13
+ Date.civil(2016,9,15) => "추석",
14
+ Date.civil(2016,1,1) => "신정",
15
+ Date.civil(2016,3,1) => "3·1절",
16
+ Date.civil(2016,5,5) => "어린이날",
17
+ Date.civil(2016,6,6) => "현충일",
18
+ Date.civil(2016,7,17) => "제헌절",
19
+ Date.civil(2016,8,15) => "광복절",
20
+ Date.civil(2016,10,3) => "개천절",
21
+ Date.civil(2016,10,9) => "한글날",
22
+ Date.civil(2016,12,25) => "크리스마스",
23
+ Date.civil(2017,1,28) => "설날"
24
+ }.each do |date, name|
22
25
  assert_equal name, (Holidays.on(date, :kr, :informal)[0] || {})[:name]
23
26
  end
24
27
 
@@ -19,5 +19,10 @@ class NyseDefinitionTests < Test::Unit::TestCase # :nodoc:
19
19
  assert_equal name, (Holidays.on(date, :nyse)[0] || {})[:name]
20
20
  end
21
21
 
22
+ # Test observed New Year
23
+ [Date.civil(2017,1,2), Date.civil(2012,1,2), Date.civil(2011,1,1), Date.civil(2006,1,2)].each do |date|
24
+ assert_equal 'New Year\'s Day', (Holidays.on(date, :nyse, :observed)[0] || {})[:name]
25
+ end
26
+
22
27
  end
23
28
  end
@@ -7,10 +7,12 @@ 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
- {Date.civil(2014,1,1) => 'New Year',
11
- Date.civil(2014,4,30) => 'Liberation Day',
12
- Date.civil(2014,5,1) => "International Workers' Day",
13
- Date.civil(2014,9,2) => 'National Day'}.each do |date, name|
10
+ {Date.civil(2014,1,1) => 'Tết dương lịch',
11
+ Date.civil(2014,4,30) => 'Ngày Giải phóng miền Nam, thống nhất đất nước',
12
+ Date.civil(2014,5,1) => "Ngày Quốc tế Lao động",
13
+ Date.civil(2014,9,2) => 'Quốc khánh',
14
+ Date.civil(2017,4,6) => "Giỗ tổ Hùng Vương",
15
+ Date.civil(2018,3,27) => "Giỗ tổ Hùng Vương"}.each do |date, name|
14
16
  assert_equal name, (Holidays.on(date, :vi)[0] || {})[:name]
15
17
  end
16
18
 
@@ -0,0 +1,89 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/../../test_helper'
2
+
3
+ require 'holidays/date_calculator/lunar_date.rb'
4
+
5
+ class LunarHolidaysCalculatorTests < Test::Unit::TestCase
6
+ def setup
7
+ @subject = Holidays::DateCalculator::LunarDate.new
8
+ end
9
+
10
+ def test_korean_new_year_returns_expected_results
11
+ assert_equal '1994-02-10', @subject.to_solar(1994,1,1, :kr).to_s
12
+ assert_equal '1995-01-31', @subject.to_solar(1995,1,1, :kr).to_s
13
+ assert_equal '1999-02-16', @subject.to_solar(1999,1,1, :kr).to_s
14
+ assert_equal '2000-02-05', @subject.to_solar(2000,1,1, :kr).to_s
15
+ assert_equal '2001-01-24', @subject.to_solar(2001,1,1, :kr).to_s
16
+ assert_equal '2002-02-12', @subject.to_solar(2002,1,1, :kr).to_s
17
+ assert_equal '2008-02-07', @subject.to_solar(2008,1,1, :kr).to_s
18
+ assert_equal '2009-01-26', @subject.to_solar(2009,1,1, :kr).to_s
19
+ assert_equal '2010-02-14', @subject.to_solar(2010,1,1, :kr).to_s
20
+ assert_equal '2011-02-03', @subject.to_solar(2011,1,1, :kr).to_s
21
+ assert_equal '2012-01-23', @subject.to_solar(2012,1,1, :kr).to_s
22
+ assert_equal '2013-02-10', @subject.to_solar(2013,1,1, :kr).to_s
23
+ assert_equal '2014-01-31', @subject.to_solar(2014,1,1, :kr).to_s
24
+ assert_equal '2015-02-19', @subject.to_solar(2015,1,1, :kr).to_s
25
+ assert_equal '2016-02-08', @subject.to_solar(2016,1,1, :kr).to_s
26
+ assert_equal '2017-01-28', @subject.to_solar(2017,1,1, :kr).to_s
27
+ assert_equal '2018-02-16', @subject.to_solar(2018,1,1, :kr).to_s
28
+ assert_equal '2019-02-05', @subject.to_solar(2019,1,1, :kr).to_s
29
+ assert_equal '2020-01-25', @subject.to_solar(2020,1,1, :kr).to_s
30
+ assert_equal '2022-02-01', @subject.to_solar(2022,1,1, :kr).to_s
31
+ assert_equal '2025-01-29', @subject.to_solar(2025,1,1, :kr).to_s
32
+ end
33
+
34
+ def test_buddahs_birthday_returns_expected_results
35
+ assert_equal '1994-05-18', @subject.to_solar(1994,4,8, :kr).to_s
36
+ assert_equal '1995-05-07', @subject.to_solar(1995,4,8, :kr).to_s
37
+ assert_equal '1999-05-22', @subject.to_solar(1999,4,8, :kr).to_s
38
+ assert_equal '2000-05-11', @subject.to_solar(2000,4,8, :kr).to_s
39
+ assert_equal '2001-05-01', @subject.to_solar(2001,4,8, :kr).to_s
40
+ assert_equal '2002-05-19', @subject.to_solar(2002,4,8, :kr).to_s
41
+ assert_equal '2008-05-12', @subject.to_solar(2008,4,8, :kr).to_s
42
+ assert_equal '2009-05-02', @subject.to_solar(2009,4,8, :kr).to_s
43
+ assert_equal '2010-05-21', @subject.to_solar(2010,4,8, :kr).to_s
44
+ assert_equal '2011-05-10', @subject.to_solar(2011,4,8, :kr).to_s
45
+ assert_equal '2012-05-28', @subject.to_solar(2012,4,8, :kr).to_s
46
+ assert_equal '2013-05-17', @subject.to_solar(2013,4,8, :kr).to_s
47
+ assert_equal '2014-05-06', @subject.to_solar(2014,4,8, :kr).to_s
48
+ assert_equal '2015-05-25', @subject.to_solar(2015,4,8, :kr).to_s
49
+ assert_equal '2016-05-14', @subject.to_solar(2016,4,8, :kr).to_s
50
+ assert_equal '2017-05-03', @subject.to_solar(2017,4,8, :kr).to_s
51
+ assert_equal '2018-05-22', @subject.to_solar(2018,4,8, :kr).to_s
52
+ assert_equal '2019-05-12', @subject.to_solar(2019,4,8, :kr).to_s
53
+ assert_equal '2020-04-30', @subject.to_solar(2020,4,8, :kr).to_s
54
+ assert_equal '2022-05-08', @subject.to_solar(2022,4,8, :kr).to_s
55
+ assert_equal '2025-05-05', @subject.to_solar(2025,4,8, :kr).to_s
56
+ end
57
+
58
+ def test_korean_thanksgiving_returns_expected_results
59
+ assert_equal '1994-09-20', @subject.to_solar(1994,8,15, :kr).to_s
60
+ assert_equal '1995-09-09', @subject.to_solar(1995,8,15, :kr).to_s
61
+ assert_equal '1999-09-24', @subject.to_solar(1999,8,15, :kr).to_s
62
+ assert_equal '2000-09-12', @subject.to_solar(2000,8,15, :kr).to_s
63
+ assert_equal '2001-10-01', @subject.to_solar(2001,8,15, :kr).to_s
64
+ assert_equal '2002-09-21', @subject.to_solar(2002,8,15, :kr).to_s
65
+ assert_equal '2008-09-14', @subject.to_solar(2008,8,15, :kr).to_s
66
+ assert_equal '2009-10-03', @subject.to_solar(2009,8,15, :kr).to_s
67
+ assert_equal '2010-09-22', @subject.to_solar(2010,8,15, :kr).to_s
68
+ assert_equal '2011-09-12', @subject.to_solar(2011,8,15, :kr).to_s
69
+ assert_equal '2012-09-30', @subject.to_solar(2012,8,15, :kr).to_s
70
+ assert_equal '2013-09-19', @subject.to_solar(2013,8,15, :kr).to_s
71
+ assert_equal '2014-09-08', @subject.to_solar(2014,8,15, :kr).to_s
72
+ assert_equal '2015-09-27', @subject.to_solar(2015,8,15, :kr).to_s
73
+ assert_equal '2016-09-15', @subject.to_solar(2016,8,15, :kr).to_s
74
+ assert_equal '2017-10-04', @subject.to_solar(2017,8,15, :kr).to_s
75
+ assert_equal '2018-09-24', @subject.to_solar(2018,8,15, :kr).to_s
76
+ assert_equal '2019-09-13', @subject.to_solar(2019,8,15, :kr).to_s
77
+ assert_equal '2020-10-01', @subject.to_solar(2020,8,15, :kr).to_s
78
+ assert_equal '2022-09-10', @subject.to_solar(2022,8,15, :kr).to_s
79
+ assert_equal '2025-10-06', @subject.to_solar(2025,8,15, :kr).to_s
80
+ end
81
+
82
+ def test_hung_kings_festival_returns_expected_results
83
+ assert_equal '2014-04-09', @subject.to_solar(2014,3,10, :vi).to_s
84
+ assert_equal '2015-04-28', @subject.to_solar(2015,3,10, :vi).to_s
85
+ assert_equal '2016-04-16', @subject.to_solar(2016,3,10, :vi).to_s
86
+ assert_equal '2017-04-06', @subject.to_solar(2017,3,10, :vi).to_s
87
+ assert_equal '2018-03-27', @subject.to_solar(2018,3,10, :vi).to_s
88
+ end
89
+ end
@@ -7,6 +7,9 @@ class FunctionProcessorTests < Test::Unit::TestCase
7
7
  @year = 2016
8
8
  @month = 1
9
9
  @day = 15
10
+ @region = :test
11
+ @input = { year: @year, month: @month, day: @day, region: @region }
12
+
10
13
  @func_id = "custom_function_id"
11
14
  @func_args = [:year]
12
15
  @func_modifier = 1
@@ -27,17 +30,17 @@ class FunctionProcessorTests < Test::Unit::TestCase
27
30
 
28
31
  def test_no_function_arguments_returns_error
29
32
  assert_raises ArgumentError do
30
- @subject.call(@year, @month, @day, @func_id, nil, @func_modifier)
33
+ @subject.call(@input, @func_id, nil, @func_modifier)
31
34
  end
32
35
 
33
36
  assert_raises ArgumentError do
34
- @subject.call(@year, @month, @day, @func_id, [], @func_modifier)
37
+ @subject.call(@input, @func_id, [], @func_modifier)
35
38
  end
36
39
  end
37
40
 
38
41
  def test_unknown_function_argument_returns_error
39
42
  assert_raises ArgumentError do
40
- @subject.call(@year, @month, @day, @func_id, [:something], @func_modifier)
43
+ @subject.call(@input, @func_id, [:something], @func_modifier)
41
44
  end
42
45
  end
43
46
 
@@ -46,7 +49,7 @@ class FunctionProcessorTests < Test::Unit::TestCase
46
49
  @custom_methods_repo.expects(:find).at_most_once.with(bad_id).returns(nil)
47
50
 
48
51
  assert_raises Holidays::FunctionNotFound do
49
- @subject.call(@year, @month, @day, bad_id, @func_args, @func_modifier)
52
+ @subject.call(@input, bad_id, @func_args, @func_modifier)
50
53
  end
51
54
  end
52
55
 
@@ -54,21 +57,21 @@ class FunctionProcessorTests < Test::Unit::TestCase
54
57
  @func_args = [:year]
55
58
  @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns(Date.civil(2016, 1, 15))
56
59
 
57
- @subject.call(@year, @month, @day, @func_id, @func_args, @func_modifier)
60
+ @subject.call(@input, @func_id, @func_args, @func_modifier)
58
61
  end
59
62
 
60
63
  def test_month_arg_passed_to_func_call
61
64
  @func_args = [:month]
62
65
  @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @month).returns(Date.civil(2016, 1, 15))
63
66
 
64
- @subject.call(@year, @month, @day, @func_id, @func_args, @func_modifier)
67
+ @subject.call(@input, @func_id, @func_args, @func_modifier)
65
68
  end
66
69
 
67
70
  def test_day_arg_passed_to_func_call
68
71
  @func_args = [:day]
69
72
  @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @day).returns(Date.civil(2016, 1, 15))
70
73
 
71
- @subject.call(@year, @month, @day, @func_id, @func_args, @func_modifier)
74
+ @subject.call(@input, @func_id, @func_args, @func_modifier)
72
75
  end
73
76
 
74
77
  def test_date_arg_passed_to_func_call
@@ -76,28 +79,35 @@ class FunctionProcessorTests < Test::Unit::TestCase
76
79
  date = Date.civil(@year, @month, @day)
77
80
  @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, date).returns(date)
78
81
 
79
- @subject.call(@year, @month, @day, @func_id, @func_args, @func_modifier)
82
+ @subject.call(@input, @func_id, @func_args, @func_modifier)
80
83
  end
81
84
 
82
85
  def test_multiple_args_passed_to_func_call
83
86
  @func_args = [:month, :day]
84
87
  @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @month, @day).returns(Date.civil(2016, 1, 15))
85
88
 
86
- @subject.call(@year, @month, @day, @func_id, @func_args, @func_modifier)
89
+ @subject.call(@input, @func_id, @func_args, @func_modifier)
90
+ end
91
+
92
+ def test_multiple_args_with_region_passed_to_func_call
93
+ @func_args = [:month, :day, :region]
94
+ @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @month, @day, @region).returns(Date.civil(2016, 1, 15))
95
+
96
+ @subject.call(@input, @func_id, @func_args, @func_modifier)
87
97
  end
88
98
 
89
99
  def test_call_returns_error_if_target_function_returns_unknown_value
90
100
  @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns("bad-response")
91
101
 
92
102
  assert_raises Holidays::InvalidFunctionResponse do
93
- @subject.call(@year, @month, @day, @func_id, @func_args, @func_modifier)
103
+ @subject.call(@input, @func_id, @func_args, @func_modifier)
94
104
  end
95
105
  end
96
106
 
97
107
  def test_call_returns_date_with_modifier
98
108
  @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns(Date.civil(2016, 3, 10))
99
109
 
100
- result = @subject.call(@year, @month, @day, @func_id, @func_args, @func_modifier)
110
+ result = @subject.call(@input, @func_id, @func_args, @func_modifier)
101
111
 
102
112
  assert_equal(Date.civil(2016, 3, 10) + @func_modifier, result)
103
113
  end
@@ -105,7 +115,7 @@ class FunctionProcessorTests < Test::Unit::TestCase
105
115
  def test_call_returns_date_no_modifier
106
116
  @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns(Date.civil(2016, 3, 10))
107
117
 
108
- result = @subject.call(@year, @month, @day, @func_id, @func_args, nil)
118
+ result = @subject.call(@input, @func_id, @func_args, nil)
109
119
 
110
120
  assert_equal(Date.civil(2016, 3, 10), result)
111
121
  end
@@ -114,7 +124,7 @@ class FunctionProcessorTests < Test::Unit::TestCase
114
124
  @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns("bad")
115
125
 
116
126
  assert_raises Holidays::InvalidFunctionResponse do
117
- @subject.call(@year, @month, @day, @func_id, @func_args, nil)
127
+ @subject.call(@input, @func_id, @func_args, nil)
118
128
  end
119
129
  end
120
130
 
@@ -122,54 +132,68 @@ class FunctionProcessorTests < Test::Unit::TestCase
122
132
  @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns(32)
123
133
 
124
134
  assert_raises Holidays::InvalidFunctionResponse do
125
- @subject.call(@year, @month, @day, @func_id, @func_args, nil)
135
+ @subject.call(@input, @func_id, @func_args, nil)
126
136
  end
127
137
  end
128
138
 
129
139
  def test_call_returns_integer_returns_modified_date
130
140
  @proc_result_cache_repo.expects(:lookup).at_most_once.with(@custom_func, @year).returns(7)
131
141
 
132
- result = @subject.call(@year, @month, @day, @func_id, @func_args, nil)
142
+ result = @subject.call(@input, @func_id, @func_args, nil)
133
143
 
134
144
  assert_equal(Date.civil(2016, 1, 7), result)
135
145
  end
136
146
 
137
147
  def test_func_modifier_not_required
138
- result = @subject.call(@year, @month, @day, @func_id, @func_args)
148
+ result = @subject.call(@input, @func_id, @func_args)
139
149
  assert_equal(Date.civil(2016, 1, 15), result)
140
150
  end
141
151
 
142
152
  def test_validate_returns_error_if_year_not_a_number
153
+ @input[:year] = 'bad-year'
143
154
  assert_raises ArgumentError do
144
- @subject.call("bad-year", @month, @day, @func_id, @func_args)
155
+ @subject.call(@input, @func_id, @func_args)
145
156
  end
146
157
  end
147
158
 
148
159
  def test_validate_returns_error_if_month_not_valid
160
+ @input[:month] = 'bad-month'
149
161
  assert_raises ArgumentError do
150
- @subject.call(@year, "bad-month", @day, @func_id, [:month])
162
+ @subject.call(@input, @func_id, [:month])
151
163
  end
152
164
 
165
+ @input[:month] = -1
153
166
  assert_raises ArgumentError do
154
- @subject.call(@year, -1, @day, @func_id, [:month])
167
+ @subject.call(@input, @func_id, [:month])
155
168
  end
156
169
 
170
+ @input[:month] = 13
157
171
  assert_raises ArgumentError do
158
- @subject.call(@year, 13, @day, @func_id, [:month])
172
+ @subject.call(@input, @func_id, [:month])
159
173
  end
160
174
  end
161
175
 
162
176
  def test_validate_returns_error_if_day_is_not_valid
177
+ @input[:day] = 0
163
178
  assert_raises ArgumentError do
164
- @subject.call(@year, @month, 0, @func_id, [:day])
179
+ @subject.call(@input, @func_id, [:day])
165
180
  end
166
181
 
182
+ @input[:day] = 32
167
183
  assert_raises ArgumentError do
168
- @subject.call(@year, @month, 32, @func_id, [:day])
184
+ @subject.call(@input, @func_id, [:day])
169
185
  end
170
186
 
187
+ @input[:day] = 'bad-day'
188
+ assert_raises ArgumentError do
189
+ @subject.call(@input, @func_id, [:day])
190
+ end
191
+ end
192
+
193
+ def test_validate_returns_error_if_region_not_a_symbol
194
+ @input[:region] = 'blah'
171
195
  assert_raises ArgumentError do
172
- @subject.call(@year, @month, "bad-day", @func_id, [:day])
196
+ @subject.call(@input, @func_id, [:region])
173
197
  end
174
198
  end
175
199
  end