revised_holidays 9.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 +7 -0
- data/.github/workflows/ruby.yml +25 -0
- data/CHANGELOG.md +446 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/Makefile +45 -0
- data/README.md +337 -0
- data/Rakefile +109 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/definitions/.github/workflows/ruby.yml +25 -0
- data/definitions/.gitignore +5 -0
- data/definitions/CHANGELOG.md +352 -0
- data/definitions/Gemfile +6 -0
- data/definitions/LICENSE +21 -0
- data/definitions/METHODS.yml +26 -0
- data/definitions/Makefile +9 -0
- data/definitions/README.md +22 -0
- data/definitions/ar.yaml +268 -0
- data/definitions/at.yaml +116 -0
- data/definitions/au.yaml +907 -0
- data/definitions/be_fr.yaml +153 -0
- data/definitions/be_nl.yaml +153 -0
- data/definitions/bg.yaml +186 -0
- data/definitions/br.yaml +178 -0
- data/definitions/ca.yaml +969 -0
- data/definitions/ch.yaml +277 -0
- data/definitions/cl.yaml +294 -0
- data/definitions/co.yaml +437 -0
- data/definitions/cr.yaml +100 -0
- data/definitions/cz.yaml +137 -0
- data/definitions/de.yaml +401 -0
- data/definitions/dk.yaml +220 -0
- data/definitions/doc/CONTRIBUTING.md +44 -0
- data/definitions/doc/MAINTAINERS.md +39 -0
- data/definitions/doc/SYNTAX.md +435 -0
- data/definitions/doc/architecture/README.md +15 -0
- data/definitions/doc/architecture/adr-001.md +86 -0
- data/definitions/doc/architecture/adr-002.md +64 -0
- data/definitions/ecbtarget.yaml +74 -0
- data/definitions/ee.yaml +123 -0
- data/definitions/es.yaml +495 -0
- data/definitions/federalreserve.yaml +389 -0
- data/definitions/federalreservebanks.yaml +821 -0
- data/definitions/fedex.yaml +102 -0
- data/definitions/fi.yaml +234 -0
- data/definitions/fr.yaml +157 -0
- data/definitions/gb.yaml +565 -0
- data/definitions/ge.yaml +158 -0
- data/definitions/gr.yaml +158 -0
- data/definitions/hk.yaml +287 -0
- data/definitions/hr.yaml +171 -0
- data/definitions/hu.yaml +156 -0
- data/definitions/ie.yaml +172 -0
- data/definitions/index.yaml +80 -0
- data/definitions/is.yaml +247 -0
- data/definitions/it.yaml +246 -0
- data/definitions/jp.yaml +761 -0
- data/definitions/ke.yaml +107 -0
- data/definitions/kr.yaml +166 -0
- data/definitions/kz.yaml +128 -0
- data/definitions/li.yaml +154 -0
- data/definitions/lib/validation/custom_method_validator.rb +38 -0
- data/definitions/lib/validation/definition_validator.rb +35 -0
- data/definitions/lib/validation/error.rb +11 -0
- data/definitions/lib/validation/month_validator.rb +58 -0
- data/definitions/lib/validation/run.rb +66 -0
- data/definitions/lib/validation/test_validator.rb +83 -0
- data/definitions/lt.yaml +198 -0
- data/definitions/lu.yaml +123 -0
- data/definitions/lv.yaml +229 -0
- data/definitions/ma.yaml +96 -0
- data/definitions/mt_en.yaml +131 -0
- data/definitions/mt_mt.yaml +131 -0
- data/definitions/mx.yaml +160 -0
- data/definitions/my.yaml +79 -0
- data/definitions/nerc.yaml +94 -0
- data/definitions/ng.yaml +97 -0
- data/definitions/nl.yaml +127 -0
- data/definitions/no.yaml +169 -0
- data/definitions/northamericainformal.yaml +105 -0
- data/definitions/nyse.yaml +137 -0
- data/definitions/nz.yaml +346 -0
- data/definitions/pe.yaml +208 -0
- data/definitions/ph.yaml +130 -0
- data/definitions/pl.yaml +796 -0
- data/definitions/pt.yaml +187 -0
- data/definitions/ro.yaml +240 -0
- data/definitions/rs_cyrl.yaml +129 -0
- data/definitions/rs_la.yaml +129 -0
- data/definitions/ru.yaml +108 -0
- data/definitions/se.yaml +238 -0
- data/definitions/sg.yaml +89 -0
- data/definitions/si.yaml +162 -0
- data/definitions/sk.yaml +154 -0
- data/definitions/spec/coverage_report.rb +7 -0
- data/definitions/spec/data/invalid/months/malformed/bad.yaml +15 -0
- data/definitions/spec/data/invalid/months/missing/no_months.yaml +9 -0
- data/definitions/spec/data/valid/simple.yaml +15 -0
- data/definitions/spec/spec_helper.rb +7 -0
- data/definitions/spec/validation/custom_method_validator_spec.rb +60 -0
- data/definitions/spec/validation/definition_validator_spec.rb +43 -0
- data/definitions/spec/validation/month_validator_spec.rb +175 -0
- data/definitions/spec/validation/test_validator_spec.rb +169 -0
- data/definitions/th.yaml +111 -0
- data/definitions/tn.yaml +83 -0
- data/definitions/tr.yaml +174 -0
- data/definitions/ua.yaml +161 -0
- data/definitions/unitednations.yaml +189 -0
- data/definitions/ups.yaml +102 -0
- data/definitions/us.yaml +965 -0
- data/definitions/ve.yaml +118 -0
- data/definitions/vi.yaml +54 -0
- data/definitions/za.yaml +139 -0
- data/doc/CONTRIBUTING.md +72 -0
- data/doc/MAINTAINERS.md +81 -0
- data/doc/REFERENCES +19 -0
- data/lib/generated_definitions/MANIFEST +83 -0
- data/lib/generated_definitions/REGIONS.rb +6 -0
- data/lib/generated_definitions/ar.rb +60 -0
- data/lib/generated_definitions/at.rb +37 -0
- data/lib/generated_definitions/au.rb +177 -0
- data/lib/generated_definitions/be.rb +42 -0
- data/lib/generated_definitions/be_fr.rb +36 -0
- data/lib/generated_definitions/be_nl.rb +36 -0
- data/lib/generated_definitions/bg.rb +53 -0
- data/lib/generated_definitions/br.rb +37 -0
- data/lib/generated_definitions/ca.rb +88 -0
- data/lib/generated_definitions/ch.rb +95 -0
- data/lib/generated_definitions/cl.rb +71 -0
- data/lib/generated_definitions/co.rb +121 -0
- data/lib/generated_definitions/cr.rb +35 -0
- data/lib/generated_definitions/cz.rb +37 -0
- data/lib/generated_definitions/de.rb +65 -0
- data/lib/generated_definitions/dk.rb +48 -0
- data/lib/generated_definitions/ecbtarget.rb +30 -0
- data/lib/generated_definitions/ee.rb +36 -0
- data/lib/generated_definitions/el.rb +38 -0
- data/lib/generated_definitions/es.rb +56 -0
- data/lib/generated_definitions/europe.rb +638 -0
- data/lib/generated_definitions/federalreserve.rb +35 -0
- data/lib/generated_definitions/federalreservebanks.rb +35 -0
- data/lib/generated_definitions/fedex.rb +36 -0
- data/lib/generated_definitions/fi.rb +61 -0
- data/lib/generated_definitions/fr.rb +39 -0
- data/lib/generated_definitions/gb.rb +51 -0
- data/lib/generated_definitions/ge.rb +41 -0
- data/lib/generated_definitions/gr.rb +38 -0
- data/lib/generated_definitions/hk.rb +106 -0
- data/lib/generated_definitions/hr.rb +40 -0
- data/lib/generated_definitions/hu.rb +35 -0
- data/lib/generated_definitions/ie.rb +33 -0
- data/lib/generated_definitions/is.rb +60 -0
- data/lib/generated_definitions/it.rb +45 -0
- data/lib/generated_definitions/jp.rb +166 -0
- data/lib/generated_definitions/ke.rb +34 -0
- data/lib/generated_definitions/kr.rb +40 -0
- data/lib/generated_definitions/kz.rb +38 -0
- data/lib/generated_definitions/li.rb +44 -0
- data/lib/generated_definitions/lt.rb +38 -0
- data/lib/generated_definitions/lu.rb +35 -0
- data/lib/generated_definitions/lv.rb +56 -0
- data/lib/generated_definitions/ma.rb +33 -0
- data/lib/generated_definitions/mt_en.rb +38 -0
- data/lib/generated_definitions/mt_mt.rb +38 -0
- data/lib/generated_definitions/mx.rb +54 -0
- data/lib/generated_definitions/my.rb +30 -0
- data/lib/generated_definitions/nerc.rb +30 -0
- data/lib/generated_definitions/ng.rb +33 -0
- data/lib/generated_definitions/nl.rb +37 -0
- data/lib/generated_definitions/no.rb +40 -0
- data/lib/generated_definitions/northamerica.rb +229 -0
- data/lib/generated_definitions/nyse.rb +34 -0
- data/lib/generated_definitions/nz.rb +105 -0
- data/lib/generated_definitions/pe.rb +43 -0
- data/lib/generated_definitions/ph.rb +50 -0
- data/lib/generated_definitions/pl.rb +73 -0
- data/lib/generated_definitions/pt.rb +40 -0
- data/lib/generated_definitions/ro.rb +39 -0
- data/lib/generated_definitions/rs_cyrl.rb +39 -0
- data/lib/generated_definitions/rs_la.rb +39 -0
- data/lib/generated_definitions/ru.rb +37 -0
- data/lib/generated_definitions/scandinavia.rb +166 -0
- data/lib/generated_definitions/se.rb +53 -0
- data/lib/generated_definitions/sg.rb +31 -0
- data/lib/generated_definitions/si.rb +39 -0
- data/lib/generated_definitions/sk.rb +39 -0
- data/lib/generated_definitions/southamerica.rb +248 -0
- data/lib/generated_definitions/th.rb +36 -0
- data/lib/generated_definitions/tn.rb +32 -0
- data/lib/generated_definitions/tr.rb +64 -0
- data/lib/generated_definitions/ua.rb +37 -0
- data/lib/generated_definitions/unitednations.rb +81 -0
- data/lib/generated_definitions/ups.rb +36 -0
- data/lib/generated_definitions/us.rb +153 -0
- data/lib/generated_definitions/ve.rb +36 -0
- data/lib/generated_definitions/vi.rb +29 -0
- data/lib/generated_definitions/za.rb +36 -0
- data/lib/holidays/core_extensions/date.rb +57 -0
- data/lib/holidays/core_extensions/time.rb +23 -0
- data/lib/holidays/date_calculator/day_of_month.rb +68 -0
- data/lib/holidays/date_calculator/easter.rb +91 -0
- data/lib/holidays/date_calculator/lunar_date.rb +371 -0
- data/lib/holidays/date_calculator/weekend_modifier.rb +80 -0
- data/lib/holidays/definition/context/function_processor.rb +91 -0
- data/lib/holidays/definition/context/generator.rb +209 -0
- data/lib/holidays/definition/context/load.rb +29 -0
- data/lib/holidays/definition/context/merger.rb +22 -0
- data/lib/holidays/definition/decorator/custom_method_proc.rb +28 -0
- data/lib/holidays/definition/decorator/custom_method_source.rb +30 -0
- data/lib/holidays/definition/decorator/test.rb +37 -0
- data/lib/holidays/definition/entity/custom_method.rb +11 -0
- data/lib/holidays/definition/entity/test.rb +11 -0
- data/lib/holidays/definition/generator/module.rb +54 -0
- data/lib/holidays/definition/generator/regions.rb +55 -0
- data/lib/holidays/definition/generator/test.rb +51 -0
- data/lib/holidays/definition/parser/custom_method.rb +67 -0
- data/lib/holidays/definition/parser/test.rb +86 -0
- data/lib/holidays/definition/repository/cache.rb +47 -0
- data/lib/holidays/definition/repository/custom_methods.rb +27 -0
- data/lib/holidays/definition/repository/holidays_by_month.rb +57 -0
- data/lib/holidays/definition/repository/proc_result_cache.rb +51 -0
- data/lib/holidays/definition/repository/regions.rb +46 -0
- data/lib/holidays/definition/validator/custom_method.rb +31 -0
- data/lib/holidays/definition/validator/region.rb +36 -0
- data/lib/holidays/definition/validator/test.rb +71 -0
- data/lib/holidays/errors.rb +11 -0
- data/lib/holidays/factory/date_calculator.rb +42 -0
- data/lib/holidays/factory/definition.rb +143 -0
- data/lib/holidays/factory/finder.rb +70 -0
- data/lib/holidays/finder/context/between.rb +45 -0
- data/lib/holidays/finder/context/dates_driver_builder.rb +64 -0
- data/lib/holidays/finder/context/next_holiday.rb +57 -0
- data/lib/holidays/finder/context/parse_options.rb +104 -0
- data/lib/holidays/finder/context/search.rb +111 -0
- data/lib/holidays/finder/context/year_holiday.rb +57 -0
- data/lib/holidays/finder/rules/in_region.rb +31 -0
- data/lib/holidays/finder/rules/year_range.rb +58 -0
- data/lib/holidays/load_all_definitions.rb +56 -0
- data/lib/holidays/version.rb +3 -0
- data/lib/holidays.rb +130 -0
- data/lib/revised_holidays.rb +1 -0
- data/revised_holidays.gemspec +31 -0
- data/test/coverage_report.rb +26 -0
- data/test/data/test_custom_govt_holiday_defs.yaml +5 -0
- data/test/data/test_custom_informal_holidays_defs.yaml +11 -0
- data/test/data/test_custom_year_range_holiday_defs.yaml +31 -0
- data/test/data/test_invalid_region.rb +15 -0
- data/test/data/test_multiple_custom_holiday_defs.yaml +12 -0
- data/test/data/test_multiple_regions_with_conflicts_region_1.yaml +38 -0
- data/test/data/test_multiple_regions_with_conflicts_region_2.yaml +38 -0
- data/test/data/test_region.rb +15 -0
- data/test/data/test_single_custom_holiday_defs.yaml +12 -0
- data/test/data/test_single_custom_holiday_with_custom_procs.yaml +28 -0
- data/test/defs/test_defs_ar.rb +69 -0
- data/test/defs/test_defs_at.rb +31 -0
- data/test/defs/test_defs_au.rb +233 -0
- data/test/defs/test_defs_be_fr.rb +45 -0
- data/test/defs/test_defs_be_nl.rb +45 -0
- data/test/defs/test_defs_bg.rb +41 -0
- data/test/defs/test_defs_br.rb +49 -0
- data/test/defs/test_defs_ca.rb +289 -0
- data/test/defs/test_defs_ch.rb +51 -0
- data/test/defs/test_defs_cl.rb +69 -0
- data/test/defs/test_defs_co.rb +113 -0
- data/test/defs/test_defs_cr.rb +29 -0
- data/test/defs/test_defs_cz.rb +37 -0
- data/test/defs/test_defs_de.rb +89 -0
- data/test/defs/test_defs_dk.rb +47 -0
- data/test/defs/test_defs_ecbtarget.rb +27 -0
- data/test/defs/test_defs_ee.rb +41 -0
- data/test/defs/test_defs_es.rb +137 -0
- data/test/defs/test_defs_europe.rb +1522 -0
- data/test/defs/test_defs_fed_ex.rb +24 -0
- data/test/defs/test_defs_federalreserve.rb +119 -0
- data/test/defs/test_defs_federalreservebanks.rb +251 -0
- data/test/defs/test_defs_fedex.rb +31 -0
- data/test/defs/test_defs_fi.rb +59 -0
- data/test/defs/test_defs_fr.rb +43 -0
- data/test/defs/test_defs_gb.rb +159 -0
- data/test/defs/test_defs_ge.rb +53 -0
- data/test/defs/test_defs_gr.rb +41 -0
- data/test/defs/test_defs_hk.rb +59 -0
- data/test/defs/test_defs_hr.rb +45 -0
- data/test/defs/test_defs_hu.rb +47 -0
- data/test/defs/test_defs_ie.rb +53 -0
- data/test/defs/test_defs_is.rb +51 -0
- data/test/defs/test_defs_it.rb +55 -0
- data/test/defs/test_defs_jp.rb +159 -0
- data/test/defs/test_defs_ke.rb +31 -0
- data/test/defs/test_defs_kr.rb +37 -0
- data/test/defs/test_defs_kz.rb +39 -0
- data/test/defs/test_defs_li.rb +35 -0
- data/test/defs/test_defs_lt.rb +65 -0
- data/test/defs/test_defs_lu.rb +35 -0
- data/test/defs/test_defs_lv.rb +98 -0
- data/test/defs/test_defs_ma.rb +29 -0
- data/test/defs/test_defs_mt_en.rb +41 -0
- data/test/defs/test_defs_mt_mt.rb +41 -0
- data/test/defs/test_defs_mx.rb +49 -0
- data/test/defs/test_defs_my.rb +23 -0
- data/test/defs/test_defs_nerc.rb +29 -0
- data/test/defs/test_defs_ng.rb +29 -0
- data/test/defs/test_defs_nl.rb +33 -0
- data/test/defs/test_defs_no.rb +43 -0
- data/test/defs/test_defs_northamerica.rb +667 -0
- data/test/defs/test_defs_nyse.rb +46 -0
- data/test/defs/test_defs_nz.rb +67 -0
- data/test/defs/test_defs_pe.rb +47 -0
- data/test/defs/test_defs_ph.rb +29 -0
- data/test/defs/test_defs_pl.rb +229 -0
- data/test/defs/test_defs_pt.rb +47 -0
- data/test/defs/test_defs_ro.rb +65 -0
- data/test/defs/test_defs_rs_cyrl.rb +46 -0
- data/test/defs/test_defs_rs_la.rb +46 -0
- data/test/defs/test_defs_ru.rb +34 -0
- data/test/defs/test_defs_scandinavia.rb +215 -0
- data/test/defs/test_defs_se.rb +59 -0
- data/test/defs/test_defs_sg.rb +25 -0
- data/test/defs/test_defs_si.rb +105 -0
- data/test/defs/test_defs_sk.rb +41 -0
- data/test/defs/test_defs_southamerica.rb +327 -0
- data/test/defs/test_defs_th.rb +33 -0
- data/test/defs/test_defs_tn.rb +27 -0
- data/test/defs/test_defs_tr.rb +60 -0
- data/test/defs/test_defs_ua.rb +41 -0
- data/test/defs/test_defs_unitednations.rb +11 -0
- data/test/defs/test_defs_ups.rb +31 -0
- data/test/defs/test_defs_us.rb +387 -0
- data/test/defs/test_defs_ve.rb +35 -0
- data/test/defs/test_defs_vi.rb +22 -0
- data/test/defs/test_defs_za.rb +35 -0
- data/test/holidays/core_extensions/test_date.rb +122 -0
- data/test/holidays/core_extensions/test_date_time.rb +60 -0
- data/test/holidays/date_calculator/test_day_of_month.rb +27 -0
- data/test/holidays/date_calculator/test_easter_gregorian.rb +30 -0
- data/test/holidays/date_calculator/test_easter_julian.rb +36 -0
- data/test/holidays/date_calculator/test_lunar_date.rb +89 -0
- data/test/holidays/date_calculator/test_weekend_modifier.rb +54 -0
- data/test/holidays/definition/context/test_function_processor.rb +199 -0
- data/test/holidays/definition/context/test_generator.rb +226 -0
- data/test/holidays/definition/context/test_load.rb +37 -0
- data/test/holidays/definition/context/test_merger.rb +25 -0
- data/test/holidays/definition/decorator/test_custom_method_proc.rb +113 -0
- data/test/holidays/definition/decorator/test_custom_method_source.rb +96 -0
- data/test/holidays/definition/decorator/test_test.rb +123 -0
- data/test/holidays/definition/generator/test_module.rb +268 -0
- data/test/holidays/definition/generator/test_regions.rb +97 -0
- data/test/holidays/definition/generator/test_test.rb +113 -0
- data/test/holidays/definition/parser/test_custom_method.rb +79 -0
- data/test/holidays/definition/parser/test_test.rb +142 -0
- data/test/holidays/definition/repository/test_cache.rb +123 -0
- data/test/holidays/definition/repository/test_custom_methods.rb +43 -0
- data/test/holidays/definition/repository/test_holidays_by_month.rb +275 -0
- data/test/holidays/definition/repository/test_proc_result_cache.rb +91 -0
- data/test/holidays/definition/repository/test_regions.rb +104 -0
- data/test/holidays/definition/validator/test_custom_method.rb +94 -0
- data/test/holidays/definition/validator/test_region.rb +54 -0
- data/test/holidays/definition/validator/test_test.rb +60 -0
- data/test/holidays/finder/context/test_between.rb +172 -0
- data/test/holidays/finder/context/test_dates_driver_builder.rb +91 -0
- data/test/holidays/finder/context/test_next_holiday.rb +156 -0
- data/test/holidays/finder/context/test_parse_options.rb +141 -0
- data/test/holidays/finder/context/test_search.rb +232 -0
- data/test/holidays/finder/context/test_year_holiday.rb +202 -0
- data/test/holidays/finder/rules/test_in_region.rb +42 -0
- data/test/holidays/finder/rules/test_year_range.rb +166 -0
- data/test/integration/README.md +9 -0
- data/test/integration/test_all_regions.rb +49 -0
- data/test/integration/test_any_holidays_during_work_week.rb +90 -0
- data/test/integration/test_available_regions.rb +23 -0
- data/test/integration/test_custom_holidays.rb +41 -0
- data/test/integration/test_custom_informal_holidays.rb +15 -0
- data/test/integration/test_custom_year_range_holidays.rb +35 -0
- data/test/integration/test_holidays.rb +243 -0
- data/test/integration/test_holidays_between.rb +87 -0
- data/test/integration/test_multiple_regions.rb +71 -0
- data/test/integration/test_multiple_regions_with_conflict.rb +29 -0
- data/test/integration/test_nonstandard_regions.rb +25 -0
- data/test/test_helper.rb +37 -0
- metadata +649 -0
|
@@ -0,0 +1,268 @@
|
|
|
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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
2
|
+
|
|
3
|
+
require 'holidays/definition/parser/custom_method'
|
|
4
|
+
require 'holidays/definition/entity/custom_method'
|
|
5
|
+
|
|
6
|
+
class ParserCustomMethodTests < Test::Unit::TestCase
|
|
7
|
+
def setup
|
|
8
|
+
@validator = mock()
|
|
9
|
+
|
|
10
|
+
@parser = Holidays::Definition::Parser::CustomMethod.new(@validator)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_parse_happy_single_method
|
|
14
|
+
input = {"custom_method"=>{"arguments"=>"year", "ruby"=>"d = Date.civil(year, 1, 1)\nd + 2\n"}}
|
|
15
|
+
@validator.expects(:valid?).with({:name => "custom_method", :arguments => "year", :source => "d = Date.civil(year, 1, 1)\nd + 2\n"}).returns(true)
|
|
16
|
+
|
|
17
|
+
result = @parser.call(input)
|
|
18
|
+
|
|
19
|
+
assert_equal(1, result.size)
|
|
20
|
+
|
|
21
|
+
custom_method = result["custom_method(year)"]
|
|
22
|
+
assert(custom_method)
|
|
23
|
+
|
|
24
|
+
assert(custom_method.is_a?(Holidays::Definition::Entity::CustomMethod))
|
|
25
|
+
assert_equal("custom_method", custom_method.name)
|
|
26
|
+
assert_equal(["year"], custom_method.arguments)
|
|
27
|
+
assert_equal("d = Date.civil(year, 1, 1)\nd + 2\n", custom_method.source)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_call_happy_with_multiple_methods
|
|
31
|
+
input = {"custom_method"=>{"arguments"=>"year", "ruby"=>"d = Date.civil(year, 1, 1)\nd + 2\n"}, "second_method"=>{"arguments"=>"month","ruby"=>"source"}}
|
|
32
|
+
@validator.expects(:valid?).with({:name => "custom_method", :arguments => "year", :source => "d = Date.civil(year, 1, 1)\nd + 2\n"}).returns(true)
|
|
33
|
+
@validator.expects(:valid?).with({:name => "second_method", :arguments => "month", :source => "source"}).returns(true)
|
|
34
|
+
|
|
35
|
+
result = @parser.call(input)
|
|
36
|
+
|
|
37
|
+
assert_equal(2, result.size)
|
|
38
|
+
|
|
39
|
+
custom_method = result["custom_method(year)"]
|
|
40
|
+
assert(custom_method)
|
|
41
|
+
|
|
42
|
+
assert(custom_method.is_a?(Holidays::Definition::Entity::CustomMethod))
|
|
43
|
+
assert_equal("custom_method", custom_method.name)
|
|
44
|
+
assert_equal(["year"], custom_method.arguments)
|
|
45
|
+
assert_equal("d = Date.civil(year, 1, 1)\nd + 2\n", custom_method.source)
|
|
46
|
+
|
|
47
|
+
second_method= result["second_method(month)"]
|
|
48
|
+
assert(second_method)
|
|
49
|
+
|
|
50
|
+
assert(second_method.is_a?(Holidays::Definition::Entity::CustomMethod))
|
|
51
|
+
assert_equal("second_method", second_method.name)
|
|
52
|
+
assert_equal(["month"], second_method.arguments)
|
|
53
|
+
assert_equal("source", second_method.source)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_call_returns_empty_hash_if_methods_are_missing
|
|
57
|
+
assert_equal({}, @parser.call(nil))
|
|
58
|
+
assert_equal({}, @parser.call({}))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_call_raises_error_if_validator_returns_false_for_single_method
|
|
62
|
+
input = {"custom_method"=>{"arguments"=>"year", "ruby"=>"d = Date.civil(year, 1, 1)\nd + 2\n"}}
|
|
63
|
+
@validator.expects(:valid?).with({:name => "custom_method", :arguments => "year", :source => "d = Date.civil(year, 1, 1)\nd + 2\n"}).returns(false)
|
|
64
|
+
|
|
65
|
+
assert_raises ArgumentError do
|
|
66
|
+
@parser.call(input)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_call_raises_error_if_validator_returns_false_for_one_of_multiple_methods
|
|
71
|
+
input = {"custom_method"=>{"arguments"=>"year", "ruby"=>"d = Date.civil(year, 1, 1)\nd + 2\n"}, "second_method"=>{"arguments"=>"month","ruby"=>"source"}}
|
|
72
|
+
@validator.expects(:valid?).with({:name => "custom_method", :arguments => "year", :source => "d = Date.civil(year, 1, 1)\nd + 2\n"}).returns(true)
|
|
73
|
+
@validator.expects(:valid?).with({:name => "second_method", :arguments => "month", :source => "source"}).returns(false)
|
|
74
|
+
|
|
75
|
+
assert_raises ArgumentError do
|
|
76
|
+
@parser.call(input)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Heh at this file name
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
|
|
3
|
+
|
|
4
|
+
require 'holidays/definition/parser/test'
|
|
5
|
+
require 'holidays/definition/entity/test'
|
|
6
|
+
|
|
7
|
+
class ParserTestTests < Test::Unit::TestCase
|
|
8
|
+
def setup
|
|
9
|
+
@validator = mock()
|
|
10
|
+
|
|
11
|
+
@parser = Holidays::Definition::Parser::Test.new(@validator)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_parse_no_tests
|
|
15
|
+
input = nil
|
|
16
|
+
result = @parser.call(input)
|
|
17
|
+
|
|
18
|
+
assert_equal(0, result.size)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_parse_single_test_happy
|
|
22
|
+
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us'] }, "expect" => { "name" => "Test Holiday" } } ]
|
|
23
|
+
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :options => nil, :name => "Test Holiday", :holiday => nil}).returns(true)
|
|
24
|
+
|
|
25
|
+
result = @parser.call(input)
|
|
26
|
+
|
|
27
|
+
assert_equal(1, result.size)
|
|
28
|
+
|
|
29
|
+
test = result.first
|
|
30
|
+
assert(test)
|
|
31
|
+
|
|
32
|
+
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
33
|
+
assert_equal([DateTime.parse('2016-01-01')], test.dates)
|
|
34
|
+
assert_equal([:us], test.regions)
|
|
35
|
+
assert_equal("Test Holiday", test.name)
|
|
36
|
+
assert(test.holiday?)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_parse_single_test_with_options
|
|
40
|
+
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us'], "options" => ['option1']}, "expect" => { "name" => "Test Holiday" } } ]
|
|
41
|
+
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :name => "Test Holiday", :options => ['option1'], :holiday => nil}).returns(true)
|
|
42
|
+
|
|
43
|
+
result = @parser.call(input)
|
|
44
|
+
|
|
45
|
+
assert_equal(1, result.size)
|
|
46
|
+
|
|
47
|
+
test = result.first
|
|
48
|
+
assert(test)
|
|
49
|
+
|
|
50
|
+
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
51
|
+
assert_equal([DateTime.parse('2016-01-01')], test.dates)
|
|
52
|
+
assert_equal([:us], test.regions)
|
|
53
|
+
assert_equal([:option1], test.options)
|
|
54
|
+
assert_equal("Test Holiday", test.name)
|
|
55
|
+
assert(test.holiday?)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_parse_single_test_with_single_option_as_string
|
|
59
|
+
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us'], "options" => 'option1'}, "expect" => { "name" => "Test Holiday" } } ]
|
|
60
|
+
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :name => "Test Holiday", :options => 'option1', :holiday => nil}).returns(true)
|
|
61
|
+
|
|
62
|
+
result = @parser.call(input)
|
|
63
|
+
|
|
64
|
+
assert_equal(1, result.size)
|
|
65
|
+
|
|
66
|
+
test = result.first
|
|
67
|
+
assert(test)
|
|
68
|
+
|
|
69
|
+
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
70
|
+
assert_equal([DateTime.parse('2016-01-01')], test.dates)
|
|
71
|
+
assert_equal([:us], test.regions)
|
|
72
|
+
assert_equal([:option1], test.options)
|
|
73
|
+
assert_equal("Test Holiday", test.name)
|
|
74
|
+
assert(test.holiday?)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_parse_single_test_no_name_no_holiday
|
|
78
|
+
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us']}, "expect" => { "holiday" => false } } ]
|
|
79
|
+
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :name => nil, :options => nil, :holiday => false}).returns(true)
|
|
80
|
+
|
|
81
|
+
result = @parser.call(input)
|
|
82
|
+
|
|
83
|
+
assert_equal(1, result.size)
|
|
84
|
+
|
|
85
|
+
test = result.first
|
|
86
|
+
assert(test)
|
|
87
|
+
|
|
88
|
+
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
89
|
+
assert_equal([DateTime.parse('2016-01-01')], test.dates)
|
|
90
|
+
assert_equal([:us], test.regions)
|
|
91
|
+
assert_nil(test.options)
|
|
92
|
+
assert_nil(test.name)
|
|
93
|
+
assert_equal(false, test.holiday?)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_parse_single_test_with_options_no_name_no_holiday
|
|
97
|
+
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us'], "options" => ['option1']}, "expect" => { "holiday" => false } } ]
|
|
98
|
+
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :name => nil, :options => ['option1'], :holiday => false}).returns(true)
|
|
99
|
+
|
|
100
|
+
result = @parser.call(input)
|
|
101
|
+
|
|
102
|
+
assert_equal(1, result.size)
|
|
103
|
+
|
|
104
|
+
test = result.first
|
|
105
|
+
assert(test)
|
|
106
|
+
|
|
107
|
+
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
108
|
+
assert_equal([DateTime.parse('2016-01-01')], test.dates)
|
|
109
|
+
assert_equal([:us], test.regions)
|
|
110
|
+
assert_equal([:option1], test.options)
|
|
111
|
+
assert_nil(test.name)
|
|
112
|
+
assert_equal(false, test.holiday?)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_parse_single_test_multiple_dates
|
|
116
|
+
input = [ { "given" => { "date" => ["2016-01-01", "2017-01-01"], "regions" => ['us']}, "expect" => { "name" => "Test Holiday"} } ]
|
|
117
|
+
@validator.expects(:valid?).with({:dates => ["2016-01-01", "2017-01-01"], :regions=> ['us'], :name => "Test Holiday", :options => nil, :holiday => nil}).returns(true)
|
|
118
|
+
|
|
119
|
+
result = @parser.call(input)
|
|
120
|
+
|
|
121
|
+
assert_equal(1, result.size)
|
|
122
|
+
|
|
123
|
+
test = result.first
|
|
124
|
+
assert(test)
|
|
125
|
+
|
|
126
|
+
assert(test.is_a?(Holidays::Definition::Entity::Test))
|
|
127
|
+
assert_equal([DateTime.parse('2016-01-01'), DateTime.parse('2017-01-01')], test.dates)
|
|
128
|
+
assert_equal([:us], test.regions)
|
|
129
|
+
assert_nil(test.options)
|
|
130
|
+
assert_equal("Test Holiday", test.name)
|
|
131
|
+
assert(test.holiday?)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_parse_single_test_fail_validation
|
|
135
|
+
input = [ { "given" => { "date" => "2016-01-01", "regions" => ['us']}, "expect" => { "name" => "Test Holiday"} } ]
|
|
136
|
+
@validator.expects(:valid?).with({:dates => ["2016-01-01"], :regions=> ['us'], :name => "Test Holiday", :options => nil, :holiday => nil}).returns(false)
|
|
137
|
+
|
|
138
|
+
assert_raises ArgumentError do
|
|
139
|
+
@parser.call(input)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|