diff options
author | Jakub Jirutka <jakub@jirutka.cz> | 2015-01-13 01:25:09 +0100 |
---|---|---|
committer | Jakub Jirutka <jakub@jirutka.cz> | 2015-01-13 01:25:09 +0100 |
commit | af668b4c83692ca8556d0aed97a3c542f7176e75 (patch) | |
tree | eeb76f7ca4855dd9cc9743439c142b60ec294da8 /test | |
parent | 9a811d65852fa3fd556c475652c321263d148edd (diff) | |
download | psych-af668b4c83692ca8556d0aed97a3c542f7176e75.zip |
Fix block chomping and add more tests
When no [chomping indicator][1] is specified for a folded or literal
block, then YAML parser should preserve the final line break (i.e. the
string should end with \n). This implies that when dumping a string
*without* the trailing newline to YAML, we should specify the stripping
indicator (-).
[1]: http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651
Diffstat (limited to 'test')
-rw-r--r-- | test/psych/test_string.rb | 38 |
1 files changed, 30 insertions, 8 deletions
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 |