diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-04-21 14:56:59 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-04-21 14:56:59 +0000 |
commit | 3bc16f62c1fb6225b3f6cb96b62f78e44636aae4 (patch) | |
tree | 7861dbce5046671694894b080ca6d0e0d15c6175 /test | |
parent | 143846ad369eba2324e13743ff03bcf50d56c942 (diff) | |
download | ruby-3bc16f62c1fb6225b3f6cb96b62f78e44636aae4.tar.gz |
* time.c: remove time_t restriction from Time class.
* timev.h: new file to define struct vtm.
* strftime.c: format struct vtm instead of struct tm.
* ext/syck/rubyext.c (mktime_do): don't use time_t;
[ruby-dev:38191]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_time.rb | 62 | ||||
-rw-r--r-- | test/yaml/test_yaml.rb | 2 |
2 files changed, 43 insertions, 21 deletions
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index c159ce724c..d9eaea6998 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -1,5 +1,6 @@ require 'test/unit' require 'rational' +require 'delegate' require 'timeout' require 'delegate' @@ -101,31 +102,47 @@ class TestTime < Test::Unit::TestCase end def test_at + assert_equal(100000, Time.at("0.1").usec) + assert_equal(10000, Time.at("0.01").usec) + assert_equal(1000, Time.at("0.001").usec) + assert_equal(100, Time.at("0.0001").usec) + assert_equal(10, Time.at("0.00001").usec) + assert_equal(1, Time.at("0.000001").usec) + assert_equal(100000000, Time.at("0.1").nsec) + assert_equal(10000000, Time.at("0.01").nsec) + assert_equal(1000000, Time.at("0.001").nsec) + assert_equal(100000, Time.at("0.0001").nsec) + assert_equal(10000, Time.at("0.00001").nsec) + assert_equal(1000, Time.at("0.000001").nsec) + assert_equal(100, Time.at("0.0000001").nsec) + assert_equal(10, Time.at("0.00000001").nsec) + assert_equal(1, Time.at("0.000000001").nsec) assert_equal(100000, Time.at(0.1).usec) assert_equal(10000, Time.at(0.01).usec) assert_equal(1000, Time.at(0.001).usec) assert_equal(100, Time.at(0.0001).usec) assert_equal(10, Time.at(0.00001).usec) - assert_equal(1, Time.at(0.000001).usec) + assert_equal(3, Time.at(0.000003).usec) assert_equal(100000000, Time.at(0.1).nsec) assert_equal(10000000, Time.at(0.01).nsec) assert_equal(1000000, Time.at(0.001).nsec) assert_equal(100000, Time.at(0.0001).nsec) assert_equal(10000, Time.at(0.00001).nsec) - assert_equal(1000, Time.at(0.000001).nsec) - assert_equal(100, Time.at(0.0000001).nsec) + assert_equal(3000, Time.at(0.000003).nsec) + assert_equal(199, Time.at(0.0000002).nsec) assert_equal(10, Time.at(0.00000001).nsec) assert_equal(1, Time.at(0.000000001).nsec) + assert_equal(0, Time.at(1e-10).nsec) assert_equal(0, Time.at(4e-10).nsec) - assert_equal(1, Time.at(6e-10).nsec) + assert_equal(0, Time.at(6e-10).nsec) assert_equal(1, Time.at(14e-10).nsec) - assert_equal(2, Time.at(16e-10).nsec) + assert_equal(1, Time.at(16e-10).nsec) if negative_time_t? - assert_equal(0, Time.at(-1e-10).nsec) - assert_equal(0, Time.at(-4e-10).nsec) + assert_equal(999999999, Time.at(-1e-10).nsec) + assert_equal(999999999, Time.at(-4e-10).nsec) assert_equal(999999999, Time.at(-6e-10).nsec) - assert_equal(999999999, Time.at(-14e-10).nsec) + assert_equal(999999998, Time.at(-14e-10).nsec) assert_equal(999999998, Time.at(-16e-10).nsec) end end @@ -142,7 +159,7 @@ class TestTime < Test::Unit::TestCase end def test_utc_subsecond - assert_equal(100000, Time.utc(2007,1,1,0,0,1.1).usec) + assert_equal(500000, Time.utc(2007,1,1,0,0,1.5).usec) assert_equal(100000, Time.utc(2007,1,1,0,0,Rational(11,10)).usec) end @@ -189,14 +206,14 @@ class TestTime < Test::Unit::TestCase def test_at3 assert_equal(T2000, Time.at(T2000)) - assert_raise(RangeError) do - Time.at(2**31-1, 1_000_000) - Time.at(2**63-1, 1_000_000) - end - assert_raise(RangeError) do - Time.at(-2**31, -1_000_000) - Time.at(-2**63, -1_000_000) - end +# assert_raise(RangeError) do +# Time.at(2**31-1, 1_000_000) +# Time.at(2**63-1, 1_000_000) +# end +# assert_raise(RangeError) do +# Time.at(-2**31, -1_000_000) +# Time.at(-2**63, -1_000_000) +# end end def test_utc_or_local @@ -216,10 +233,15 @@ class TestTime < Test::Unit::TestCase end assert_raise(ArgumentError) { Time.gm(2000, 1, 1, 0, 0, -(2**31), :foo, :foo) } o = Object.new - def o.divmod(x); nil; end + def o.to_r; nil; end assert_raise(TypeError) { Time.gm(2000, 1, 1, 0, 0, o, :foo, :foo) } - def o.divmod(x); [-1, 0]; end - assert_raise(ArgumentError) { Time.gm(2000, 1, 1, 0, 0, o, :foo, :foo) } + def o.to_r; ""; end + assert_raise(TypeError) { Time.gm(2000, 1, 1, 0, 0, o, :foo, :foo) } + def o.to_r; Rational(11); end + assert_equal(11, Time.gm(2000, 1, 1, 0, 0, o).sec) + o = Object.new + def o.to_int; 10; end + assert_equal(10, Time.gm(2000, 1, 1, 0, 0, o).sec) assert_raise(ArgumentError) { Time.gm(2000, 13) } t = Time.local(2000) diff --git a/test/yaml/test_yaml.rb b/test/yaml/test_yaml.rb index 4f612ebaef..8c7aef3dcd 100644 --- a/test/yaml/test_yaml.rb +++ b/test/yaml/test_yaml.rb @@ -48,7 +48,7 @@ class YAML_Unit_Tests < Test::Unit::TestCase # Make a time with the time zone # def mktime( year, mon, day, hour, min, sec, usec, zone = "Z" ) - usec = usec.to_s.to_f * 1000000 + usec = Rational(usec.to_s) * 1000000 val = Time::utc( year.to_i, mon.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i, usec ) if zone != "Z" hour = zone[0,3].to_i * 3600 |