summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-09-29 20:15:02 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2009-09-29 20:15:02 -0700
commit5e5da976f0ffb2bf6de72242b15dd24f95636483 (patch)
treecb8246d517f7c36c05ee3fe91e3a333f718e62d6
parentb17beefedab46e8a3c511c252436be1f8da40fcc (diff)
downloadpsych-5e5da976f0ffb2bf6de72242b15dd24f95636483.zip
list round trips
-rw-r--r--lib/psych/ruby.rb2
-rw-r--r--lib/psych/visitors/yast_builder.rb16
-rw-r--r--test/visitors/test_yast_builder.rb4
3 files changed, 18 insertions, 4 deletions
diff --git a/lib/psych/ruby.rb b/lib/psych/ruby.rb
index 6802391..f63fee1 100644
--- a/lib/psych/ruby.rb
+++ b/lib/psych/ruby.rb
@@ -1,4 +1,4 @@
-[Object, String, Class, Hash].each do |klass|
+[Object, String, Class, Hash, Array].each do |klass|
klass.send(:remove_method, :to_yaml)
end
diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb
index 00f533f..aad42d3 100644
--- a/lib/psych/visitors/yast_builder.rb
+++ b/lib/psych/visitors/yast_builder.rb
@@ -29,9 +29,7 @@ module Psych
end
visitor_for(::Hash) do |o|
- map = Nodes::Mapping.new
- @stack.last.children << map
- @stack.push map
+ @stack.push append Nodes::Mapping.new
o.each do |k,v|
k.accept self
@@ -40,6 +38,18 @@ module Psych
@stack.pop
end
+
+ visitor_for(::Array) do |o|
+ @stack.push append Nodes::Sequence.new
+ o.each { |c| c.accept self }
+ @stack.pop
+ end
+
+ private
+ def append o
+ @stack.last.children << o
+ o
+ end
end
end
end
diff --git a/test/visitors/test_yast_builder.rb b/test/visitors/test_yast_builder.rb
index 027764a..3979566 100644
--- a/test/visitors/test_yast_builder.rb
+++ b/test/visitors/test_yast_builder.rb
@@ -33,6 +33,10 @@ module Psych
assert_round_trip('a' => 'b')
end
+ def test_list
+ assert_round_trip(%w{ a b })
+ end
+
def assert_round_trip obj
@v.accept(obj)
assert_equal(obj, Psych.load(@v.tree.to_yaml))