Project

General

Profile

Bug #1331 ยป yaml_test.rb

yaml_test.rb - bahuvrihi (Simon Chiang), 03/30/2009 12:53 PM

 
1
require 'yaml'
2
require 'test/unit'
3

    
4
class A; end
5

    
6
class YAMLTest < Test::Unit::TestCase
7
  
8
  # Enable the gsub to make the tests pass
9
  def fix(dump)
10
    #dump.gsub!(/((?:&id\d+\s+)?!ruby\/object:.*?)\s*\?/) { "? #{$1} " }
11
  end
12
  
13
  # Currently this is the dump:
14
  #
15
  #   --- 
16
  #   !ruby/object:A ? {}
17
  #   : :a
18
  #
19
  # The dump should be:
20
  #
21
  #   --- 
22
  #   ? !ruby/object:A  {}
23
  #   : :a
24
  #
25
  def test_dump_and_reload_hash_with_ruby_object_as_key
26
    hash = { A.new => :a }
27
    
28
    dump = YAML.dump(hash)
29
    fix(dump)
30
    
31
    assert_nothing_raised { YAML.load(dump) }
32
  end
33
  
34
  # Currently this is the dump:
35
  #
36
  #   --- 
37
  #   &id001 !ruby/object:A ? {}
38
  #   : *id001
39
  #
40
  # The dump should be:
41
  #
42
  #   --- 
43
  #   ? &id001 !ruby/object:A  {}
44
  #   : *id001
45
  #
46
  def test_dump_and_reload_self_referential_hash_with_ruby_object_as_key
47
    a = A.new
48
    hash = { a => a }
49
    
50
    dump = YAML.dump(hash)
51
    fix(dump)
52

    
53
    assert_nothing_raised { YAML.load(dump) }
54
  end
55
end