ruby-changes:16582
From: tenderlove <ko1@a...>
Date: Thu, 8 Jul 2010 08:18:47 +0900 (JST)
Subject: [ruby-changes:16582] Ruby:r28574 (trunk): * ext/psych/lib/psych/visitors/yaml_tree.rb (push): adding version
tenderlove 2010-07-08 08:18:27 +0900 (Thu, 08 Jul 2010) New Revision: 28574 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28574 Log: * ext/psych/lib/psych/visitors/yaml_tree.rb (push): adding version and header emit options. * test/psych/test_psych.rb: corresponding test. Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/test/psych/test_psych.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 28573) +++ ChangeLog (revision 28574) @@ -1,3 +1,10 @@ +Thu Jul 8 08:16:57 2010 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/visitors/yaml_tree.rb (push): adding version + and header emit options. + + * test/psych/test_psych.rb: corresponding test. + Thu Jul 8 08:01:03 2010 Aaron Patterson <aaron@t...> * ext/psych/emitter.c: updating documentation about emit options Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 28573) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 28574) @@ -13,6 +13,7 @@ @emitter = emitter @st = {} @ss = ScalarScanner.new + @options = options @dispatch_cache = Hash.new do |h,klass| method = "visit_#{(klass.name || '').split('::').join('_')}" @@ -43,7 +44,19 @@ def push object start unless started? - @emitter.start_document [], [], false + version = [] + version = [1,1] if @options[:header] + + case @options[:version] + when Array + version = @options[:version] + when String + version = @options[:version].split('.').map { |x| x.to_i } + else + version = [1,1] + end if @options[:version] + + @emitter.start_document version, [], false accept object @emitter.end_document end Index: test/psych/test_psych.rb =================================================================== --- test/psych/test_psych.rb (revision 28573) +++ test/psych/test_psych.rb (revision 28574) @@ -18,6 +18,26 @@ assert_match(/\? ! "b/, yml) end + def test_header + yml = Psych.dump({:a => {'b' => 'c'}}, {:header => true}) + assert_match(/YAML/, yml) + end + + def test_version_array + yml = Psych.dump({:a => {'b' => 'c'}}, {:version => [1,1]}) + assert_match(/1.1/, yml) + end + + def test_version_string + yml = Psych.dump({:a => {'b' => 'c'}}, {:version => '1.1'}) + assert_match(/1.1/, yml) + end + + def test_version_bool + yml = Psych.dump({:a => {'b' => 'c'}}, {:version => true}) + assert_match(/1.1/, yml) + end + def test_load_argument_error assert_raises(TypeError) do Psych.load nil -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/