2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2013-03-26 10:55:04 -04:00
|
|
|
require_relative 'helper'
|
2010-07-02 20:52:43 -04:00
|
|
|
require 'date'
|
|
|
|
|
|
|
|
module Psych
|
|
|
|
class TestDateTime < TestCase
|
2013-11-26 16:41:48 -05:00
|
|
|
def test_negative_year
|
2017-04-05 09:16:32 -04:00
|
|
|
time = Time.utc(-1, 12, 16)
|
2013-11-26 16:41:48 -05:00
|
|
|
assert_cycle time
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_new_datetime
|
|
|
|
assert_cycle DateTime.new
|
|
|
|
end
|
|
|
|
|
2013-11-26 14:48:03 -05:00
|
|
|
def test_invalid_date
|
|
|
|
assert_cycle "2013-10-31T10:40:07-000000000000033"
|
|
|
|
end
|
|
|
|
|
2010-07-02 20:52:43 -04: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 15:51:12 -04: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-02 20:52:43 -04:00
|
|
|
end
|
|
|
|
end
|