2015-12-16 05:07:31 +00:00
|
|
|
# frozen_string_literal: false
|
2013-03-26 14:55:04 +00:00
|
|
|
require_relative 'helper'
|
2010-07-03 00:52:43 +00:00
|
|
|
require 'date'
|
|
|
|
|
|
|
|
module Psych
|
|
|
|
class TestDateTime < TestCase
|
2013-11-26 21:41:48 +00:00
|
|
|
def test_negative_year
|
2017-04-05 13:16:32 +00:00
|
|
|
time = Time.utc(-1, 12, 16)
|
2013-11-26 21:41:48 +00:00
|
|
|
assert_cycle time
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_new_datetime
|
|
|
|
assert_cycle DateTime.new
|
|
|
|
end
|
|
|
|
|
2013-11-26 19:48:03 +00:00
|
|
|
def test_invalid_date
|
|
|
|
assert_cycle "2013-10-31T10:40:07-000000000000033"
|
|
|
|
end
|
|
|
|
|
2010-07-03 00:52:43 +00:00
|
|
|
def test_string_tag
|
|
|
|
dt = DateTime.now
|
|
|
|
yaml = Psych.dump dt
|
|
|
|
assert_match(/DateTime/, yaml)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_round_trip
|
|
|
|
dt = DateTime.now
|
|
|
|
assert_cycle dt
|
|
|
|
end
|
2013-07-05 19:51:12 +00:00
|
|
|
|
|
|
|
def test_alias_with_time
|
|
|
|
t = Time.now
|
|
|
|
h = {:a => t, :b => t}
|
|
|
|
yaml = Psych.dump h
|
|
|
|
assert_match('&', yaml)
|
|
|
|
assert_match('*', yaml)
|
|
|
|
end
|
2010-07-03 00:52:43 +00:00
|
|
|
end
|
|
|
|
end
|