diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-04-23 21:11:57 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-04-23 21:11:57 -0700 |
commit | 3bfd17a39c2ff3cdb76251e4ff327fee05376d44 (patch) | |
tree | db7946e61e4d097f0e8e8d8028b27d5ba1422f13 /test | |
parent | 432ae1baa61bd1c8e0ea489b811e5df3f51d846c (diff) | |
download | psych-3bfd17a39c2ff3cdb76251e4ff327fee05376d44.zip |
supporting add_ruby_type
Diffstat (limited to 'test')
-rw-r--r-- | test/psych/test_deprecated.rb | 16 | ||||
-rw-r--r-- | test/psych/test_psych.rb | 23 |
2 files changed, 38 insertions, 1 deletions
diff --git a/test/psych/test_deprecated.rb b/test/psych/test_deprecated.rb index 41106ff..c93b36e 100644 --- a/test/psych/test_deprecated.rb +++ b/test/psych/test_deprecated.rb @@ -2,6 +2,10 @@ require_relative 'helper' module Psych class TestDeprecated < TestCase + def teardown + Psych.domain_types.clear + end + class QuickEmitter attr_reader :name attr_reader :value @@ -147,5 +151,17 @@ module Psych def test_yaml_as assert_match(/helloworld/, Psych.dump(YamlAs.new)) end + + def test_ruby_type + types = [] + appender = lambda { |*args| types << args } + + Psych.add_ruby_type('foo', &appender) + Psych.load <<-eoyml +- !ruby.yaml.org,2002/foo bar + eoyml + + assert_equal [["tag:ruby.yaml.org,2002:foo", "bar"]], types + end end end diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb index 91c67b1..78f022c 100644 --- a/test/psych/test_psych.rb +++ b/test/psych/test_psych.rb @@ -4,6 +4,10 @@ require 'stringio' require 'tempfile' class TestPsych < Psych::TestCase + def teardown + Psych.domain_types.clear + end + def test_load_argument_error assert_raises(TypeError) do Psych.load nil @@ -56,7 +60,7 @@ class TestPsych < Psych::TestCase Psych.add_builtin_type 'omap', do |type, val| got = val end - Psych.load('--- !omap hello') + Psych.load('--- !!omap hello') assert_equal 'hello', got ensure Psych.remove_type 'omap' @@ -98,4 +102,21 @@ class TestPsych < Psych::TestCase assert_equal false, Psych.load('') assert_equal false, Psych.parse('') end + + def test_callbacks + types = [] + appender = lambda { |*args| types << args } + + Psych.add_builtin_type('foo', &appender) + Psych.add_domain_type('example.com,2002', 'foo', &appender) + Psych.load <<-eoyml +- !tag:yaml.org,2002:foo bar +- !tag:example.com,2002:foo bar + eoyml + + assert_equal [ + ["tag:yaml.org,2002:foo", "bar"], + ["tag:example.com,2002:foo", "bar"] + ], types + end end |