summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2021-11-24 09:07:47 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2021-11-24 09:07:47 +0000
commit1fbf663b00bf1bdde4ebbbf0875dd7d37b0d90c6 (patch)
treeb4e31c49102e8916d18192fdfd065e71e22f43cf /test
parent95ba9053e20ad8d113af37b3f1f4cbfff1f6a8f1 (diff)
Merge date-2.0.2
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/date/test_date_parse.rb164
-rw-r--r--test/date/test_date_strftime.rb7
2 files changed, 73 insertions, 98 deletions
diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb
index e17fd3eb25..5bc2cebf82 100644
--- a/test/date/test_date_parse.rb
+++ b/test/date/test_date_parse.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require 'test/unit'
require 'date'
+require 'timeout'
class TestDateParse < Test::Unit::TestCase
@@ -121,8 +122,6 @@ class TestDateParse < Test::Unit::TestCase
[['S40.05.23T23:55:21-09:00',false],[1965,5,23,23,55,21,'-09:00',-9*3600,nil], __LINE__],
[['H11.05.23 23:55:21Z',false],[1999,5,23,23,55,21,'Z',0,nil], __LINE__],
[['H11.05.23T23:55:21Z',false],[1999,5,23,23,55,21,'Z',0,nil], __LINE__],
- [['H31.04.30 23:55:21Z',false],[2019,4,30,23,55,21,'Z',0,nil], __LINE__],
- [['H31.04.30T23:55:21Z',false],[2019,4,30,23,55,21,'Z',0,nil], __LINE__],
# ofx date
[['19990523235521',false],[1999,5,23,23,55,21,nil,nil,nil], __LINE__],
@@ -418,14 +417,7 @@ class TestDateParse < Test::Unit::TestCase
a[1] = -1
a[2] = h[:yday]
end
- l = format('<failed at line %d>', l)
- assert_equal(y, a, l)
- if y[6]
- h = Date._parse(x[0].dup.taint, *x[1..-1])
- assert_equal(y[6], h[:zone], l)
- assert_equal(y[6].encoding, h[:zone].encoding, l)
- assert_predicate(h[:zone], :tainted?, l)
- end
+ assert_equal(y, a, format('<failed at line %d>', l))
end
end
@@ -832,6 +824,13 @@ class TestDateParse < Test::Unit::TestCase
h = Date._iso8601('')
assert_equal({}, h)
+
+ h = Date._iso8601(nil)
+ assert_equal({}, h)
+
+ h = Date._iso8601('01-02-03T04:05:06Z'.to_sym)
+ assert_equal([2001, 2, 3, 4, 5, 6, 0],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test__rfc3339
@@ -847,6 +846,13 @@ class TestDateParse < Test::Unit::TestCase
h = Date._rfc3339('')
assert_equal({}, h)
+
+ h = Date._rfc3339(nil)
+ assert_equal({}, h)
+
+ h = Date._rfc3339('2001-02-03T04:05:06Z'.to_sym)
+ assert_equal([2001, 2, 3, 4, 5, 6, 0],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test__xmlschema
@@ -929,6 +935,13 @@ class TestDateParse < Test::Unit::TestCase
h = Date._xmlschema('')
assert_equal({}, h)
+
+ h = Date._xmlschema(nil)
+ assert_equal({}, h)
+
+ h = Date._xmlschema('2001-02-03'.to_sym)
+ assert_equal([2001, 2, 3, nil, nil, nil, nil],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test__rfc2822
@@ -961,6 +974,13 @@ class TestDateParse < Test::Unit::TestCase
h = Date._rfc2822('')
assert_equal({}, h)
+
+ h = Date._rfc2822(nil)
+ assert_equal({}, h)
+
+ h = Date._rfc2822('Sat, 3 Feb 2001 04:05:06 UT'.to_sym)
+ assert_equal([2001, 2, 3, 4, 5, 6, 0],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test__httpdate
@@ -981,6 +1001,13 @@ class TestDateParse < Test::Unit::TestCase
h = Date._httpdate('')
assert_equal({}, h)
+
+ h = Date._httpdate(nil)
+ assert_equal({}, h)
+
+ h = Date._httpdate('Sat, 03 Feb 2001 04:05:06 GMT'.to_sym)
+ assert_equal([2001, 2, 3, 4, 5, 6, 0],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test__jisx0301
@@ -993,15 +1020,6 @@ class TestDateParse < Test::Unit::TestCase
h = Date._jisx0301('S63.02.03')
assert_equal([1988, 2, 3, nil, nil, nil, nil],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('H31.04.30')
- assert_equal([2019, 4, 30, nil, nil, nil, nil],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('H31.05.01')
- assert_equal([2019, 5, 1, nil, nil, nil, nil],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('R01.05.01')
- assert_equal([2019, 5, 1, nil, nil, nil, nil],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
h = Date._jisx0301('H13.02.03T04:05:06')
assert_equal([2001, 2, 3, 4, 5, 6, nil],
@@ -1016,47 +1034,15 @@ class TestDateParse < Test::Unit::TestCase
assert_equal([2001, 2, 3, 4, 5, 6, 3600],
h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('H31.04.30T04:05:06')
- assert_equal([2019, 4, 30, 4, 5, 6, nil],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('H31.04.30T04:05:06,07')
- assert_equal([2019, 4, 30, 4, 5, 6, nil],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('H31.04.30T04:05:06Z')
- assert_equal([2019, 4, 30, 4, 5, 6, 0],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('H31.04.30T04:05:06.07+0100')
- assert_equal([2019, 4, 30, 4, 5, 6, 3600],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
-
- h = Date._jisx0301('H31.05.01T04:05:06')
- assert_equal([2019, 5, 1, 4, 5, 6, nil],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('H31.05.01T04:05:06,07')
- assert_equal([2019, 5, 1, 4, 5, 6, nil],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('H31.05.01T04:05:06Z')
- assert_equal([2019, 5, 1, 4, 5, 6, 0],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('H31.05.01T04:05:06.07+0100')
- assert_equal([2019, 5, 1, 4, 5, 6, 3600],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
-
- h = Date._jisx0301('R01.05.01T04:05:06')
- assert_equal([2019, 5, 1, 4, 5, 6, nil],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('R01.05.01T04:05:06,07')
- assert_equal([2019, 5, 1, 4, 5, 6, nil],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('R01.05.01T04:05:06Z')
- assert_equal([2019, 5, 1, 4, 5, 6, 0],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
- h = Date._jisx0301('R01.05.01T04:05:06.07+0100')
- assert_equal([2019, 5, 1, 4, 5, 6, 3600],
- h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
-
h = Date._jisx0301('')
assert_equal({}, h)
+
+ h = Date._jisx0301(nil)
+ assert_equal({}, h)
+
+ h = Date._jisx0301('H13.02.03T04:05:06.07+0100'.to_sym)
+ assert_equal([2001, 2, 3, 4, 5, 6, 3600],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test_iso8601
@@ -1140,33 +1126,9 @@ class TestDateParse < Test::Unit::TestCase
assert_equal(Date.new(2001,2,3), d)
assert_equal(Date::ITALY + 10, d.start)
- d = Date.jisx0301('H31.04.30', Date::ITALY + 10)
- assert_equal(Date.new(2019,4,30), d)
- assert_equal(Date::ITALY + 10, d.start)
-
- d = Date.jisx0301('H31.05.01', Date::ITALY + 10)
- assert_equal(Date.new(2019,5,1), d)
- assert_equal(Date::ITALY + 10, d.start)
-
- d = Date.jisx0301('R01.05.01', Date::ITALY + 10)
- assert_equal(Date.new(2019,5,1), d)
- assert_equal(Date::ITALY + 10, d.start)
-
d = DateTime.jisx0301('H13.02.03T04:05:06+07:00', Date::ITALY + 10)
assert_equal(DateTime.new(2001,2,3,4,5,6,'+07:00'), d)
assert_equal(Date::ITALY + 10, d.start)
-
- d = DateTime.jisx0301('H31.04.30T04:05:06+07:00', Date::ITALY + 10)
- assert_equal(DateTime.new(2019,4,30,4,5,6,'+07:00'), d)
- assert_equal(Date::ITALY + 10, d.start)
-
- d = DateTime.jisx0301('H31.05.01T04:05:06+07:00', Date::ITALY + 10)
- assert_equal(DateTime.new(2019,5,1,4,5,6,'+07:00'), d)
- assert_equal(Date::ITALY + 10, d.start)
-
- d = DateTime.jisx0301('R01.05.01T04:05:06+07:00', Date::ITALY + 10)
- assert_equal(DateTime.new(2019,5,1,4,5,6,'+07:00'), d)
- assert_equal(Date::ITALY + 10, d.start)
end
def test_given_string
@@ -1201,16 +1163,34 @@ class TestDateParse < Test::Unit::TestCase
s0 = s.dup
assert_not_equal({}, Date._jisx0301(s))
assert_equal(s0, s)
-
- s = 'H31.04.30T04:05:06,07Z'
- s0 = s.dup
- assert_not_equal({}, Date._jisx0301(s))
- assert_equal(s0, s)
-
- s = 'H31.05.01T04:05:06,07Z'
- s0 = s.dup
- assert_not_equal({}, Date._jisx0301(s))
- assert_equal(s0, s)
end
+ def test_length_limit
+ assert_raise(ArgumentError) { Date._parse("1" * 1000) }
+ assert_raise(ArgumentError) { Date._iso8601("1" * 1000) }
+ assert_raise(ArgumentError) { Date._rfc3339("1" * 1000) }
+ assert_raise(ArgumentError) { Date._xmlschema("1" * 1000) }
+ assert_raise(ArgumentError) { Date._rfc2822("1" * 1000) }
+ assert_raise(ArgumentError) { Date._rfc822("1" * 1000) }
+ assert_raise(ArgumentError) { Date._jisx0301("1" * 1000) }
+
+ assert_raise(ArgumentError) { Date.parse("1" * 1000) }
+ assert_raise(ArgumentError) { Date.iso8601("1" * 1000) }
+ assert_raise(ArgumentError) { Date.rfc3339("1" * 1000) }
+ assert_raise(ArgumentError) { Date.xmlschema("1" * 1000) }
+ assert_raise(ArgumentError) { Date.rfc2822("1" * 1000) }
+ assert_raise(ArgumentError) { Date.rfc822("1" * 1000) }
+ assert_raise(ArgumentError) { Date.jisx0301("1" * 1000) }
+
+ assert_raise(ArgumentError) { DateTime.parse("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.iso8601("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.rfc3339("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.xmlschema("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.rfc2822("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.rfc822("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.jisx0301("1" * 1000) }
+
+ assert_raise(ArgumentError) { Date._parse("Jan " + "9" * 1000000) }
+ assert_raise(Timeout::Error) { Timeout.timeout(1) { Date._parse("Jan " + "9" * 1000000, limit: nil) } }
+ end
end
diff --git a/test/date/test_date_strftime.rb b/test/date/test_date_strftime.rb
index dc237a909d..a33eaa340f 100644
--- a/test/date/test_date_strftime.rb
+++ b/test/date/test_date_strftime.rb
@@ -406,8 +406,6 @@ class TestDateStrftime < Test::Unit::TestCase
assert_equal('S64.01.07', Date.parse('1989-01-07').jisx0301)
assert_equal('H01.01.08', Date.parse('1989-01-08').jisx0301)
assert_equal('H18.09.01', Date.parse('2006-09-01').jisx0301)
- assert_equal('H31.04.30', Date.parse('2019-04-30').jisx0301)
- assert_equal('R01.05.01', Date.parse('2019-05-01').jisx0301)
%w(M06.01.01
M45.07.29
@@ -416,10 +414,7 @@ class TestDateStrftime < Test::Unit::TestCase
S01.12.25
S64.01.07
H01.01.08
- H18.09.01
- H31.04.30
- R01.05.01
- ).each do |s|
+ H18.09.01).each do |s|
assert_equal(s, Date.parse(s).jisx0301)
end