summaryrefslogtreecommitdiff
path: root/test/psych
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-16 06:37:22 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-16 06:37:22 +0000
commita5c577757ece55432acbed341d299ac8849d633f (patch)
treef528ce60dc834b1304c71061ecbf7691edfbe250 /test/psych
parent983cbb1aed57665e3a616f40b759f35bf143e091 (diff)
* ext/psych/lib/psych.rb: bump version
* ext/psych/lib/psych/visitors/yaml_tree.rb: fix line width wrapping for long strings. Thanks Jakub Jirutka <jakub@jirutka.cz> * test/psych/test_string.rb: test for change git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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 26a4e201e53..df8fb986bb4 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