diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/helper.rb | 3 | ||||
-rw-r--r-- | test/psych/test_array.rb (renamed from test/yaml/test_array.rb) | 11 | ||||
-rw-r--r-- | test/psych/test_boolean.rb (renamed from test/yaml/test_boolean.rb) | 17 | ||||
-rw-r--r-- | test/psych/test_class.rb (renamed from test/yaml/test_class.rb) | 7 | ||||
-rw-r--r-- | test/psych/test_exception.rb (renamed from test/yaml/test_exception.rb) | 11 | ||||
-rw-r--r-- | test/psych/test_hash.rb (renamed from test/yaml/test_hash.rb) | 13 | ||||
-rw-r--r-- | test/psych/test_null.rb (renamed from test/yaml/test_null.rb) | 7 | ||||
-rw-r--r-- | test/psych/test_object.rb (renamed from test/yaml/test_object.rb) | 5 | ||||
-rw-r--r-- | test/psych/test_omap.rb (renamed from test/yaml/test_omap.rb) | 25 | ||||
-rw-r--r-- | test/psych/test_set.rb (renamed from test/yaml/test_set.rb) | 19 | ||||
-rw-r--r-- | test/psych/test_string.rb (renamed from test/yaml/test_string.rb) | 19 | ||||
-rw-r--r-- | test/psych/test_struct.rb | 27 | ||||
-rw-r--r-- | test/psych/test_symbol.rb | 22 | ||||
-rw-r--r-- | test/psych/test_yaml.rb (renamed from test/yaml/test_yaml.rb) | 126 | ||||
-rw-r--r-- | test/yaml/test_struct.rb | 32 | ||||
-rw-r--r-- | test/yaml/test_symbol.rb | 21 |
16 files changed, 171 insertions, 194 deletions
diff --git a/test/helper.rb b/test/helper.rb deleted file mode 100644 index c271650..0000000 --- a/test/helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'test/unit' -require 'psych' -require 'psych/yaml' diff --git a/test/yaml/test_array.rb b/test/psych/test_array.rb index 23434e5..ab83270 100644 --- a/test/yaml/test_array.rb +++ b/test/psych/test_array.rb @@ -1,6 +1,7 @@ -require 'helper' +require 'minitest/autorun' +require 'psych' -module YAML +module Psych class TestArray < MiniTest::Unit::TestCase def setup @list = [{ :a => 'b' }, 'foo'] @@ -8,15 +9,15 @@ module YAML def test_self_referential @list << @list - assert_equal @list, YAML.load(@list.to_yaml) + assert_equal @list, Psych.load(@list.to_yaml) end def test_to_yaml - assert_equal @list, YAML.load(@list.to_yaml) + assert_equal @list, Psych.load(@list.to_yaml) end def test_dump - assert_equal @list, YAML.load(YAML.dump(@list)) + assert_equal @list, Psych.load(Psych.dump(@list)) end end end diff --git a/test/yaml/test_boolean.rb b/test/psych/test_boolean.rb index 5edeb87..020b603 100644 --- a/test/yaml/test_boolean.rb +++ b/test/psych/test_boolean.rb @@ -1,19 +1,20 @@ -require 'helper' +require 'minitest/autorun' +require 'psych' -module YAML +module Psych ### # Test booleans from YAML spec: # http://yaml.org/type/bool.html class TestBoolean < MiniTest::Unit::TestCase %w{ yes Yes YES true True TRUE on On ON }.each do |truth| define_method(:"test_#{truth}") do - assert_equal true, YAML.load("--- #{truth}") + assert_equal true, Psych.load("--- #{truth}") end end %w{ no No NO false False FALSE off Off OFF }.each do |truth| define_method(:"test_#{truth}") do - assert_equal false, YAML.load("--- #{truth}") + assert_equal false, Psych.load("--- #{truth}") end end @@ -21,16 +22,16 @@ module YAML # YAML spec says "y" and "Y" may be used as true, but Syck treats them # as literal strings def test_y - assert_equal "y", YAML.load("--- y") - assert_equal "Y", YAML.load("--- Y") + assert_equal "y", Psych.load("--- y") + assert_equal "Y", Psych.load("--- Y") end ### # YAML spec says "n" and "N" may be used as false, but Syck treats them # as literal strings def test_n - assert_equal "n", YAML.load("--- n") - assert_equal "N", YAML.load("--- N") + assert_equal "n", Psych.load("--- n") + assert_equal "N", Psych.load("--- N") end end end diff --git a/test/yaml/test_class.rb b/test/psych/test_class.rb index 7ad54a6..cfa5d40 100644 --- a/test/yaml/test_class.rb +++ b/test/psych/test_class.rb @@ -1,6 +1,7 @@ -require 'helper' +require 'minitest/autorun' +require 'psych' -module YAML +module Psych class TestClass < MiniTest::Unit::TestCase def test_to_yaml assert_raises(::TypeError) do @@ -10,7 +11,7 @@ module YAML def test_dump assert_raises(::TypeError) do - YAML.dump TestClass + Psych.dump TestClass end end end diff --git a/test/yaml/test_exception.rb b/test/psych/test_exception.rb index da0e6b0..b4d821e 100644 --- a/test/yaml/test_exception.rb +++ b/test/psych/test_exception.rb @@ -1,6 +1,7 @@ -require 'helper' +require 'minitest/autorun' +require 'psych' -module YAML +module Psych class TestException < MiniTest::Unit::TestCase class Wups < Exception attr_reader :foo, :bar @@ -16,14 +17,14 @@ module YAML end def test_to_yaml - w = YAML.load(@wups.to_yaml) + w = Psych.load(@wups.to_yaml) assert_equal @wups, w assert_equal 1, w.foo assert_equal 2, w.bar end def test_dump - w = YAML.load(@wups.to_yaml) + w = Psych.load(@wups.to_yaml) assert_equal @wups, w assert_equal 1, w.foo assert_equal 2, w.bar @@ -36,7 +37,7 @@ module YAML end end - w = YAML.load(YAML.dump(@wups)) + w = Psych.load(Psych.dump(@wups)) assert_equal @wups, w assert_equal 1, w.foo assert_nil w.bar diff --git a/test/yaml/test_hash.rb b/test/psych/test_hash.rb index c6c37bf..76bf595 100644 --- a/test/yaml/test_hash.rb +++ b/test/psych/test_hash.rb @@ -1,6 +1,7 @@ -require 'helper' +require 'minitest/autorun' +require 'psych' -module YAML +module Psych class TestHash < MiniTest::Unit::TestCase def setup @hash = { :a => 'b' } @@ -8,19 +9,19 @@ module YAML def test_self_referential @hash['self'] = @hash - assert_equal @hash, YAML.load(YAML.dump(@hash)) + assert_equal @hash, Psych.load(Psych.dump(@hash)) end def test_to_yaml - assert_equal @hash, YAML.load(@hash.to_yaml) + assert_equal @hash, Psych.load(@hash.to_yaml) end def test_dump - assert_equal @hash, YAML.load(YAML.dump(@hash)) + assert_equal @hash, Psych.load(Psych.dump(@hash)) end def test_ref_append - hash = YAML.load(<<-eoyml) + hash = Psych.load(<<-eoyml) --- foo: &foo hello: world diff --git a/test/yaml/test_null.rb b/test/psych/test_null.rb index e7d08df..261c2b9 100644 --- a/test/yaml/test_null.rb +++ b/test/psych/test_null.rb @@ -1,12 +1,13 @@ -require 'helper' +require 'minitest/autorun' +require 'psych' -module YAML +module Psych ### # Test null from YAML spec: # http://yaml.org/type/null.html class TestNull < MiniTest::Unit::TestCase def test_null_list - assert_equal [nil] * 5, YAML.load(<<-eoyml) + assert_equal [nil] * 5, Psych.load(<<-eoyml) --- - ~ - null diff --git a/test/yaml/test_object.rb b/test/psych/test_object.rb index 4f63d0e..51f7ab4 100644 --- a/test/yaml/test_object.rb +++ b/test/psych/test_object.rb @@ -1,6 +1,7 @@ -require 'helper' +require 'minitest/autorun' +require 'psych' -module YAML +module Psych class Tagged yaml_tag '!foo' diff --git a/test/yaml/test_omap.rb b/test/psych/test_omap.rb index 836c822..3e17901 100644 --- a/test/yaml/test_omap.rb +++ b/test/psych/test_omap.rb @@ -1,22 +1,23 @@ -require 'helper' +require 'minitest/autorun' +require 'psych' -module YAML +module Psych class TestOmap < MiniTest::Unit::TestCase def test_self_referential - map = YAML::Omap.new + map = Psych::Omap.new map['foo'] = 'bar' map['self'] = map - assert_equal(map, YAML.load(YAML.dump(map))) + assert_equal(map, Psych.load(Psych.dump(map))) end def test_keys - map = YAML::Omap.new + map = Psych::Omap.new map['foo'] = 'bar' assert_equal 'bar', map['foo'] end def test_order - map = YAML::Omap.new + map = Psych::Omap.new map['a'] = 'b' map['b'] = 'c' assert_equal [%w{a b}, %w{b c}], map.to_a @@ -24,14 +25,14 @@ module YAML def test_square list = [["a", "b"], ["b", "c"]] - map = YAML::Omap[*list.flatten] + map = Psych::Omap[*list.flatten] assert_equal list, map.to_a assert_equal 'b', map['a'] assert_equal 'c', map['b'] end def test_to_yaml - map = YAML::Omap['a', 'b', 'c', 'd'] + map = Psych::Omap['a', 'b', 'c', 'd'] yaml = map.to_yaml assert_match('!omap', yaml) assert_match('- a: b', yaml) @@ -40,8 +41,8 @@ module YAML def test_round_trip list = [["a", "b"], ["b", "c"]] - map = YAML::Omap[*list.flatten] - loaded = YAML.load(YAML.dump(map)) + map = Psych::Omap[*list.flatten] + loaded = Psych.load(Psych.dump(map)) assert_equal map, loaded assert_equal list, loaded.to_a @@ -49,7 +50,7 @@ module YAML def test_load list = [["a", "b"], ["c", "d"]] - map = YAML.load(<<-eoyml) + map = Psych.load(<<-eoyml) --- !omap - a: b - c: d @@ -60,7 +61,7 @@ module YAML # NOTE: This test will not work with Syck def test_load_shorthand list = [["a", "b"], ["c", "d"]] - map = YAML.load(<<-eoyml) + map = Psych.load(<<-eoyml) --- !!omap - a: b - c: d diff --git a/test/yaml/test_set.rb b/test/psych/test_set.rb index 5468d26..071eedc 100644 --- a/test/yaml/test_set.rb +++ b/test/psych/test_set.rb @@ -1,9 +1,10 @@ -require 'helper' +require 'minitest/autorun' +require 'psych' -module YAML +module Psych class TestSet < MiniTest::Unit::TestCase def setup - @set = YAML::Set.new + @set = Psych::Set.new @set['foo'] = 'bar' @set['bar'] = 'baz' end @@ -13,13 +14,13 @@ module YAML end def test_roundtrip - assert_equal(@set, YAML.load(YAML.dump(@set))) + assert_equal(@set, Psych.load(Psych.dump(@set))) end ### # FIXME: Syck should also support !!set as shorthand def test_load_from_yaml - loaded = YAML.load(<<-eoyml) + loaded = Psych.load(<<-eoyml) --- !set foo: bar bar: baz @@ -28,21 +29,21 @@ bar: baz end def test_loaded_class - assert_instance_of(YAML::Set, YAML.load(YAML.dump(@set))) + assert_instance_of(Psych::Set, Psych.load(Psych.dump(@set))) end def test_set_shorthand - loaded = YAML.load(<<-eoyml) + loaded = Psych.load(<<-eoyml) --- !!set foo: bar bar: baz eoyml - assert_instance_of(YAML::Set, loaded) + assert_instance_of(Psych::Set, loaded) end def test_set_self_reference @set['self'] = @set - assert_equal(@set, YAML.load(YAML.dump(@set))) + assert_equal(@set, Psych.load(Psych.dump(@set))) end end end diff --git a/test/yaml/test_string.rb b/test/psych/test_string.rb index 0faf8d8..5e69318 100644 --- a/test/yaml/test_string.rb +++ b/test/psych/test_string.rb @@ -1,26 +1,27 @@ -require 'helper' +require 'minitest/autorun' +require 'psych' -module YAML +module Psych class TestString < MiniTest::Unit::TestCase def test_binary_string_null string = "\x00" - yml = YAML.dump string + yml = Psych.dump string assert_match(/binary/, yml) - assert_equal string, YAML.load(yml) + assert_equal string, Psych.load(yml) end def test_binary_string string = binary_string - yml = YAML.dump string + yml = Psych.dump string assert_match(/binary/, yml) - assert_equal string, YAML.load(yml) + assert_equal string, Psych.load(yml) end def test_non_binary_string string = binary_string(0.29) - yml = YAML.dump string + yml = Psych.dump string refute_match(/binary/, yml) - assert_equal string, YAML.load(yml) + assert_equal string, Psych.load(yml) end def test_string_with_ivars @@ -28,7 +29,7 @@ module YAML ivar = "on rock and roll" food.instance_variable_set(:@we_built_this_city, ivar) - str = YAML.load YAML.dump food + str = Psych.load Psych.dump food assert_equal ivar, food.instance_variable_get(:@we_built_this_city) end diff --git a/test/psych/test_struct.rb b/test/psych/test_struct.rb index 3d3b9bc..3ec12b0 100644 --- a/test/psych/test_struct.rb +++ b/test/psych/test_struct.rb @@ -1,6 +1,14 @@ require 'minitest/autorun' require 'psych' +class StructWithIvar < Struct.new(:foo) + attr_reader :bar + def initialize *args + super + @bar = 'hello' + end +end + module Psych class TestStruct < MiniTest::Unit::TestCase class StructSubclass < Struct.new(:foo) @@ -21,5 +29,24 @@ module Psych # in ruby. # assert_equal(ss, loaded) end + + def test_roundtrip + thing = StructWithIvar.new('bar') + struct = Psych.load(Psych.dump(thing)) + + assert_equal 'hello', struct.bar + assert_equal 'bar', struct.foo + end + + def test_load + obj = Psych.load(<<-eoyml) +--- !ruby/struct:StructWithIvar +:foo: bar +:@bar: hello + eoyml + + assert_equal 'hello', obj.bar + assert_equal 'bar', obj.foo + end end end diff --git a/test/psych/test_symbol.rb b/test/psych/test_symbol.rb new file mode 100644 index 0000000..9a783be --- /dev/null +++ b/test/psych/test_symbol.rb @@ -0,0 +1,22 @@ +require 'minitest/autorun' +require 'psych' + +module Psych + class TestSymbol < MiniTest::Unit::TestCase + def test_to_yaml + assert_equal :a, Psych.load(:a.to_yaml) + end + + def test_dump + assert_equal :a, Psych.load(Psych.dump(:a)) + end + + def test_stringy + assert_equal :"1", Psych.load(Psych.dump(:"1")) + end + + def test_load_quoted + assert_equal :"1", Psych.load("--- :'1'\n") + end + end +end diff --git a/test/yaml/test_yaml.rb b/test/psych/test_yaml.rb index 886e5f2..5aac5cb 100644 --- a/test/yaml/test_yaml.rb +++ b/test/psych/test_yaml.rb @@ -2,25 +2,25 @@ # vim:sw=4:ts=4 # $Id$ # -require 'test/unit' +require 'minitest/autorun' require 'psych' # [ruby-core:01946] -module YAML_Tests +module Psych_Tests StructTest = Struct::new( :c ) end -class YAML_Unit_Tests < Test::Unit::TestCase +class Psych_Unit_Tests < MiniTest::Unit::TestCase # - # Convert between YAML and the object to verify correct parsing and + # Convert between Psych and the object to verify correct parsing and # emitting # def assert_to_yaml( obj, yaml ) - assert_equal( obj, YAML::load( yaml ) ) - assert_equal( obj, YAML::parse( yaml ).transform ) - assert_equal( obj, YAML::load( obj.to_yaml ) ) - assert_equal( obj, YAML::parse( obj.to_yaml ).transform ) - assert_equal( obj, YAML::load( + assert_equal( obj, Psych::load( yaml ) ) + assert_equal( obj, Psych::parse( yaml ).transform ) + assert_equal( obj, Psych::load( obj.to_yaml ) ) + assert_equal( obj, Psych::parse( obj.to_yaml ).transform ) + assert_equal( obj, Psych::load( obj.to_yaml( :UseVersion => true, :UseHeader => true, :SortKeys => true ) ) ) end @@ -29,16 +29,16 @@ class YAML_Unit_Tests < Test::Unit::TestCase # Test parser only # def assert_parse_only( obj, yaml ) - assert_equal( obj, YAML::load( yaml ) ) - assert_equal( obj, YAML::parse( yaml ).transform ) + assert_equal( obj, Psych::load( yaml ) ) + assert_equal( obj, Psych::parse( yaml ).transform ) end def assert_cycle( obj ) - assert_equal( obj, YAML::load( obj.to_yaml ) ) + assert_equal( obj, Psych::load( obj.to_yaml ) ) end #def assert_path_segments( path, segments ) - # YAML::YPath.each_path( path ) { |choice| + # Psych::YPath.each_path( path ) { |choice| # assert_equal( choice.segments, segments.shift ) # } # assert_equal( segments.length, 0, "Some segments leftover: #{ segments.inspect }" ) @@ -60,7 +60,7 @@ class YAML_Unit_Tests < Test::Unit::TestCase end # - # Tests modified from 00basic.t in YAML.pm + # Tests modified from 00basic.t in Psych.pm # def test_basic_map # Simple map @@ -80,13 +80,13 @@ EOY assert_cycle(":") assert_parse_only( { 1 => 'simple string', 2 => 42, 3 => '1 Single Quoted String', - 4 => 'YAML\'s Double "Quoted" String', 5 => "A block\n with several\n lines.\n", + 4 => 'Psych\'s Double "Quoted" String', 5 => "A block\n with several\n lines.\n", 6 => "A \"chomped\" block", 7 => "A folded\n string\n", 8 => ": started string" }, <<EOY 1: simple string 2: 42 3: '1 Single Quoted String' -4: "YAML's Double \\\"Quoted\\\" String" +4: "Psych's Double \\\"Quoted\\\" String" 5: | A block with several @@ -470,7 +470,7 @@ exponential: 12.3015e+02 fixed: 1,230.15 negative infinity: -.inf EOY - nan = YAML::load( <<EOY ) + nan = Psych::load( <<EOY ) not a number: .NaN EOY assert( nan['not a number'].nan? ) @@ -536,7 +536,7 @@ EOY def test_spec_log_file doc_ct = 0 - YAML::load_documents( <<EOY + Psych::load_documents( <<EOY --- Time: 2001-11-23 15:01:42 -05:00 User: ed @@ -585,19 +585,19 @@ EOY end def test_spec_root_fold - y = YAML::load( <<EOY + y = Psych::load( <<EOY --- -This YAML stream contains a single text value. +This Psych stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end. EOY ) - assert_equal( y, "This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end." ) + assert_equal( y, "This Psych stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end." ) end def test_spec_root_mapping - y = YAML::load( <<EOY + y = Psych::load( <<EOY # This stream is an example of a top-level mapping. invoice : 34843 date : 2001-01-23 @@ -609,7 +609,7 @@ EOY def test_spec_oneline_docs doc_ct = 0 - YAML::load_documents( <<EOY + Psych::load_documents( <<EOY # The following is a sequence of three documents. # The first contains an empty mapping, the second # an empty sequence, and the last an empty string. @@ -641,8 +641,8 @@ EOY raise ArgumentError, "Not a Hash in domain.tld,2002/invoice: " + val.inspect end } - YAML.add_domain_type( "domain.tld,2002", 'invoice', &customer_proc ) - YAML.add_domain_type( "domain.tld,2002", 'customer', &customer_proc ) + Psych.add_domain_type( "domain.tld,2002", 'invoice', &customer_proc ) + Psych.add_domain_type( "domain.tld,2002", 'customer', &customer_proc ) assert_parse_only( { "invoice"=> { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } }, <<EOY # 'http://domain.tld,2002/invoice' is some type family. invoice: !domain.tld,2002/invoice @@ -687,32 +687,6 @@ EOY ) end - def test_spec_private_types - doc_ct = 0 - YAML::parse_documents( <<EOY -# Private types are per-document. ---- -pool: !!ball - number: 8 - color: black ---- -bearing: !!ball - material: steel -EOY - ) { |doc| - case doc_ct - when 0 - assert_equal( doc['pool'].type_id, 'x-private:ball' ) - assert_equal( doc['pool'].transform.value, { 'number' => 8, 'color' => 'black' } ) - when 1 - assert_equal( doc['bearing'].type_id, 'x-private:ball' ) - assert_equal( doc['bearing'].transform.value, { 'material' => 'steel' } ) - end - doc_ct += 1 - } - assert_equal( doc_ct, 2 ) - end - ### # Commenting out this test. This line: # @@ -723,10 +697,10 @@ EOY # http://yaml.org/spec/1.1/#id896876 # # def test_spec_url_escaping -# YAML.add_domain_type( "domain.tld,2002", "type0" ) { |type, val| +# Psych.add_domain_type( "domain.tld,2002", "type0" ) { |type, val| # "ONE: #{val}" # } -# YAML.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val| +# Psych.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val| # "TWO: #{val}" # } # assert_parse_only( @@ -734,7 +708,7 @@ EOY #same: # - !domain.tld,2002/type\\x30 value # - !domain.tld,2002/type0 value -#different: # As far as the YAML parser is concerned +#different: # As far as the Psych parser is concerned # - !domain.tld,2002/type%30 value #EOY # ) @@ -755,7 +729,7 @@ EOY end def test_spec_explicit_families - YAML.add_domain_type( "somewhere.com,2002", 'type' ) { |type, val| + Psych.add_domain_type( "somewhere.com,2002", 'type' ) { |type, val| "SOMEWHERE: #{val}" } assert_parse_only( @@ -776,7 +750,7 @@ EOY def test_spec_application_family # Testing the clarkevans.com graphs - YAML.add_domain_type( "clarkevans.com,2002", 'graph/shape' ) { |type, val| + Psych.add_domain_type( "clarkevans.com,2002", 'graph/shape' ) { |type, val| if Array === val val << "Shape Container" val @@ -793,10 +767,10 @@ EOY raise ArgumentError, "Invalid graph of type #{val.class}: " + val.inspect end } - YAML.add_domain_type( "clarkevans.com,2002", 'graph/circle', &one_shape_proc ) - YAML.add_domain_type( "clarkevans.com,2002", 'graph/line', &one_shape_proc ) - YAML.add_domain_type( "clarkevans.com,2002", 'graph/text', &one_shape_proc ) - # MODIFIED to remove invalid YAML + Psych.add_domain_type( "clarkevans.com,2002", 'graph/circle', &one_shape_proc ) + Psych.add_domain_type( "clarkevans.com,2002", 'graph/line', &one_shape_proc ) + Psych.add_domain_type( "clarkevans.com,2002", 'graph/text', &one_shape_proc ) + # MODIFIED to remove invalid Psych assert_parse_only( [[{"radius"=>7, "center"=>{"x"=>73, "y"=>129}, "TYPE"=>"Shape: graph/circle"}, {"finish"=>{"x"=>89, "y"=>102}, "TYPE"=>"Shape: graph/line", "start"=>{"x"=>73, "y"=>129}}, {"TYPE"=>"Shape: graph/text", "value"=>"Pretty vector drawing.", "start"=>{"x"=>73, "y"=>129}, "color"=>16772795}, "Shape Container"]], <<EOY - !clarkevans.com,2002/graph/shape @@ -1110,8 +1084,8 @@ EOY EOY ) - assert_to_yaml( YAML_Tests::StructTest.new( 123 ), <<EOY ) ---- !ruby/struct:YAML_Tests::StructTest + assert_to_yaml( Psych_Tests::StructTest.new( 123 ), <<EOY ) +--- !ruby/struct:Psych_Tests::StructTest c: 123 EOY @@ -1124,9 +1098,9 @@ numerator: 1 denominator: 2 EOY - # Read YAML dumped by the ruby 1.8.3. + # Read Psych dumped by the ruby 1.8.3. assert_to_yaml( Rational(1, 2), "!ruby/object:Rational 1/2\n" ) - assert_raise( ArgumentError ) { YAML.load("!ruby/object:Rational INVALID/RATIONAL\n") } + assert_raises( ArgumentError ) { Psych.load("!ruby/object:Rational INVALID/RATIONAL\n") } end def test_ruby_complex @@ -1136,9 +1110,9 @@ image: 4 real: 3 EOY - # Read YAML dumped by the ruby 1.8.3. + # Read Psych dumped by the ruby 1.8.3. assert_to_yaml( Complex(3, 4), "!ruby/object:Complex 3+4i\n" ) - assert_raise( ArgumentError ) { YAML.load("!ruby/object:Complex INVALID+COMPLEXi\n") } + assert_raises( ArgumentError ) { Psych.load("!ruby/object:Complex INVALID+COMPLEXi\n") } end def test_emitting_indicators @@ -1149,10 +1123,10 @@ EOY end ## - ## Test the YAML::Stream class -- INACTIVE at the moment + ## Test the Psych::Stream class -- INACTIVE at the moment ## #def test_document - # y = YAML::Stream.new( :Indent => 2, :UseVersion => 0 ) + # y = Psych::Stream.new( :Indent => 2, :UseVersion => 0 ) # y.add( # { 'hi' => 'hello', 'map' => # { 'good' => 'two' }, @@ -1211,7 +1185,7 @@ EOY # Stress test [ruby-core:1071] # a = []; 1000.times { a << {"a"=>"b", "c"=>"d"} } - # YAML::load( a.to_yaml ) + # Psych::load( a.to_yaml ) end @@ -1258,7 +1232,7 @@ EOY def test_circular_references a = []; a[0] = a; a[1] = a inspect_str = "[[...], [...]]" - assert_equal( inspect_str, YAML::load( a.to_yaml ).inspect ) + assert_equal( inspect_str, Psych::load( a.to_yaml ).inspect ) end # @@ -1295,14 +1269,14 @@ EOY # # empty seq as key # - o = YAML.load({[]=>""}.to_yaml) + o = Psych.load({[]=>""}.to_yaml) assert_equal(Hash, o.class) assert_equal([[]], o.keys) # # empty map as key # - o = YAML.load({{}=>""}.to_yaml) + o = Psych.load({{}=>""}.to_yaml) assert_equal(Hash, o.class) assert_equal([{}], o.keys) end @@ -1311,23 +1285,23 @@ EOY # contributed by riley lynch [ruby-Bugs-8548] # def test_object_id_collision - omap = YAML::Omap.new + omap = Psych::Omap.new 1000.times { |i| omap["key_#{i}"] = { "value" => i } } raise "id collision in ordered map" if omap.to_yaml =~ /id\d+/ end def test_date_out_of_range - assert_nothing_raised{YAML::load('1900-01-01T00:00:00+00:00')} + Psych::load('1900-01-01T00:00:00+00:00') end def test_normal_exit - YAML.load("2000-01-01 00:00:00.#{"0"*1000} +00:00\n") + Psych.load("2000-01-01 00:00:00.#{"0"*1000} +00:00\n") # '[ruby-core:13735]' end end #if $0 == __FILE__ -# suite = Test::Unit::TestSuite.new('YAML') +# suite = Test::Unit::TestSuite.new('Psych') # ObjectSpace.each_object(Class) do |klass| # suite << klass.suite if (Test::Unit::TestCase > klass) # end diff --git a/test/yaml/test_struct.rb b/test/yaml/test_struct.rb deleted file mode 100644 index 91d7451..0000000 --- a/test/yaml/test_struct.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'helper' - -class StructWithIvar < Struct.new(:foo) - attr_reader :bar - def initialize *args - super - @bar = 'hello' - end -end - -module YAML - class TestStruct < MiniTest::Unit::TestCase - def test_roundtrip - thing = StructWithIvar.new('bar') - struct = YAML.load(YAML.dump(thing)) - - assert_equal 'hello', struct.bar - assert_equal 'bar', struct.foo - end - - def test_load - obj = YAML.load(<<-eoyml) ---- !ruby/struct:StructWithIvar -:foo: bar -:@bar: hello - eoyml - - assert_equal 'hello', obj.bar - assert_equal 'bar', obj.foo - end - end -end diff --git a/test/yaml/test_symbol.rb b/test/yaml/test_symbol.rb deleted file mode 100644 index 57e1385..0000000 --- a/test/yaml/test_symbol.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'helper' - -module YAML - class TestSymbol < MiniTest::Unit::TestCase - def test_to_yaml - assert_equal :a, YAML.load(:a.to_yaml) - end - - def test_dump - assert_equal :a, YAML.load(YAML.dump(:a)) - end - - def test_stringy - assert_equal :"1", YAML.load(YAML.dump(:"1")) - end - - def test_load_quoted - assert_equal :"1", YAML.load("--- :'1'\n") - end - end -end |