diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-03-27 19:14:53 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-03-27 19:14:53 -0700 |
commit | 5f1a7543e7bcde61323cd02fb3a82ceda733d051 (patch) | |
tree | cb7ddf55ce1991aa7600f50cfcc2ec15fc0b3ac4 /test/psych/helper.rb | |
parent | 47c4176ce9a349bac0417ebada7690babf79b2a5 (diff) | |
download | psych-5f1a7543e7bcde61323cd02fb3a82ceda733d051.zip |
removed the to_yaml method
Diffstat (limited to 'test/psych/helper.rb')
-rw-r--r-- | test/psych/helper.rb | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/test/psych/helper.rb b/test/psych/helper.rb index 184fac1..04d3547 100644 --- a/test/psych/helper.rb +++ b/test/psych/helper.rb @@ -1,4 +1,3 @@ -require 'psych' require 'minitest/autorun' require 'stringio' require 'tempfile' @@ -6,6 +5,52 @@ require 'date' module Psych class TestCase < MiniTest::Unit::TestCase - # Yes... blank for now. But we will use this. + # + # Convert between Psych and the object to verify correct parsing and + # emitting + # + def assert_to_yaml( obj, yaml ) + assert_equal( obj, Psych::load( yaml ) ) + assert_equal( obj, Psych::parse( yaml ).transform ) + assert_equal( obj, Psych::load( obj.psych_to_yaml ) ) + assert_equal( obj, Psych::parse( obj.psych_to_yaml ).transform ) + assert_equal( obj, Psych::load( + obj.psych_to_yaml( + :UseVersion => true, :UseHeader => true, :SortKeys => true + ) + )) + end + + # + # Test parser only + # + def assert_parse_only( obj, yaml ) + assert_equal( obj, Psych::load( yaml ) ) + assert_equal( obj, Psych::parse( yaml ).transform ) + end + + def assert_cycle( obj ) + v = Visitors::YAMLTree.new + v << obj + assert_equal(obj, Psych.load(v.tree.to_yaml)) + assert_equal( obj, Psych::load(Psych.dump(obj))) + assert_equal( obj, Psych::load( obj.psych_to_yaml ) ) + end + + # + # Make a time with the time zone + # + def mktime( year, mon, day, hour, min, sec, usec, zone = "Z" ) + usec = Rational(usec.to_s) * 1000000 + val = Time::utc( year.to_i, mon.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i, usec ) + if zone != "Z" + hour = zone[0,3].to_i * 3600 + min = zone[3,2].to_i * 60 + ofs = (hour + min) + val = Time.at( val.tv_sec - ofs, val.tv_nsec / 1000.0 ) + end + return val + end end end +require 'psych' |