From 670b62a61c9e26a34dce43fe1e6a50ad57c92923 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 10 Jun 2010 15:15:47 +0000 Subject: make it runnable by ruby 1.8.6. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28258 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_time_tz.rb | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'test/ruby/test_time_tz.rb') diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb index ddad6985bd..857b41a4cf 100644 --- a/test/ruby/test_time_tz.rb +++ b/test/ruby/test_time_tz.rb @@ -29,6 +29,19 @@ class TestTimeTZ < Test::Unit::TestCase expected << "%02d%02d" % [gmtoff / 60, gmtoff % 60] expected end + + def group_by(e, &block) + if e.respond_to? :group_by + e.group_by(&block) + else + h = {} + e.each {|o| + (h[yield(o)] ||= []) << o + } + h + end + end + end include Util @@ -42,9 +55,10 @@ class TestTimeTZ < Test::Unit::TestCase end end + def assert_time_constructor(tz, expected, method, args, message=nil) m = message ? "#{message}\n" : "" - m << "TZ=#{tz} Time.#{method}(#{args.map(&:inspect).join(', ')})" + m << "TZ=#{tz} Time.#{method}(#{args.map {|arg| arg.inspect }.join(', ')})" real = time_to_s(Time.send(method, *args)) assert_equal(expected, real, m) end @@ -125,10 +139,11 @@ class TestTimeTZ < Test::Unit::TestCase "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12 } - GENTESTNAME = "test_gen_0" + @testnum = 0 def self.gen_test_name(hint) - GENTESTNAME.succ! - GENTESTNAME.sub(/gen_/) { "gen" + "_#{hint}_".gsub(/[^0-9A-Za-z]+/, '_') } + @testnum += 1 + s = "test_gen_#{@testnum}" + s.sub(/gen_/) { "gen" + "_#{hint}_".gsub(/[^0-9A-Za-z]+/, '_') } end def self.gen_zdump_test @@ -163,7 +178,7 @@ class TestTimeTZ < Test::Unit::TestCase } sample.each {|tz, u, l, gmtoff| expected = "%04d-%02d-%02d %02d:%02d:%02d %s" % (l+[format_gmtoff(gmtoff)]) - mesg = "TZ=#{tz} Time.utc(#{u.map(&:inspect).join(', ')}).localtime" + mesg = "TZ=#{tz} Time.utc(#{u.map {|arg| arg.inspect }.join(', ')}).localtime" define_method(gen_test_name(tz)) { with_tz(tz) { t = nil @@ -173,7 +188,7 @@ class TestTimeTZ < Test::Unit::TestCase } } } - sample.group_by {|tz, _, _, _| tz }.each {|tz, a| + group_by(sample) {|tz, _, _, _| tz }.each {|tz, a| a.each_with_index {|(_, u, l, gmtoff), i| expected = "%04d-%02d-%02d %02d:%02d:%02d %s" % (l+[format_gmtoff(gmtoff)]) monotonic_to_past = i == 0 || (a[i-1][2] <=> l) < 0 -- cgit v1.2.3