summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-01-17 09:23:09 -0500
committerAaron Patterson <aaron.patterson@gmail.com>2015-01-17 09:23:09 -0500
commitd48f64557ddcfd6f9d51a8a56557844de7c2e8e9 (patch)
treef579c432844ca337d6defe0836cf0af6c6180dca
parentcb75738e594f9d7f7d4899e0f932fcb55a9ad1e1 (diff)
parent372449c75b9cb3e418a20d8e3913a9b9b47d915a (diff)
downloadpsych-d48f64557ddcfd6f9d51a8a56557844de7c2e8e9.tar.gz
Merge pull request #221 from nobu/fix-anchor
Fix anchor
-rw-r--r--lib/psych/visitors/yaml_tree.rb2
-rw-r--r--test/psych/test_string.rb24
2 files changed, 17 insertions, 9 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index c1039c6..8841cb0 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -310,7 +310,7 @@ module Psych
style = Nodes::Scalar::LITERAL
plain = false
quote = false
- elsif o =~ /\n[^\Z]/ # match \n except blank line at the end of string
+ elsif o =~ /\n(?!\Z)/ # match \n except blank line at the end of string
style = Nodes::Scalar::LITERAL
elsif o == '<<'
style = Nodes::Scalar::SINGLE_QUOTED
diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb
index df8fb98..a8ae55c 100644
--- a/test/psych/test_string.rb
+++ b/test/psych/test_string.rb
@@ -66,18 +66,26 @@ module Psych
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)
+ [
+ "Lorem ipsum\ndolor\n",
+ "Lorem ipsum\nZolor\n",
+ ].each do |str|
+ yaml = Psych.dump str, line_width: 12
+ assert_match /---\s*\|\n(.*\n){2}\Z/, yaml
+ assert_equal str, Psych.load(yaml)
+ end
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)
+ [
+ "Lorem ipsum\ndolor",
+ "Lorem ipsum\nZolor",
+ ].each do |str|
+ yaml = Psych.dump str, line_width: 12
+ assert_match /---\s*\|-\n(.*\n){2}\Z/, yaml
+ assert_equal str, Psych.load(yaml)
+ end
end
def test_cycle_x