test/tc_timezone_proxy.rb in tzinfo-1.1.0 vs test/tc_timezone_proxy.rb in tzinfo-1.2.0

- old
+ new

@@ -1,32 +1,10 @@ -#-- -# Copyright (c) 2005-2013 Philip Ross -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -#++ - require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils') include TZInfo -class TCTimezoneProxy < Test::Unit::TestCase +class TCTimezoneProxy < Minitest::Test def test_not_exist proxy = TimezoneProxy.new('Nothing/Special') assert_equal('Nothing/Special', proxy.identifier) assert_raises(InvalidTimezoneIdentifier) { proxy.now } assert_raises(InvalidTimezoneIdentifier) { proxy.current_period } @@ -34,21 +12,22 @@ assert_raises(InvalidTimezoneIdentifier) { proxy.current_time_and_period } assert_raises(InvalidTimezoneIdentifier) { proxy.utc_to_local(DateTime.new(2006,1,1,0,0,0)) } assert_raises(InvalidTimezoneIdentifier) { proxy.local_to_utc(DateTime.new(2006,1,1,0,0,0)) } assert_raises(InvalidTimezoneIdentifier) { proxy.period_for_utc(DateTime.new(2006,1,1,0,0,0)) } assert_raises(InvalidTimezoneIdentifier) { proxy.period_for_local(DateTime.new(2006,1,1,0,0,0)) } + assert_raises(InvalidTimezoneIdentifier) { proxy.canonical_identifier } + assert_raises(InvalidTimezoneIdentifier) { proxy.canonical_zone } end def test_valid proxy = TimezoneProxy.new('Europe/London') assert_equal('Europe/London', proxy.identifier) - # Test nothing raised - proxy.now - proxy.current_period - proxy.current_period_and_time - proxy.current_time_and_period + assert_nothing_raised { proxy.now } + assert_nothing_raised { proxy.current_period } + assert_nothing_raised { proxy.current_period_and_time } + assert_nothing_raised { proxy.current_time_and_period } real = Timezone.get('Europe/London') assert_equal(real.utc_to_local(DateTime.new(2005,8,1,0,0,0)), proxy.utc_to_local(DateTime.new(2005,8,1,0,0,0))) assert_equal(real.local_to_utc(DateTime.new(2005,8,1,0,0,0)), proxy.local_to_utc(DateTime.new(2005,8,1,0,0,0))) @@ -58,16 +37,43 @@ assert_equal(real.name, proxy.name) assert_equal(real.to_s, proxy.to_s) assert_equal(real.friendly_identifier(true), proxy.friendly_identifier(true)) assert_equal(real.friendly_identifier(false), proxy.friendly_identifier(false)) assert_equal(real.friendly_identifier, proxy.friendly_identifier) + assert_equal(real.canonical_identifier, proxy.canonical_identifier) + assert_same(real.canonical_zone, proxy.canonical_zone) assert_equal('Europe/London', proxy.identifier) assert(real == proxy) assert(proxy == real) assert_equal(0, real <=> proxy) assert_equal(0, proxy <=> real) + end + + def test_canonical_linked + # Test that the implementation of canonical_zone and canonical_identifier + # are actually calling the real timezone and not just returning it and + # its identifier. + + real = Timezone.get('UTC') + proxy = TimezoneProxy.new('UTC') + + # ZoneinfoDataSource doesn't return LinkedTimezoneInfo instances for any + # timezone. + if real.kind_of?(LinkedTimezone) + assert_equal('Etc/UTC', proxy.canonical_identifier) + assert_same(Timezone.get('Etc/UTC'), proxy.canonical_zone) + else + if DataSource.get.kind_of?(RubyDataSource) + # Not got a LinkedTimezone despite using a DataSource that supports it. + # Raise an exception as this shouldn't happen. + raise 'Non-LinkedTimezone instance returned for UTC using RubyDataSource' + end + + assert_equal('UTC', proxy.canonical_identifier) + assert_same(Timezone.get('UTC'), proxy.canonical_zone) + end end def test_equals assert_equal(true, TimezoneProxy.new('Europe/London') == TimezoneProxy.new('Europe/London')) assert_equal(false, TimezoneProxy.new('Europe/London') == TimezoneProxy.new('Europe/Paris'))