mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_time_tz.rb: Fix test error with tzdata-2014g.
[ruby-core:65058] [Bug #10245] Reported by Vit Ondruch. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4d10c2b91d
commit
565fef8210
2 changed files with 77 additions and 27 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Sep 22 12:10:29 2014 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* test/ruby/test_time_tz.rb: Fix test error with tzdata-2014g.
|
||||
[ruby-core:65058] [Bug #10245] Reported by Vit Ondruch.
|
||||
|
||||
Mon Sep 22 09:28:43 2014 Eric Wong <e@80x24.org>
|
||||
|
||||
* ext/socket/ancdata.c ({send,recv}msg_args_struct): 24 => 16 bytes
|
||||
|
|
|
@ -206,35 +206,42 @@ class TestTimeTZ < Test::Unit::TestCase
|
|||
s.sub(/gen_/) { "gen" + "_#{hint}_".gsub(/[^0-9A-Za-z]+/, '_') }
|
||||
end
|
||||
|
||||
def self.parse_zdump_line(line)
|
||||
return nil if /\A\#/ =~ line || /\A\s*\z/ =~ line
|
||||
if /\A(\S+)\s+
|
||||
\S+\s+(\S+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d)\s+(\d+)\s+UTC?
|
||||
\s+=\s+
|
||||
\S+\s+(\S+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d)\s+(\d+)\s+\S+
|
||||
\s+isdst=\d+\s+gmtoff=(-?\d+)\n
|
||||
\z/x !~ line
|
||||
raise "unexpected zdump line: #{line.inspect}"
|
||||
end
|
||||
tz, u_mon, u_day, u_hour, u_min, u_sec, u_year,
|
||||
l_mon, l_day, l_hour, l_min, l_sec, l_year, gmtoff = $~.captures
|
||||
u_year = u_year.to_i
|
||||
u_mon = MON2NUM[u_mon]
|
||||
u_day = u_day.to_i
|
||||
u_hour = u_hour.to_i
|
||||
u_min = u_min.to_i
|
||||
u_sec = u_sec.to_i
|
||||
l_year = l_year.to_i
|
||||
l_mon = MON2NUM[l_mon]
|
||||
l_day = l_day.to_i
|
||||
l_hour = l_hour.to_i
|
||||
l_min = l_min.to_i
|
||||
l_sec = l_sec.to_i
|
||||
gmtoff = gmtoff.to_i
|
||||
[tz,
|
||||
[u_year, u_mon, u_day, u_hour, u_min, u_sec],
|
||||
[l_year, l_mon, l_day, l_hour, l_min, l_sec],
|
||||
gmtoff]
|
||||
end
|
||||
|
||||
def self.gen_zdump_test(data)
|
||||
sample = []
|
||||
data.each_line {|line|
|
||||
next if /\A\#/ =~ line || /\A\s*\z/ =~ line
|
||||
/\A(\S+)\s+
|
||||
\S+\s+(\S+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d)\s+(\d+)\s+UTC
|
||||
\s+=\s+
|
||||
\S+\s+(\S+)\s+(\d+)\s+(\d\d):(\d\d):(\d\d)\s+(\d+)\s+\S+
|
||||
\s+isdst=\d+\s+gmtoff=(-?\d+)\n
|
||||
\z/x =~ line
|
||||
tz, u_mon, u_day, u_hour, u_min, u_sec, u_year,
|
||||
l_mon, l_day, l_hour, l_min, l_sec, l_year, gmtoff = $~.captures
|
||||
u_year = u_year.to_i
|
||||
u_mon = MON2NUM[u_mon]
|
||||
u_day = u_day.to_i
|
||||
u_hour = u_hour.to_i
|
||||
u_min = u_min.to_i
|
||||
u_sec = u_sec.to_i
|
||||
l_year = l_year.to_i
|
||||
l_mon = MON2NUM[l_mon]
|
||||
l_day = l_day.to_i
|
||||
l_hour = l_hour.to_i
|
||||
l_min = l_min.to_i
|
||||
l_sec = l_sec.to_i
|
||||
gmtoff = gmtoff.to_i
|
||||
sample << [tz,
|
||||
[u_year, u_mon, u_day, u_hour, u_min, u_sec],
|
||||
[l_year, l_mon, l_day, l_hour, l_min, l_sec],
|
||||
gmtoff]
|
||||
s = parse_zdump_line(line)
|
||||
sample << s if s
|
||||
}
|
||||
sample.each {|tz, u, l, gmtoff|
|
||||
expected_utc = "%04d-%02d-%02d %02d:%02d:%02d UTC" % u
|
||||
|
@ -255,6 +262,7 @@ class TestTimeTZ < Test::Unit::TestCase
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
group_by(sample) {|tz, _, _, _| tz }.each {|tz, a|
|
||||
a.each_with_index {|(_, _, l, gmtoff), i|
|
||||
expected = "%04d-%02d-%02d %02d:%02d:%02d %s" % (l+[format_gmtoff(gmtoff)])
|
||||
|
@ -355,7 +363,44 @@ right/America/Los_Angeles Wed Dec 31 23:59:60 2008 UTC = Wed Dec 31 15:59:60 20
|
|||
right/Europe/Paris Fri Jun 30 23:59:60 1972 UTC = Sat Jul 1 00:59:60 1972 CET isdst=0 gmtoff=3600
|
||||
right/Europe/Paris Wed Dec 31 23:59:60 2008 UTC = Thu Jan 1 00:59:60 2009 CET isdst=0 gmtoff=3600
|
||||
End
|
||||
gen_zdump_test <<'End' if has_lisbon_tz
|
||||
|
||||
def self.gen_variational_zdump_test(hint, data)
|
||||
sample = []
|
||||
data.each_line {|line|
|
||||
s = parse_zdump_line(line)
|
||||
sample << s if s
|
||||
}
|
||||
|
||||
define_method(gen_test_name(hint)) {
|
||||
results = []
|
||||
sample.each {|tz, u, l, gmtoff|
|
||||
expected_utc = "%04d-%02d-%02d %02d:%02d:%02d UTC" % u
|
||||
expected = "%04d-%02d-%02d %02d:%02d:%02d %s" % (l+[format_gmtoff(gmtoff)])
|
||||
mesg_utc = "TZ=#{tz} Time.utc(#{u.map {|arg| arg.inspect }.join(', ')})"
|
||||
mesg = "#{mesg_utc}.localtime"
|
||||
with_tz(tz) {
|
||||
t = nil
|
||||
assert_nothing_raised(mesg) { t = Time.utc(*u) }
|
||||
assert_equal(expected_utc, time_to_s(t), mesg_utc)
|
||||
assert_nothing_raised(mesg) { t.localtime }
|
||||
|
||||
results << [
|
||||
expected == time_to_s(t),
|
||||
gmtoff == t.gmtoff,
|
||||
format_gmtoff(gmtoff) == t.strftime("%z"),
|
||||
format_gmtoff(gmtoff, true) == t.strftime("%:z"),
|
||||
format_gmtoff2(gmtoff) == t.strftime("%::z")
|
||||
]
|
||||
}
|
||||
}
|
||||
assert_includes(results, [true, true, true, true, true])
|
||||
}
|
||||
end
|
||||
|
||||
# tzdata-2014g fixed the offset for lisbon from -0:36:32 to -0:36:45.
|
||||
# [ruby-core:65058] [Bug #10245]
|
||||
gen_variational_zdump_test "lisbon", <<'End' if has_lisbon_tz
|
||||
Europe/Lisbon Mon Jan 1 00:36:31 1912 UTC = Sun Dec 31 23:59:59 1911 LMT isdst=0 gmtoff=-2192
|
||||
Europe/Lisbon Mon Jan 1 00:36:44 1912 UT = Sun Dec 31 23:59:59 1911 LMT isdst=0 gmtoff=-2205
|
||||
End
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue