ruby/test/psych/helper.rb
tenderlove a7c2faebb0 merge revision(s) 33160,33381,33382,33383,33384,33385:
* ext/psych/lib/psych.rb: update psych version.
    * ext/psych/psych.gemspec: generate new gemspec for new version.

    * ext/psych/lib/psych.rb: calling `yaml` rather than `to_yaml`.
    * ext/psych/lib/psych/nodes/node.rb: Rename `to_yaml` to just `yaml`
      in order to avoid YAML::ENGINE switching from replacing this method.
    * test/psych/helper.rb: fix tests for method name change.
    * test/psych/test_document.rb: ditto
    * test/psych/visitors/test_emitter.rb: ditto

    * ext/psych/lib/psych/scalar_scanner.rb: Match values against the
      floating point spec defined in YAML to avoid erronious parses.
    * test/psych/test_numeric.rb: corresponding test.

    * ext/psych/lib/psych/visitors/to_ruby.rb: ToRuby visitor can be
      constructed with a ScalarScanner.
    * ext/psych/lib/psych/visitors/yaml_tree.rb: ScalarScanner can be
      passed to the YAMLTree visitor.

    * ext/psych/lib/psych/visitors/to_ruby.rb: Define Regexp::NOENCODING
      for 1.9.2 backwards compatibility.
    * ext/psych/lib/psych/visitors/yaml_tree.rb: Fix Date string
      generation for 1.9.2 backwards compatibility.

    * ext/psych/lib/psych/visitors/yaml_tree.rb: emit strings tagged as
      ascii-8bit as binary in YAML.
    * test/psych/test_string.rb: corresponding test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-12 17:47:29 +00:00

63 lines
1.7 KiB
Ruby

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.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