[前][次][番号順一覧][スレッド一覧]

ruby-changes:16289

From: akr <ko1@a...>
Date: Fri, 11 Jun 2010 00:15:54 +0900 (JST)
Subject: [ruby-changes:16289] Ruby:r28258 (trunk): make it runnable by ruby 1.8.6.

akr	2010-06-11 00:15:47 +0900 (Fri, 11 Jun 2010)

  New Revision: 28258

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28258

  Log:
    make it runnable by ruby 1.8.6.

  Modified files:
    trunk/test/ruby/test_time_tz.rb

Index: test/ruby/test_time_tz.rb
===================================================================
--- test/ruby/test_time_tz.rb	(revision 28257)
+++ test/ruby/test_time_tz.rb	(revision 28258)
@@ -29,6 +29,19 @@
       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 @@
     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 @@
     "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 @@
     }
     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 @@
         }
       }
     }
-    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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]