summaryrefslogtreecommitdiff
path: root/test/date/test_date_parse.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/date/test_date_parse.rb')
-rw-r--r--test/date/test_date_parse.rb47
1 files changed, 25 insertions, 22 deletions
diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb
index 0b4a383630..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,10 +591,7 @@ class TestDateParse < Test::Unit::TestCase
end
def test__parse_too_long_year
- 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])
+ omit 'transient' if RUBY_ENGINE == 'truffleruby'
str = "Jan - 1" + "0" * 100_000
h = EnvUtil.timeout(3) {Date._parse(str, limit: 100_010)}
@@ -867,9 +866,7 @@ class TestDateParse < Test::Unit::TestCase
h = Date._iso8601(nil)
assert_equal({}, h)
- h = assert_deprecated_warn {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))
+ assert_raise(TypeError) {Date._iso8601('01-02-03T04:05:06Z'.to_sym)}
end
def test__rfc3339
@@ -889,9 +886,7 @@ class TestDateParse < Test::Unit::TestCase
h = Date._rfc3339(nil)
assert_equal({}, h)
- h = assert_deprecated_warn {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))
+ assert_raise(TypeError) {Date._rfc3339('2001-02-03T04:05:06Z'.to_sym)}
end
def test__xmlschema
@@ -978,9 +973,7 @@ class TestDateParse < Test::Unit::TestCase
h = Date._xmlschema(nil)
assert_equal({}, h)
- h = assert_deprecated_warn {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))
+ assert_raise(TypeError) {Date._xmlschema('2001-02-03'.to_sym)}
end
def test__rfc2822
@@ -1017,9 +1010,7 @@ class TestDateParse < Test::Unit::TestCase
h = Date._rfc2822(nil)
assert_equal({}, h)
- h = assert_deprecated_warn {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))
+ assert_raise(TypeError) {Date._rfc2822('Sat, 3 Feb 2001 04:05:06 UT'.to_sym)}
end
def test__httpdate
@@ -1044,9 +1035,7 @@ class TestDateParse < Test::Unit::TestCase
h = Date._httpdate(nil)
assert_equal({}, h)
- h = assert_deprecated_warn {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))
+ assert_raise(TypeError) {Date._httpdate('Sat, 03 Feb 2001 04:05:06 GMT'.to_sym)}
end
def test__jisx0301
@@ -1127,9 +1116,7 @@ class TestDateParse < Test::Unit::TestCase
h = Date._jisx0301(nil)
assert_equal({}, h)
- h = assert_deprecated_warn {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))
+ assert_raise(TypeError) {Date._jisx0301('H13.02.03T04:05:06.07+0100'.to_sym)}
end
def test_iso8601
@@ -1313,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