Add tests for to_s(:inspect)

This commit is contained in:
akinomaeni 2020-05-10 00:03:37 +09:00
parent 27cf6eced8
commit 6379f99c97
4 changed files with 17 additions and 7 deletions

View File

@ -28,6 +28,7 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal "February 21, 2005", date.to_s(:long)
assert_equal "February 21st, 2005", date.to_s(:long_ordinal)
assert_equal "2005-02-21", date.to_s(:db)
assert_equal "2005-02-21", date.to_s(:inspect)
assert_equal "21 Feb 2005", date.to_s(:rfc822)
assert_equal "2005-02-21", date.to_s(:iso8601)
end
@ -39,6 +40,7 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal "February 01, 2005", date.to_s(:long)
assert_equal "February 1st, 2005", date.to_s(:long_ordinal)
assert_equal "2005-02-01", date.to_s(:db)
assert_equal "2005-02-01", date.to_s(:inspect)
assert_equal "01 Feb 2005", date.to_s(:rfc822)
assert_equal "2005-02-01", date.to_s(:iso8601)
end

View File

@ -15,13 +15,14 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
def test_to_s
datetime = DateTime.new(2005, 2, 21, 14, 30, 0, 0)
assert_equal "2005-02-21 14:30:00", datetime.to_s(:db)
assert_equal "14:30", datetime.to_s(:time)
assert_equal "21 Feb 14:30", datetime.to_s(:short)
assert_equal "February 21, 2005 14:30", datetime.to_s(:long)
assert_equal "Mon, 21 Feb 2005 14:30:00 +0000", datetime.to_s(:rfc822)
assert_equal "February 21st, 2005 14:30", datetime.to_s(:long_ordinal)
assert_match(/^2005-02-21T14:30:00(Z|\+00:00)$/, datetime.to_s)
assert_equal "2005-02-21 14:30:00", datetime.to_s(:db)
assert_equal "2005-02-21 14:30:00.000000000 +0000", datetime.to_s(:inspect)
assert_equal "14:30", datetime.to_s(:time)
assert_equal "21 Feb 14:30", datetime.to_s(:short)
assert_equal "February 21, 2005 14:30", datetime.to_s(:long)
assert_equal "Mon, 21 Feb 2005 14:30:00 +0000", datetime.to_s(:rfc822)
assert_equal "February 21st, 2005 14:30", datetime.to_s(:long_ordinal)
assert_match(/^2005-02-21T14:30:00(Z|\+00:00)$/, datetime.to_s)
with_env_tz "US/Central" do
assert_equal "2009-02-05T14:30:05-06:00", DateTime.civil(2009, 2, 5, 14, 30, 5, Rational(-21600, 86400)).to_s(:iso8601)

View File

@ -562,6 +562,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal "February 21st, 2005 17:44", time.to_s(:long_ordinal)
with_env_tz "UTC" do
assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_s(:rfc822)
assert_equal "2005-02-21 17:44:30.123456789 +0000", time.to_s(:inspect)
end
with_env_tz "US/Central" do
assert_equal "Thu, 05 Feb 2009 14:30:05 -0600", Time.local(2009, 2, 5, 14, 30, 5).to_s(:rfc822)
@ -569,6 +570,8 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal "2009-02-05T14:30:05-06:00", Time.local(2009, 2, 5, 14, 30, 5).to_s(:iso8601)
assert_equal "2008-06-09T04:05:01-05:00", Time.local(2008, 6, 9, 4, 5, 1).to_s(:iso8601)
assert_equal "2009-02-05T14:30:05Z", Time.utc(2009, 2, 5, 14, 30, 5).to_s(:iso8601)
assert_equal "2009-02-05 14:30:05.000000000 -0600", Time.local(2009, 2, 5, 14, 30, 5).to_s(:inspect)
assert_equal "2008-06-09 04:05:01.000000000 -0500", Time.local(2008, 6, 9, 4, 5, 1).to_s(:inspect)
end
end

View File

@ -141,6 +141,10 @@ class TimeWithZoneTest < ActiveSupport::TestCase
assert_equal "2000-01-01 00:00:00", @twz.to_s(:db)
end
def test_to_s_inspect
assert_equal "1999-12-31 19:00:00.000000000 -0500", @twz.to_s(:inspect)
end
def test_xmlschema
assert_equal "1999-12-31T19:00:00-05:00", @twz.xmlschema
end