summaryrefslogtreecommitdiff
path: root/test/psych
diff options
context:
space:
mode:
Diffstat (limited to 'test/psych')
-rw-r--r--test/psych/test_string.rb50
1 files changed, 48 insertions, 2 deletions
diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb
index 26a4e201e5..df8fb986bb 100644
--- a/test/psych/test_string.rb
+++ b/test/psych/test_string.rb
@@ -30,8 +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_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_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/, yaml
+ assert_equal str, Psych.load(yaml)
+ end
+
+ 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
+
+ # 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