* 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
This commit is contained in:
tenderlove 2015-01-16 06:37:22 +00:00
Родитель 983cbb1aed
Коммит a5c577757e
4 изменённых файлов: 74 добавлений и 19 удалений

Просмотреть файл

@ -1,3 +1,12 @@
Fri Jan 16 15:35:21 2015 Aaron Patterson <aaron@tenderlovemaking.com>
* 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
Fri Jan 16 11:44:44 2015 Kazuki Tsujimoto <kazuki@callcc.net> Fri Jan 16 11:44:44 2015 Kazuki Tsujimoto <kazuki@callcc.net>
* eval_intern.h, vm.c, vm_eval.c, vm_insnhelper.c: * eval_intern.h, vm.c, vm_eval.c, vm_insnhelper.c:

Просмотреть файл

@ -217,7 +217,7 @@ require 'psych/class_loader'
module Psych module Psych
# The version is Psych you're using # The version is Psych you're using
VERSION = '2.0.8' VERSION = '2.0.9'
# The version of libyaml Psych is using # The version of libyaml Psych is using
LIBYAML_VERSION = Psych.libyaml_version.join '.' LIBYAML_VERSION = Psych.libyaml_version.join '.'

Просмотреть файл

@ -62,13 +62,14 @@ module Psych
def initialize emitter, ss, options def initialize emitter, ss, options
super() super()
@started = false @started = false
@finished = false @finished = false
@emitter = emitter @emitter = emitter
@st = Registrar.new @st = Registrar.new
@ss = ss @ss = ss
@options = options @options = options
@coders = [] @line_width = options[:line_width]
@coders = []
@dispatch_cache = Hash.new do |h,klass| @dispatch_cache = Hash.new do |h,klass|
method = "visit_#{(klass.name || '').split('::').join('_')}" method = "visit_#{(klass.name || '').split('::').join('_')}"
@ -301,28 +302,27 @@ module Psych
quote = true quote = true
style = Nodes::Scalar::PLAIN style = Nodes::Scalar::PLAIN
tag = nil tag = nil
str = o
if binary?(o) if binary?(o)
str = [o].pack('m').chomp o = [o].pack('m').chomp
tag = '!binary' # FIXME: change to below when syck is removed tag = '!binary' # FIXME: change to below when syck is removed
#tag = 'tag:yaml.org,2002:binary' #tag = 'tag:yaml.org,2002:binary'
style = Nodes::Scalar::LITERAL style = Nodes::Scalar::LITERAL
plain = false plain = false
quote = false quote = false
elsif o =~ /\n/ elsif o =~ /\n[^\Z]/ # match \n except blank line at the end of string
style = Nodes::Scalar::LITERAL style = Nodes::Scalar::LITERAL
elsif o == '<<' elsif o == '<<'
style = Nodes::Scalar::SINGLE_QUOTED style = Nodes::Scalar::SINGLE_QUOTED
tag = 'tag:yaml.org,2002:str' tag = 'tag:yaml.org,2002:str'
plain = false plain = false
quote = false quote = false
elsif @line_width && o.length > @line_width
style = Nodes::Scalar::FOLDED
elsif o =~ /^[^[:word:]][^"]*$/ elsif o =~ /^[^[:word:]][^"]*$/
style = Nodes::Scalar::DOUBLE_QUOTED style = Nodes::Scalar::DOUBLE_QUOTED
else elsif not String === @ss.tokenize(o)
unless String === @ss.tokenize(o) style = Nodes::Scalar::SINGLE_QUOTED
style = Nodes::Scalar::SINGLE_QUOTED
end
end end
ivars = find_ivars o ivars = find_ivars o
@ -333,14 +333,14 @@ module Psych
plain = false plain = false
quote = false quote = false
end end
@emitter.scalar str, nil, tag, plain, quote, style @emitter.scalar o, nil, tag, plain, quote, style
else else
maptag = '!ruby/string' maptag = '!ruby/string'
maptag << ":#{o.class}" unless o.class == ::String maptag << ":#{o.class}" unless o.class == ::String
register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK) register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
@emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY @emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY
@emitter.scalar str, nil, tag, plain, quote, style @emitter.scalar o, nil, tag, plain, quote, style
dump_ivars o dump_ivars o

Просмотреть файл

@ -30,8 +30,54 @@ module Psych
end end
def test_doublequotes_when_there_is_a_single def test_doublequotes_when_there_is_a_single
yaml = Psych.dump "@123'abc" str = "@123'abc"
assert_match(/---\s*"/, yaml) 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 end
def test_cycle_x def test_cycle_x