зеркало из https://github.com/github/ruby.git
* ext/psych/lib/psych/visitors/yaml_tree.rb: fixing string quotation
when dumping Ruby strings. Thanks Ingy * test/psych/test_psych.rb: appropriate tests. * test/psych/test_yaml.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
7a68f53dc6
Коммит
1c836f811c
|
@ -1,3 +1,12 @@
|
||||||
|
Fri Feb 8 08:53:27 2013 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* ext/psych/lib/psych/visitors/yaml_tree.rb: fixing string quotation
|
||||||
|
when dumping Ruby strings. Thanks Ingy
|
||||||
|
|
||||||
|
* test/psych/test_psych.rb: appropriate tests.
|
||||||
|
|
||||||
|
* test/psych/test_yaml.rb: ditto
|
||||||
|
|
||||||
Fri Feb 8 08:50:42 2013 Aaron Patterson <aaron@tenderlovemaking.com>
|
Fri Feb 8 08:50:42 2013 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
* ext/psych/lib/psych/visitors/yaml_tree.rb: change output reference
|
* ext/psych/lib/psych/visitors/yaml_tree.rb: change output reference
|
||||||
|
|
|
@ -253,9 +253,9 @@ module Psych
|
||||||
private :binary?
|
private :binary?
|
||||||
|
|
||||||
def visit_String o
|
def visit_String o
|
||||||
plain = false
|
plain = true
|
||||||
quote = false
|
quote = true
|
||||||
style = Nodes::Scalar::ANY
|
style = Nodes::Scalar::PLAIN
|
||||||
tag = nil
|
tag = nil
|
||||||
str = o
|
str = o
|
||||||
|
|
||||||
|
@ -264,15 +264,14 @@ module Psych
|
||||||
tag = '!binary' # FIXME: change to below when syck is removed
|
tag = '!binary' # FIXME: change to below when syck is removed
|
||||||
#tag = 'tag:yaml.org,2002:binary'
|
#tag = 'tag:yaml.org,2002:binary'
|
||||||
style = Nodes::Scalar::LITERAL
|
style = Nodes::Scalar::LITERAL
|
||||||
|
plain = false
|
||||||
|
quote = false
|
||||||
elsif o =~ /\n/
|
elsif o =~ /\n/
|
||||||
quote = true
|
|
||||||
style = Nodes::Scalar::LITERAL
|
style = Nodes::Scalar::LITERAL
|
||||||
elsif o =~ /^\W/
|
|
||||||
quote = true
|
|
||||||
style = Nodes::Scalar::DOUBLE_QUOTED
|
|
||||||
else
|
else
|
||||||
quote = !(String === @ss.tokenize(o))
|
unless String === @ss.tokenize(o)
|
||||||
plain = !quote
|
style = Nodes::Scalar::SINGLE_QUOTED
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ivars = find_ivars o
|
ivars = find_ivars o
|
||||||
|
|
|
@ -20,7 +20,7 @@ class TestPsych < Psych::TestCase
|
||||||
|
|
||||||
def test_canonical
|
def test_canonical
|
||||||
yml = Psych.dump({:a => {'b' => 'c'}}, {:canonical => true})
|
yml = Psych.dump({:a => {'b' => 'c'}}, {:canonical => true})
|
||||||
assert_match(/\? ! "b/, yml)
|
assert_match(/\? "b/, yml)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_header
|
def test_header
|
||||||
|
|
|
@ -1274,7 +1274,16 @@ EOY
|
||||||
|
|
||||||
def test_string_starting_with_non_word_character_uses_double_quotes_without_exclamation_mark
|
def test_string_starting_with_non_word_character_uses_double_quotes_without_exclamation_mark
|
||||||
yaml = Psych.dump("@123'abc")
|
yaml = Psych.dump("@123'abc")
|
||||||
assert_match("\"", yaml)
|
|
||||||
refute_match("!", yaml)
|
refute_match("!", yaml)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_string_dump_with_colon
|
||||||
|
yaml = Psych.dump 'x: foo'
|
||||||
|
refute_match '!', yaml
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_string_dump_starting_with_star
|
||||||
|
yaml = Psych.dump '*foo'
|
||||||
|
refute_match '!', yaml
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче