summaryrefslogtreecommitdiff
path: root/test/ruby/test_time_tz.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-10 15:15:47 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-10 15:15:47 +0000
commit670b62a61c9e26a34dce43fe1e6a50ad57c92923 (patch)
tree5fd26d52abec95723c9266d39c2414d84c06fa49 /test/ruby/test_time_tz.rb
parent9c2a96885560cfb85e0f68793fd43dc71e7a467c (diff)
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
Diffstat (limited to 'test/ruby/test_time_tz.rb')
-rw-r--r--test/ruby/test_time_tz.rb27
1 files changed, 21 insertions, 6 deletions
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