From b9b923ca942096ddb1062be2deb9e6de9a65f346 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Sun, 28 Mar 2010 21:49:37 +0000 Subject: * 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 --- test/psych/test_psych.rb | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/psych/test_psych.rb (limited to 'test/psych/test_psych.rb') diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb new file mode 100644 index 0000000000..b07af815af --- /dev/null +++ b/test/psych/test_psych.rb @@ -0,0 +1,69 @@ +require 'test/psych/helper' + +class TestPsych < Psych::TestCase + def test_dump_stream + things = [22, "foo \n", {}] + stream = Psych.dump_stream(*things) + assert_equal things, Psych.load_stream(stream) + end + + def test_simple + assert_equal 'foo', Psych.load("--- foo\n") + end + + def test_libyaml_version + assert Psych.libyaml_version + assert_equal Psych.libyaml_version.join('.'), Psych::LIBYAML_VERSION + end + + def test_load_documents + docs = Psych.load_documents("--- foo\n...\n--- bar\n...") + assert_equal %w{ foo bar }, docs + end + + def test_parse_stream + docs = Psych.parse_stream("--- foo\n...\n--- bar\n...") + assert_equal %w{ foo bar }, docs.children.map { |x| x.transform } + end + + def test_add_builtin_type + got = nil + Psych.add_builtin_type 'omap', do |type, val| + got = val + end + Psych.load('--- !omap hello') + assert_equal 'hello', got + ensure + Psych.remove_type 'omap' + end + + def test_domain_types + got = nil + Psych.add_domain_type 'foo.bar,2002', 'foo' do |type, val| + got = val + end + + Psych.load('--- !foo.bar,2002/foo hello') + assert_equal 'hello', got + + Psych.load("--- !foo.bar,2002/foo\n- hello\n- world") + assert_equal %w{ hello world }, got + + Psych.load("--- !foo.bar,2002/foo\nhello: world") + assert_equal({ 'hello' => 'world' }, got) + end + + def test_load_file + name = File.join(Dir.tmpdir, 'yikes.yml') + File.open(name, 'wb') { |f| f.write('--- hello world') } + + assert_equal 'hello world', Psych.load_file(name) + end + + def test_parse_file + name = File.join(Dir.tmpdir, 'yikes.yml') + File.open(name, 'wb') { |f| f.write('--- hello world') } + + assert_equal 'hello world', Psych.parse_file(name).transform + end +end -- cgit v1.2.3