diff options
Diffstat (limited to 'test/psych')
-rw-r--r-- | test/psych/test_date_time.rb | 31 | ||||
-rw-r--r-- | test/psych/visitors/test_yaml_tree.rb | 17 |
2 files changed, 48 insertions, 0 deletions
diff --git a/test/psych/test_date_time.rb b/test/psych/test_date_time.rb index 443669d17f..3c8b436098 100644 --- a/test/psych/test_date_time.rb +++ b/test/psych/test_date_time.rb @@ -9,10 +9,41 @@ module Psych assert_cycle time end + def test_usec + time = Time.utc(2017, 4, 13, 12, 0, 0, 5) + assert_cycle time + end + + def test_non_utc + time = Time.new(2017, 4, 13, 12, 0, 0.5, "+09:00") + assert_cycle time + end + + def test_timezone_offset + times = [Time.new(2017, 4, 13, 12, 0, 0, "+09:00"), + Time.new(2017, 4, 13, 12, 0, 0, "-05:00")] + cycled = Psych::load(Psych.dump times) + assert_match(/12:00:00 \+0900/, cycled.first.to_s) + assert_match(/12:00:00 -0500/, cycled.last.to_s) + end + def test_new_datetime assert_cycle DateTime.new end + def test_datetime_non_utc + dt = DateTime.new(2017, 4, 13, 12, 0, 0.5, "+09:00") + assert_cycle dt + end + + def test_datetime_timezone_offset + times = [DateTime.new(2017, 4, 13, 12, 0, 0, "+09:00"), + DateTime.new(2017, 4, 13, 12, 0, 0, "-05:00")] + cycled = Psych::load(Psych.dump times) + assert_match(/12:00:00\+09:00/, cycled.first.to_s) + assert_match(/12:00:00-05:00/, cycled.last.to_s) + end + def test_invalid_date assert_cycle "2013-10-31T10:40:07-000000000000033" end diff --git a/test/psych/visitors/test_yaml_tree.rb b/test/psych/visitors/test_yaml_tree.rb index ea38f6d6d4..8fc18f2fe6 100644 --- a/test/psych/visitors/test_yaml_tree.rb +++ b/test/psych/visitors/test_yaml_tree.rb @@ -4,6 +4,15 @@ require 'psych/helper' module Psych module Visitors class TestYAMLTree < TestCase + class TestDelegatorClass < Delegator + def initialize(obj); super; @obj = obj; end + def __setobj__(obj); @obj = obj; end + def __getobj__; @obj; end + end + + class TestSimpleDelegatorClass < SimpleDelegator + end + def setup super @v = Visitors::YAMLTree.create @@ -175,6 +184,14 @@ module Psych assert_cycle 'nUll' assert_cycle '~' end + + def test_delegator + assert_cycle(TestDelegatorClass.new([1, 2, 3])) + end + + def test_simple_delegator + assert_cycle(TestSimpleDelegatorClass.new([1, 2, 3])) + end end end end |