b6bbea
From a92bb23525243ada0f8b63ccdfeafb385408524b Mon Sep 17 00:00:00 2001
b6bbea
From: akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
b6bbea
Date: Mon, 22 Sep 2014 03:12:23 +0000
b6bbea
Subject: [PATCH] * test/ruby/test_time_tz.rb: Fix test error with
b6bbea
 tzdata-2014g.   [ruby-core:65058] [Bug #10245] Reported by Vit Ondruch.
b6bbea
b6bbea
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
b6bbea
b6bbea
Conflicts:
b6bbea
	ChangeLog
b6bbea
	test/ruby/test_time_tz.rb
b6bbea
---
b6bbea
 ChangeLog                 |  5 +++
b6bbea
 test/ruby/test_time_tz.rb | 99 ++++++++++++++++++++++++++++++++++-------------
b6bbea
 2 files changed, 78 insertions(+), 26 deletions(-)
b6bbea
b6bbea
diff --git a/ChangeLog b/ChangeLog
b6bbea
index 6734f63..e760152 100644
b6bbea
--- a/ChangeLog
b6bbea
+++ b/ChangeLog
b6bbea
@@ -1,3 +1,8 @@
b6bbea
+Mon Sep 22 12:10:29 2014  Tanaka Akira  <akr@fsij.org>
b6bbea
+
b6bbea
+	* test/ruby/test_time_tz.rb: Fix test error with tzdata-2014g.
b6bbea
+	  [ruby-core:65058] [Bug #10245] Reported by Vit Ondruch.
b6bbea
+
b6bbea
 Fri Jan  3 10:43:57 2014  Aman Gupta <ruby@tmm1.net>
b6bbea
 
b6bbea
 	* test/net/imap/cacert.pem: generate new CA cert, since the last one
b6bbea
diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb
b6bbea
index bb69af8..626ecd1 100644
b6bbea
--- a/test/ruby/test_time_tz.rb
b6bbea
+++ b/test/ruby/test_time_tz.rb
b6bbea
@@ -200,35 +200,42 @@ class TestTimeTZ < Test::Unit::TestCase
b6bbea
     s.sub(/gen_/) { "gen" + "_#{hint}_".gsub(/[^0-9A-Za-z]+/, '_') }
b6bbea
   end
b6bbea
 
b6bbea
+  def self.parse_zdump_line(line)
b6bbea
+    return nil if /\A\#/ =~ line || /\A\s*\z/ =~ line
b6bbea
+    if /\A(\S+)\s+
b6bbea
+        \S+\s+(\S+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d)\s+(\d+)\s+UTC?
b6bbea
+        \s+=\s+
b6bbea
+        \S+\s+(\S+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d)\s+(\d+)\s+\S+
b6bbea
+        \s+isdst=\d+\s+gmtoff=(-?\d+)\n
b6bbea
+        \z/x !~ line
b6bbea
+      raise "unexpected zdump line: #{line.inspect}"
b6bbea
+    end
b6bbea
+    tz, u_mon, u_day, u_hour, u_min, u_sec, u_year,
b6bbea
+      l_mon, l_day, l_hour, l_min, l_sec, l_year, gmtoff = $~.captures
b6bbea
+    u_year = u_year.to_i
b6bbea
+    u_mon = MON2NUM[u_mon]
b6bbea
+    u_day = u_day.to_i
b6bbea
+    u_hour = u_hour.to_i
b6bbea
+    u_min = u_min.to_i
b6bbea
+    u_sec = u_sec.to_i
b6bbea
+    l_year = l_year.to_i
b6bbea
+    l_mon = MON2NUM[l_mon]
b6bbea
+    l_day = l_day.to_i
b6bbea
+    l_hour = l_hour.to_i
b6bbea
+    l_min = l_min.to_i
b6bbea
+    l_sec = l_sec.to_i
b6bbea
+    gmtoff = gmtoff.to_i
b6bbea
+    [tz,
b6bbea
+     [u_year, u_mon, u_day, u_hour, u_min, u_sec],
b6bbea
+     [l_year, l_mon, l_day, l_hour, l_min, l_sec],
b6bbea
+     gmtoff]
b6bbea
+  end
b6bbea
+
b6bbea
   def self.gen_zdump_test(data)
b6bbea
     sample = []
b6bbea
     data.each_line {|line|
b6bbea
-      next if /\A\#/ =~ line || /\A\s*\z/ =~ line
b6bbea
-      /\A(\S+)\s+
b6bbea
-       \S+\s+(\S+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d)\s+(\d+)\s+UTC
b6bbea
-       \s+=\s+
b6bbea
-       \S+\s+(\S+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d)\s+(\d+)\s+\S+
b6bbea
-       \s+isdst=\d+\s+gmtoff=(-?\d+)\n
b6bbea
-       \z/x =~ line
b6bbea
-       tz, u_mon, u_day, u_hour, u_min, u_sec, u_year,
b6bbea
-         l_mon, l_day, l_hour, l_min, l_sec, l_year, gmtoff = $~.captures
b6bbea
-      u_year = u_year.to_i
b6bbea
-      u_mon = MON2NUM[u_mon]
b6bbea
-      u_day = u_day.to_i
b6bbea
-      u_hour = u_hour.to_i
b6bbea
-      u_min = u_min.to_i
b6bbea
-      u_sec = u_sec.to_i
b6bbea
-      l_year = l_year.to_i
b6bbea
-      l_mon = MON2NUM[l_mon]
b6bbea
-      l_day = l_day.to_i
b6bbea
-      l_hour = l_hour.to_i
b6bbea
-      l_min = l_min.to_i
b6bbea
-      l_sec = l_sec.to_i
b6bbea
-      gmtoff = gmtoff.to_i
b6bbea
-      sample << [tz,
b6bbea
-                 [u_year, u_mon, u_day, u_hour, u_min, u_sec],
b6bbea
-                 [l_year, l_mon, l_day, l_hour, l_min, l_sec],
b6bbea
-                 gmtoff]
b6bbea
+      s = parse_zdump_line(line)
b6bbea
+      sample << s if s
b6bbea
     }
b6bbea
     sample.each {|tz, u, l, gmtoff|
b6bbea
       expected_utc = "%04d-%02d-%02d %02d:%02d:%02d UTC" % u
b6bbea
@@ -249,6 +256,7 @@ class TestTimeTZ < Test::Unit::TestCase
b6bbea
         }
b6bbea
       }
b6bbea
     }
b6bbea
+
b6bbea
     group_by(sample) {|tz, _, _, _| tz }.each {|tz, a|
b6bbea
       a.each_with_index {|(_, u, l, gmtoff), i|
b6bbea
         expected = "%04d-%02d-%02d %02d:%02d:%02d %s" % (l+[format_gmtoff(gmtoff)])
b6bbea
@@ -348,6 +356,45 @@ right/America/Los_Angeles  Wed Dec 31 23:59:60 2008 UTC = Wed Dec 31 15:59:60 20
b6bbea
 #right/Asia/Tokyo  Sat Dec 31 23:59:60 2005 UTC = Sun Jan  1 08:59:60 2006 JST isdst=0 gmtoff=32400
b6bbea
 right/Europe/Paris  Fri Jun 30 23:59:60 1972 UTC = Sat Jul  1 00:59:60 1972 CET isdst=0 gmtoff=3600
b6bbea
 right/Europe/Paris  Wed Dec 31 23:59:60 2008 UTC = Thu Jan  1 00:59:60 2009 CET isdst=0 gmtoff=3600
b6bbea
+End
b6bbea
+
b6bbea
+  def self.gen_variational_zdump_test(hint, data)
b6bbea
+    sample = []
b6bbea
+    data.each_line {|line|
b6bbea
+      s = parse_zdump_line(line)
b6bbea
+      sample << s if s
b6bbea
+    }
b6bbea
+
b6bbea
+    define_method(gen_test_name(hint)) {
b6bbea
+      results = []
b6bbea
+      sample.each {|tz, u, l, gmtoff|
b6bbea
+        expected_utc = "%04d-%02d-%02d %02d:%02d:%02d UTC" % u
b6bbea
+        expected = "%04d-%02d-%02d %02d:%02d:%02d %s" % (l+[format_gmtoff(gmtoff)])
b6bbea
+        mesg_utc = "TZ=#{tz} Time.utc(#{u.map {|arg| arg.inspect }.join(', ')})"
b6bbea
+        mesg = "#{mesg_utc}.localtime"
b6bbea
+        with_tz(tz) {
b6bbea
+          t = nil
b6bbea
+          assert_nothing_raised(mesg) { t = Time.utc(*u) }
b6bbea
+          assert_equal(expected_utc, time_to_s(t), mesg_utc)
b6bbea
+          assert_nothing_raised(mesg) { t.localtime }
b6bbea
+
b6bbea
+          results << [
b6bbea
+            expected == time_to_s(t),
b6bbea
+            gmtoff == t.gmtoff,
b6bbea
+            format_gmtoff(gmtoff) == t.strftime("%z"),
b6bbea
+            format_gmtoff(gmtoff, true) == t.strftime("%:z"),
b6bbea
+            format_gmtoff2(gmtoff) == t.strftime("%::z")
b6bbea
+          ]
b6bbea
+        }
b6bbea
+      }
b6bbea
+      assert_includes(results, [true, true, true, true, true])
b6bbea
+    }
b6bbea
+  end
b6bbea
+
b6bbea
+  # tzdata-2014g fixed the offset for lisbon from -0:36:32 to -0:36:45.
b6bbea
+  # [ruby-core:65058] [Bug #10245]
b6bbea
+  gen_variational_zdump_test "lisbon", <<'End' if force_tz_test
b6bbea
 Europe/Lisbon  Mon Jan  1 00:36:31 1912 UTC = Sun Dec 31 23:59:59 1911 LMT isdst=0 gmtoff=-2192
b6bbea
+Europe/Lisbon  Mon Jan  1 00:36:44 1912 UT = Sun Dec 31 23:59:59 1911 LMT isdst=0 gmtoff=-2205
b6bbea
 End
b6bbea
 end
b6bbea
-- 
b6bbea
1.9.3
b6bbea