aboutsummaryrefslogtreecommitdiffstats
path: root/test/psych/helper.rb
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-28 21:49:37 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-28 21:49:37 +0000
commitb9b923ca942096ddb1062be2deb9e6de9a65f346 (patch)
treebc8466746efbe763c7e8a54390d9b34db1aa63c4 /test/psych/helper.rb
parenta8a99a7379fa8e07f217fc7b24e3a9208a967898 (diff)
downloadruby-b9b923ca942096ddb1062be2deb9e6de9a65f346.tar.gz
* ext/psych/*: importing Psych to trunk
* test/psych/*: ditto * lib/psych/*: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/psych/helper.rb')
-rw-r--r--test/psych/helper.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/psych/helper.rb b/test/psych/helper.rb
new file mode 100644
index 0000000000..61049d6cf2
--- /dev/null
+++ b/test/psych/helper.rb
@@ -0,0 +1,63 @@
+require 'minitest/autorun'
+require 'stringio'
+require 'tempfile'
+require 'date'
+
+module Psych
+ class TestCase < MiniTest::Unit::TestCase
+ #
+ # 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'
+
+# FIXME: remove this when syck is removed
+o = Object.new
+a = o.method(:psych_to_yaml)
+b = o.method(:to_yaml)
+raise "psych should define to_yaml" unless a == b