diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-07 15:51:21 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-07 15:51:21 -0700 |
commit | 57c468a5f8bd3ffc1cb93b07db6b823872316a18 (patch) | |
tree | dad229aa55917b157c2eba2f76d9da3a7e947866 | |
parent | 98ce58ac328aca5f5d541c9118b5e4184b916bd3 (diff) | |
download | psych-57c468a5f8bd3ffc1cb93b07db6b823872316a18.zip |
fixing float parsing
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 2 | ||||
-rw-r--r-- | test/visitors/test_to_ruby.rb | 6 | ||||
-rw-r--r-- | test/visitors/test_yast_builder.rb | 5 |
3 files changed, 13 insertions, 0 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index bb80ad6..c757d25 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -22,6 +22,8 @@ module Psych Complex(o.value) when "!ruby/object:Rational" Rational(o.value) + when "tag:yaml.org,2002:float", "!float" + Float(ScalarScanner.new(o.value).tokenize.last) when "!ruby/regexp" o.value =~ /^\/(.*)\/([mix]*)$/ source = $1 diff --git a/test/visitors/test_to_ruby.rb b/test/visitors/test_to_ruby.rb index 9c37690..8bf9c91 100644 --- a/test/visitors/test_to_ruby.rb +++ b/test/visitors/test_to_ruby.rb @@ -173,6 +173,9 @@ module Psych i = Nodes::Scalar.new(num, nil, 'tag:yaml.org,2002:float') assert_equal 1000.3, i.to_ruby + i = Nodes::Scalar.new(num, nil, '!float') + assert_equal 1000.3, i.to_ruby + assert_equal 1000.3, Nodes::Scalar.new(num).to_ruby end end @@ -196,6 +199,9 @@ module Psych end def test_float + i = Nodes::Scalar.new('12', nil, 'tag:yaml.org,2002:float') + assert_equal 12.0, i.to_ruby + i = Nodes::Scalar.new('1.2', nil, 'tag:yaml.org,2002:float') assert_equal 1.2, i.to_ruby diff --git a/test/visitors/test_yast_builder.rb b/test/visitors/test_yast_builder.rb index 4730e7d..532ab09 100644 --- a/test/visitors/test_yast_builder.rb +++ b/test/visitors/test_yast_builder.rb @@ -8,6 +8,11 @@ module Psych @v = Visitors::YASTBuilder.new end + def test_struct_const + foo = Struct.new("Foo", :bar) + assert_round_trip foo.new('bar') + end + A = Struct.new(:foo) def test_struct |