2007-11-20 01:58:20 +01:00
|
|
|
require File.dirname(__FILE__) + '/test_helper'
|
2007-11-21 01:13:18 +01:00
|
|
|
|
2007-11-29 03:24:00 +01:00
|
|
|
require 'holidays/ca'
|
|
|
|
|
|
|
|
# Re-include CA defs via holidays/north_america to ensure that individual
|
|
|
|
# defs aren't duplicated.
|
|
|
|
require 'holidays/north_america'
|
|
|
|
|
2007-11-21 01:13:18 +01:00
|
|
|
class HolidaysTests < Test::Unit::TestCase
|
2007-11-20 01:58:20 +01:00
|
|
|
def setup
|
|
|
|
@date = Date.civil(2008,1,1)
|
|
|
|
end
|
|
|
|
|
2007-11-22 21:39:26 +01:00
|
|
|
def test_on
|
|
|
|
h = Holidays.on(Date.civil(2008,9,1), :ca)
|
|
|
|
assert_equal 'Labour Day', h[0][:name]
|
2007-11-20 01:58:20 +01:00
|
|
|
|
2007-11-22 21:39:26 +01:00
|
|
|
holidays = Holidays.on(Date.civil(2008,7,4), :ca)
|
|
|
|
assert_equal 0, holidays.length
|
2007-11-20 05:06:48 +01:00
|
|
|
end
|
|
|
|
|
2007-11-22 21:39:26 +01:00
|
|
|
def test_between
|
2007-11-30 01:03:43 +01:00
|
|
|
holidays = Holidays.between(Date.civil(2008,7,1), Date.civil(2008,7,1), :ca)
|
|
|
|
assert_equal 1, holidays.length
|
|
|
|
|
2007-11-22 21:39:26 +01:00
|
|
|
holidays = Holidays.between(Date.civil(2008,7,1), Date.civil(2008,7,31), :ca)
|
|
|
|
assert_equal 1, holidays.length
|
2007-11-20 01:58:20 +01:00
|
|
|
|
2007-11-22 21:39:26 +01:00
|
|
|
holidays = Holidays.between(Date.civil(2008,7,2), Date.civil(2008,7,31), :ca)
|
|
|
|
assert_equal 0, holidays.length
|
2007-11-21 01:13:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_requires_valid_regions
|
2010-03-28 04:23:35 +02:00
|
|
|
assert_raises Holidays::UnknownRegionError do
|
2007-11-22 21:39:26 +01:00
|
|
|
Holidays.on(Date.civil(2008,1,1), :xx)
|
2007-11-21 01:13:18 +01:00
|
|
|
end
|
|
|
|
|
2010-03-28 04:23:35 +02:00
|
|
|
assert_raises Holidays::UnknownRegionError do
|
2007-11-22 21:39:26 +01:00
|
|
|
Holidays.on(Date.civil(2008,1,1), [:ca,:xx])
|
2007-11-21 01:13:18 +01:00
|
|
|
end
|
|
|
|
|
2010-03-28 04:23:35 +02:00
|
|
|
assert_raises Holidays::UnknownRegionError do
|
2007-11-21 01:13:18 +01:00
|
|
|
Holidays.between(Date.civil(2008,1,1), Date.civil(2008,12,31), [:ca,:xx])
|
|
|
|
end
|
2007-11-20 01:58:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_region_params
|
2007-11-22 21:39:26 +01:00
|
|
|
holidays = Holidays.on(@date, :ca)
|
2007-11-20 01:58:20 +01:00
|
|
|
assert_equal 1, holidays.length
|
|
|
|
|
2007-11-22 21:39:26 +01:00
|
|
|
holidays = Holidays.on(@date, [:ca_bc,:ca])
|
2007-11-20 01:58:20 +01:00
|
|
|
assert_equal 1, holidays.length
|
|
|
|
end
|
2007-11-22 21:39:26 +01:00
|
|
|
|
2007-11-30 00:23:35 +01:00
|
|
|
def test_observed_dates
|
|
|
|
# Should fall on Tuesday the 1st
|
2007-11-30 01:03:43 +01:00
|
|
|
assert_equal 1, Holidays.on(Date.civil(2008,7,1), :ca, :observed).length
|
2007-11-30 00:23:35 +01:00
|
|
|
|
|
|
|
# Should fall on Monday the 2nd
|
|
|
|
assert_equal 1, Holidays.on(Date.civil(2007,7,2), :ca, :observed).length
|
|
|
|
end
|
|
|
|
|
2007-11-22 21:39:26 +01:00
|
|
|
def test_any_region
|
2007-11-30 00:23:35 +01:00
|
|
|
# Should return Victoria Day.
|
2007-11-22 21:39:26 +01:00
|
|
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca)
|
2007-11-30 00:23:35 +01:00
|
|
|
assert_equal 1, holidays.length
|
2007-11-20 01:58:20 +01:00
|
|
|
|
2007-11-30 00:23:35 +01:00
|
|
|
# Should return Victoria Day and National Patriotes Day.
|
2007-11-25 00:22:10 +01:00
|
|
|
#
|
2007-11-30 00:23:35 +01:00
|
|
|
# Should be 2 in the CA region but other regional files are loaded during the
|
2007-11-25 00:22:10 +01:00
|
|
|
# unit tests add to the :any count.
|
|
|
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), [:any])
|
2007-11-30 00:23:35 +01:00
|
|
|
assert holidays.length >= 2
|
|
|
|
|
|
|
|
# Test blank region
|
|
|
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31))
|
2007-11-25 00:22:10 +01:00
|
|
|
assert holidays.length >= 3
|
2007-11-20 01:58:20 +01:00
|
|
|
end
|
2007-11-22 21:39:26 +01:00
|
|
|
|
|
|
|
def test_sub_regions
|
2007-11-30 00:23:35 +01:00
|
|
|
# Should return Victoria Day.
|
2007-11-22 21:39:26 +01:00
|
|
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca)
|
2007-11-30 00:23:35 +01:00
|
|
|
assert_equal 1, holidays.length
|
2007-11-20 01:58:20 +01:00
|
|
|
|
2007-11-30 00:23:35 +01:00
|
|
|
# Should return Victoria Da and National Patriotes Day.
|
2007-11-22 21:39:26 +01:00
|
|
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca_qc)
|
2007-11-30 00:23:35 +01:00
|
|
|
assert 2, holidays.length
|
2007-11-25 00:22:10 +01:00
|
|
|
|
2007-11-30 00:23:35 +01:00
|
|
|
# Should return Victoria Day and National Patriotes Day.
|
2007-11-25 00:22:10 +01:00
|
|
|
holidays = Holidays.between(Date.civil(2008,5,1), Date.civil(2008,5,31), :ca_)
|
2007-11-30 00:23:35 +01:00
|
|
|
assert_equal 2, holidays.length
|
2007-11-20 01:58:20 +01:00
|
|
|
end
|
2007-11-25 00:22:10 +01:00
|
|
|
|
|
|
|
def test_easter_sunday
|
|
|
|
assert_equal '1800-04-13', Holidays.easter(1800).to_s
|
|
|
|
assert_equal '1899-04-02', Holidays.easter(1899).to_s
|
|
|
|
assert_equal '1900-04-15', Holidays.easter(1900).to_s
|
|
|
|
assert_equal '1999-04-04', Holidays.easter(1999).to_s
|
|
|
|
assert_equal '2000-04-23', Holidays.easter(2000).to_s
|
|
|
|
assert_equal '2025-04-20', Holidays.easter(2025).to_s
|
|
|
|
assert_equal '2035-03-25', Holidays.easter(2035).to_s
|
|
|
|
assert_equal '2067-04-03', Holidays.easter(2067).to_s
|
|
|
|
assert_equal '2099-04-12', Holidays.easter(2099).to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_easter_lambda
|
|
|
|
[Date.civil(1800,4,11), Date.civil(1899,3,31), Date.civil(1900,4,13),
|
|
|
|
Date.civil(2008,3,21), Date.civil(2035,3,23)].each do |date|
|
|
|
|
assert_equal 'Good Friday', Holidays.on(date, :ca)[0][:name]
|
|
|
|
end
|
|
|
|
|
|
|
|
[Date.civil(1800,4,14), Date.civil(1899,4,3), Date.civil(1900,4,16),
|
|
|
|
Date.civil(2008,3,24), Date.civil(2035,3,26)].each do |date|
|
2007-11-30 00:23:35 +01:00
|
|
|
assert_equal 'Easter Monday', Holidays.on(date, :ca_qc, :informal)[0][:name]
|
2007-11-25 00:22:10 +01:00
|
|
|
end
|
|
|
|
end
|
2007-11-20 01:58:20 +01:00
|
|
|
end
|