* ext/psych/lib/psych/visitors/yaml_tree.rb (push): adding version
and header emit options. * test/psych/test_psych.rb: corresponding test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3a185ede69
commit
646b699536
@ -1,3 +1,10 @@
|
|||||||
|
Thu Jul 8 08:16:57 2010 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* 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@tenderlovemaking.com>
|
Thu Jul 8 08:01:03 2010 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
* ext/psych/emitter.c: updating documentation about emit options
|
* ext/psych/emitter.c: updating documentation about emit options
|
||||||
|
@ -13,6 +13,7 @@ module Psych
|
|||||||
@emitter = emitter
|
@emitter = emitter
|
||||||
@st = {}
|
@st = {}
|
||||||
@ss = ScalarScanner.new
|
@ss = ScalarScanner.new
|
||||||
|
@options = options
|
||||||
|
|
||||||
@dispatch_cache = Hash.new do |h,klass|
|
@dispatch_cache = Hash.new do |h,klass|
|
||||||
method = "visit_#{(klass.name || '').split('::').join('_')}"
|
method = "visit_#{(klass.name || '').split('::').join('_')}"
|
||||||
@ -43,7 +44,19 @@ module Psych
|
|||||||
|
|
||||||
def push object
|
def push object
|
||||||
start unless started?
|
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
|
accept object
|
||||||
@emitter.end_document
|
@emitter.end_document
|
||||||
end
|
end
|
||||||
|
@ -18,6 +18,26 @@ class TestPsych < Psych::TestCase
|
|||||||
assert_match(/\? ! "b/, yml)
|
assert_match(/\? ! "b/, yml)
|
||||||
end
|
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
|
def test_load_argument_error
|
||||||
assert_raises(TypeError) do
|
assert_raises(TypeError) do
|
||||||
Psych.load nil
|
Psych.load nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user