diff options
Diffstat (limited to 'test/date')
| -rw-r--r-- | test/date/test_date_conv.rb | 20 | ||||
| -rw-r--r-- | test/date/test_date_parse.rb | 26 | ||||
| -rw-r--r-- | test/date/test_date_strptime.rb | 15 |
3 files changed, 41 insertions, 20 deletions
diff --git a/test/date/test_date_conv.rb b/test/date/test_date_conv.rb index 772fbee9a4..8d81084435 100644 --- a/test/date/test_date_conv.rb +++ b/test/date/test_date_conv.rb @@ -82,21 +82,17 @@ class TestDateConv < Test::Unit::TestCase assert_equal([1582, 10, 13, 1, 2, 3, 456789], [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.usec]) - if Time.allocate.respond_to?(:nsec) - d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123.to_r/86400000000000 - t = d.to_time.utc - assert_equal([2004, 9, 19, 1, 2, 3, 456789123], - [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.nsec]) - end + d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123.to_r/86400000000000 + t = d.to_time.utc + assert_equal([2004, 9, 19, 1, 2, 3, 456789123], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.nsec]) # TruffleRuby does not support more than nanoseconds unless RUBY_ENGINE == 'truffleruby' - if Time.allocate.respond_to?(:subsec) - d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123456789123.to_r/86400000000000000000000 - t = d.to_time.utc - assert_equal([2004, 9, 19, 1, 2, 3, Rational(456789123456789123,1000000000000000000)], - [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.subsec]) - end + d = DateTime.new(2004, 9, 19, 1, 2, 3, 0) + 456789123456789123.to_r/86400000000000000000000 + t = d.to_time.utc + assert_equal([2004, 9, 19, 1, 2, 3, Rational(456789123456789123,1000000000000000000)], + [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.subsec]) end end diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb index cc29771cf8..8308f258d5 100644 --- a/test/date/test_date_parse.rb +++ b/test/date/test_date_parse.rb @@ -544,6 +544,8 @@ class TestDateParse < Test::Unit::TestCase h = Date._parse('') assert_equal({}, h) + + assert_raise(TypeError) {Date._parse(nil)} end def test_parse @@ -589,13 +591,7 @@ class TestDateParse < Test::Unit::TestCase end def test__parse_too_long_year - # Math.log10 does not support so big numbers like 10^100_000 on TruffleRuby - unless RUBY_ENGINE == 'truffleruby' - str = "Jan 1" + "0" * 100_000 - h = EnvUtil.timeout(3) {Date._parse(str, limit: 100_010)} - assert_equal(100_000, Math.log10(h[:year])) - assert_equal(1, h[:mon]) - end + omit 'transient' if RUBY_ENGINE == 'truffleruby' str = "Jan - 1" + "0" * 100_000 h = EnvUtil.timeout(3) {Date._parse(str, limit: 100_010)} @@ -1304,4 +1300,20 @@ class TestDateParse < Test::Unit::TestCase assert_raise(ArgumentError) { Date._parse("Jan " + "9" * 1000000) } end + + def test_string_argument + s = '2001-02-03T04:05:06Z' + obj = Class.new(Struct.new(:to_str, :count)) do + def to_str + self.count +=1 + super + end + end.new(s, 0) + + all_assertions_foreach(nil, :_parse, :_iso8601, :_rfc3339, :_xmlschema) do |m| + obj.count = 0 + assert_not_equal({}, Date.__send__(m, obj)) + assert_equal(1, obj.count) + end + end end diff --git a/test/date/test_date_strptime.rb b/test/date/test_date_strptime.rb index 4efe1a47d0..6aa7db292d 100644 --- a/test/date/test_date_strptime.rb +++ b/test/date/test_date_strptime.rb @@ -517,7 +517,20 @@ class TestDateStrptime < Test::Unit::TestCase d = DateTime.strptime('9000 +0200', '%Q %z') assert_equal([1970, 1, 1, 2, 0, 9], [d.year, d.mon, d.mday, d.hour, d.min, d.sec]) assert_equal(Rational(2, 24), d.offset) - end + def test_format_modified + str = " " * 100 + fmt = Struct.new(:str) { + def to_str + str << "2026-06-01" << " "*100 + " %F " + end + }.new(str) + d = Date._strptime(str, fmt) + assert_not_nil(d) + assert_equal(2026, d[:year]) + assert_equal(6, d[:mon]) + assert_equal(1, d[:mday]) + end end |
