diff options
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 1 | ||||
-rw-r--r-- | test/psych/test_string.rb | 38 |
2 files changed, 30 insertions, 9 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index ba1ac13..f6427ce 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -319,7 +319,6 @@ module Psych quote = false elsif @line_width && o.length > @line_width style = Nodes::Scalar::FOLDED - o += "\n" unless o =~ /\n\Z/ # to avoid non-default chomping indicator elsif o =~ /^[^[:word:]][^"]*$/ style = Nodes::Scalar::DOUBLE_QUOTED elsif not String === @ss.tokenize(o) diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb index 3188b5c..df8fb98 100644 --- a/test/psych/test_string.rb +++ b/test/psych/test_string.rb @@ -30,32 +30,54 @@ module Psych end def test_doublequotes_when_there_is_a_single - yaml = Psych.dump "@123'abc" - assert_match(/---\s*"/, yaml) + str = "@123'abc" + yaml = Psych.dump str + assert_match /---\s*"/, yaml + assert_equal str, Psych.load(yaml) end - def test_plain_when_shorten_than_line_width + def test_plain_when_shorten_than_line_width_and_no_final_line_break str = "Lorem ipsum" yaml = Psych.dump str, line_width: 12 assert_match /---\s*[^>|]+\n/, yaml + assert_equal str, Psych.load(yaml) end - def test_folded_when_longer_than_line_width_and_no_newlines - str = "Lorem ipsum dolor sit amet, consectetur" + def test_plain_when_shorten_than_line_width_and_with_final_line_break + str = "Lorem ipsum\n" yaml = Psych.dump str, line_width: 12 - assert_match /---\s*>\n(.*\n){3}\Z/, yaml + assert_match /---\s*[^>|]+\n/, yaml + assert_equal str, Psych.load(yaml) end - def test_folded_when_longer_than_line_width_and_trailing_newline + def test_folded_when_longer_than_line_width_and_with_final_line_break str = "Lorem ipsum dolor sit\n" yaml = Psych.dump str, line_width: 12 assert_match /---\s*>\n(.*\n){2}\Z/, yaml + assert_equal str, Psych.load(yaml) end - def test_literal_when_inner_newline + # http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651 + def test_folded_strip_when_longer_than_line_width_and_no_newlines + str = "Lorem ipsum dolor sit amet, consectetur" + yaml = Psych.dump str, line_width: 12 + assert_match /---\s*>-\n(.*\n){3}\Z/, yaml + assert_equal str, Psych.load(yaml) + end + + def test_literal_when_inner_and_final_line_break str = "Lorem ipsum\ndolor\n" yaml = Psych.dump str, line_width: 12 assert_match /---\s*|\n(.*\n){2}\Z/, yaml + assert_equal str, Psych.load(yaml) + end + + # http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651 + def test_literal_strip_when_inner_line_break_and_no_final_line_break + str = "Lorem ipsum\ndolor" + yaml = Psych.dump str, line_width: 12 + assert_match /---\s*|-\n(.*\n){2}\Z/, yaml + assert_equal str, Psych.load(yaml) end def test_cycle_x |