mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Import psych-3.0.0.beta1 from ruby/psych.
* Removed deprecated code. * Removed code related syck gem. * Fixed typos. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4389ba641f
commit
6d77e28763
20 changed files with 52 additions and 398 deletions
|
@ -17,7 +17,6 @@ require 'psych/omap'
|
||||||
require 'psych/set'
|
require 'psych/set'
|
||||||
require 'psych/coder'
|
require 'psych/coder'
|
||||||
require 'psych/core_ext'
|
require 'psych/core_ext'
|
||||||
require 'psych/deprecated'
|
|
||||||
require 'psych/stream'
|
require 'psych/stream'
|
||||||
require 'psych/json/tree_builder'
|
require 'psych/json/tree_builder'
|
||||||
require 'psych/json/stream'
|
require 'psych/json/stream'
|
||||||
|
|
|
@ -4,31 +4,14 @@ class Object
|
||||||
Psych.add_tag(url, self)
|
Psych.add_tag(url, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME: rename this to "to_yaml" when syck is removed
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# call-seq: to_yaml(options = {})
|
# call-seq: to_yaml(options = {})
|
||||||
#
|
#
|
||||||
# Convert an object to YAML. See Psych.dump for more information on the
|
# Convert an object to YAML. See Psych.dump for more information on the
|
||||||
# available +options+.
|
# available +options+.
|
||||||
def psych_to_yaml options = {}
|
def to_yaml options = {}
|
||||||
Psych.dump self, options
|
Psych.dump self, options
|
||||||
end
|
end
|
||||||
remove_method :to_yaml rescue nil
|
|
||||||
alias :to_yaml :psych_to_yaml
|
|
||||||
end
|
|
||||||
|
|
||||||
class Module
|
|
||||||
def psych_yaml_as url
|
|
||||||
return if caller[0].end_with?('rubytypes.rb')
|
|
||||||
if $VERBOSE
|
|
||||||
warn "#{caller[0]}: yaml_as is deprecated, please use yaml_tag"
|
|
||||||
end
|
|
||||||
Psych.add_tag(url, self)
|
|
||||||
end
|
|
||||||
|
|
||||||
remove_method :yaml_as rescue nil
|
|
||||||
alias :yaml_as :psych_yaml_as
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if defined?(::IRB)
|
if defined?(::IRB)
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
# frozen_string_literal: false
|
|
||||||
require 'date'
|
|
||||||
|
|
||||||
module Psych
|
|
||||||
DEPRECATED = __FILE__ # :nodoc:
|
|
||||||
|
|
||||||
module DeprecatedMethods # :nodoc:
|
|
||||||
attr_accessor :taguri
|
|
||||||
attr_accessor :to_yaml_style
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.quick_emit thing, opts = {}, &block # :nodoc:
|
|
||||||
warn "#{caller[0]}: YAML.quick_emit is deprecated" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
|
||||||
target = eval 'self', block.binding
|
|
||||||
target.extend DeprecatedMethods
|
|
||||||
metaclass = class << target; self; end
|
|
||||||
metaclass.send(:define_method, :encode_with) do |coder|
|
|
||||||
target.taguri = coder.tag
|
|
||||||
target.to_yaml_style = coder.style
|
|
||||||
block.call coder
|
|
||||||
end
|
|
||||||
target.psych_to_yaml unless opts[:nodump]
|
|
||||||
end
|
|
||||||
|
|
||||||
# This method is deprecated, use Psych.load_stream instead.
|
|
||||||
def self.load_documents yaml, &block
|
|
||||||
if $VERBOSE
|
|
||||||
warn "#{caller[0]}: load_documents is deprecated, use load_stream"
|
|
||||||
end
|
|
||||||
list = load_stream yaml
|
|
||||||
return list unless block_given?
|
|
||||||
list.each(&block)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.detect_implicit thing
|
|
||||||
warn "#{caller[0]}: detect_implicit is deprecated" if $VERBOSE
|
|
||||||
return '' unless String === thing
|
|
||||||
return 'null' if '' == thing
|
|
||||||
ss = ScalarScanner.new(ClassLoader.new)
|
|
||||||
ss.tokenize(thing).class.name.downcase
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.add_ruby_type type_tag, &block
|
|
||||||
warn "#{caller[0]}: add_ruby_type is deprecated, use add_domain_type" if $VERBOSE
|
|
||||||
domain = 'ruby.yaml.org,2002'
|
|
||||||
key = ['tag', domain, type_tag].join ':'
|
|
||||||
@domain_types[key] = [key, block]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.add_private_type type_tag, &block
|
|
||||||
warn "#{caller[0]}: add_private_type is deprecated, use add_domain_type" if $VERBOSE
|
|
||||||
domain = 'x-private'
|
|
||||||
key = [domain, type_tag].join ':'
|
|
||||||
@domain_types[key] = [key, block]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.tagurize thing
|
|
||||||
warn "#{caller[0]}: add_private_type is deprecated, use add_domain_type" if $VERBOSE
|
|
||||||
return thing unless String === thing
|
|
||||||
"tag:yaml.org,2002:#{thing}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.read_type_class type, reference
|
|
||||||
warn "#{caller[0]}: read_type_class is deprecated" if $VERBOSE
|
|
||||||
_, _, type, name = type.split ':', 4
|
|
||||||
|
|
||||||
reference = name.split('::').inject(reference) do |k,n|
|
|
||||||
k.const_get(n.to_sym)
|
|
||||||
end if name
|
|
||||||
[type, reference]
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.object_maker klass, hash
|
|
||||||
warn "#{caller[0]}: object_maker is deprecated" if $VERBOSE
|
|
||||||
klass.allocate.tap do |obj|
|
|
||||||
hash.each { |k,v| obj.instance_variable_set(:"@#{k}", v) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Object
|
|
||||||
undef :to_yaml_properties rescue nil
|
|
||||||
def to_yaml_properties # :nodoc:
|
|
||||||
instance_variables
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -10,7 +10,6 @@ module Psych
|
||||||
|
|
||||||
# Taken from http://yaml.org/type/float.html
|
# Taken from http://yaml.org/type/float.html
|
||||||
FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10)
|
FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9]*([eE][-+][0-9]+)?(?# base 10)
|
||||||
|[-+]?[0-9][0-9_,]*(:[0-5]?[0-9])+\.[0-9_]*(?# base 60)
|
|
||||||
|[-+]?\.(inf|Inf|INF)(?# infinity)
|
|[-+]?\.(inf|Inf|INF)(?# infinity)
|
||||||
|\.(nan|NaN|NAN)(?# not a number))$/x
|
|\.(nan|NaN|NAN)(?# not a number))$/x
|
||||||
|
|
||||||
|
@ -83,13 +82,13 @@ module Psych
|
||||||
else
|
else
|
||||||
@symbol_cache[string] = class_loader.symbolize(string.sub(/^:/, ''))
|
@symbol_cache[string] = class_loader.symbolize(string.sub(/^:/, ''))
|
||||||
end
|
end
|
||||||
when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+$/
|
when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}$/
|
||||||
i = 0
|
i = 0
|
||||||
string.split(':').each_with_index do |n,e|
|
string.split(':').each_with_index do |n,e|
|
||||||
i += (n.to_i * 60 ** (e - 2).abs)
|
i += (n.to_i * 60 ** (e - 2).abs)
|
||||||
end
|
end
|
||||||
i
|
i
|
||||||
when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+\.[0-9_]*$/
|
when /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9]){1,2}\.[0-9_]*$/
|
||||||
i = 0
|
i = 0
|
||||||
string.split(':').each_with_index do |n,e|
|
string.split(':').each_with_index do |n,e|
|
||||||
i += (n.to_f * 60 ** (e - 2).abs)
|
i += (n.to_f * 60 ** (e - 2).abs)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: false
|
||||||
module Psych
|
module Psych
|
||||||
# The version is Psych you're using
|
# The version is Psych you're using
|
||||||
VERSION = '2.2.3'
|
VERSION = '3.0.0.beta1'
|
||||||
|
|
||||||
if RUBY_ENGINE == 'jruby'
|
if RUBY_ENGINE == 'jruby'
|
||||||
DEFAULT_SNAKEYAML_VERSION = '1.18'.freeze
|
DEFAULT_SNAKEYAML_VERSION = '1.18'.freeze
|
||||||
|
|
|
@ -380,11 +380,6 @@ module Psych
|
||||||
|
|
||||||
if o.respond_to?(:init_with)
|
if o.respond_to?(:init_with)
|
||||||
o.init_with c
|
o.init_with c
|
||||||
elsif o.respond_to?(:yaml_initialize)
|
|
||||||
if $VERBOSE
|
|
||||||
warn "Implementing #{o.class}#yaml_initialize is deprecated, please implement \"init_with(coder)\""
|
|
||||||
end
|
|
||||||
o.yaml_initialize c.tag, c.map
|
|
||||||
else
|
else
|
||||||
h.each { |k,v| o.instance_variable_set(:"@#{k}", v) }
|
h.each { |k,v| o.instance_variable_set(:"@#{k}", v) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,15 +53,6 @@ module Psych
|
||||||
new(emitter, ss, options)
|
new(emitter, ss, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.new emitter = nil, ss = nil, options = nil
|
|
||||||
return super if emitter && ss && options
|
|
||||||
|
|
||||||
if $VERBOSE
|
|
||||||
warn "This API is deprecated, please pass an emitter, scalar scanner, and options or call #{self}.create() (#{caller.first})"
|
|
||||||
end
|
|
||||||
create emitter, ss
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize emitter, ss, options
|
def initialize emitter, ss, options
|
||||||
super()
|
super()
|
||||||
@started = false
|
@started = false
|
||||||
|
@ -139,24 +130,6 @@ module Psych
|
||||||
return @emitter.alias anchor
|
return @emitter.alias anchor
|
||||||
end
|
end
|
||||||
|
|
||||||
if target.respond_to?(:to_yaml)
|
|
||||||
begin
|
|
||||||
loc = target.method(:to_yaml).source_location.first
|
|
||||||
if loc !~ /(syck\/rubytypes.rb|psych\/core_ext.rb)/
|
|
||||||
unless target.respond_to?(:encode_with)
|
|
||||||
if $VERBOSE
|
|
||||||
warn "implementing to_yaml is deprecated, please implement \"encode_with\""
|
|
||||||
end
|
|
||||||
|
|
||||||
target.to_yaml(:nodump => true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue
|
|
||||||
# public_method or source_location might be overridden,
|
|
||||||
# and it's OK to skip it since it's only to emit a warning
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if target.respond_to?(:encode_with)
|
if target.respond_to?(:encode_with)
|
||||||
dump_coder target
|
dump_coder target
|
||||||
else
|
else
|
||||||
|
@ -336,7 +309,7 @@ module Psych
|
||||||
end
|
end
|
||||||
|
|
||||||
is_primitive = o.class == ::String
|
is_primitive = o.class == ::String
|
||||||
ivars = find_ivars o, is_primitive
|
ivars = is_primitive ? [] : o.instance_variables
|
||||||
|
|
||||||
if ivars.empty?
|
if ivars.empty?
|
||||||
unless is_primitive
|
unless is_primitive
|
||||||
|
@ -527,24 +500,6 @@ module Psych
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME: remove this method once "to_yaml_properties" is removed
|
|
||||||
def find_ivars target, is_primitive=false
|
|
||||||
begin
|
|
||||||
loc = target.method(:to_yaml_properties).source_location.first
|
|
||||||
unless loc.start_with?(Psych::DEPRECATED) || loc.end_with?('rubytypes.rb')
|
|
||||||
if $VERBOSE
|
|
||||||
warn "#{loc}: to_yaml_properties is deprecated, please implement \"encode_with(coder)\""
|
|
||||||
end
|
|
||||||
return target.to_yaml_properties
|
|
||||||
end
|
|
||||||
rescue
|
|
||||||
# public_method or source_location might be overridden,
|
|
||||||
# and it's OK to skip it since it's only to emit a warning.
|
|
||||||
end
|
|
||||||
|
|
||||||
is_primitive ? [] : target.instance_variables
|
|
||||||
end
|
|
||||||
|
|
||||||
def register target, yaml_obj
|
def register target, yaml_obj
|
||||||
@st.register target, yaml_obj
|
@st.register target, yaml_obj
|
||||||
yaml_obj
|
yaml_obj
|
||||||
|
@ -586,9 +541,7 @@ module Psych
|
||||||
end
|
end
|
||||||
|
|
||||||
def dump_ivars target
|
def dump_ivars target
|
||||||
ivars = find_ivars target
|
target.instance_variables.each do |iv|
|
||||||
|
|
||||||
ivars.each do |iv|
|
|
||||||
@emitter.scalar("#{iv.to_s.sub(/^@/, '')}", nil, nil, true, false, Nodes::Scalar::ANY)
|
@emitter.scalar("#{iv.to_s.sub(/^@/, '')}", nil, nil, true, false, Nodes::Scalar::ANY)
|
||||||
accept target.instance_variable_get(iv)
|
accept target.instance_variable_get(iv)
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "psych"
|
s.name = "psych"
|
||||||
s.version = "2.2.3"
|
s.version = "3.0.0.beta1"
|
||||||
s.authors = ["Aaron Patterson", "SHIBATA Hiroshi", "Charles Oliver Nutter"]
|
s.authors = ["Aaron Patterson", "SHIBATA Hiroshi", "Charles Oliver Nutter"]
|
||||||
s.email = ["aaron@tenderlovemaking.com", "hsbt@ruby-lang.org", "headius@headius.com"]
|
s.email = ["aaron@tenderlovemaking.com", "hsbt@ruby-lang.org", "headius@headius.com"]
|
||||||
s.date = "2016-11-14"
|
s.date = "2016-11-14"
|
||||||
|
@ -17,7 +17,7 @@ DESCRIPTION
|
||||||
s.require_paths = ["lib"]
|
s.require_paths = ["lib"]
|
||||||
|
|
||||||
# for ruby core repository. It was generated by `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
# for ruby core repository. It was generated by `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
||||||
s.files = [".gitignore", ".travis.yml", "CHANGELOG.rdoc", "Gemfile", "Mavenfile", "README.md", "Rakefile", "bin/console", "bin/setup", "ext/psych/.gitignore", "ext/psych/depend", "ext/psych/extconf.rb", "ext/psych/psych.c", "ext/psych/psych.h", "ext/psych/psych_emitter.c", "ext/psych/psych_emitter.h", "ext/psych/psych_parser.c", "ext/psych/psych_parser.h", "ext/psych/psych_to_ruby.c", "ext/psych/psych_to_ruby.h", "ext/psych/psych_yaml_tree.c", "ext/psych/psych_yaml_tree.h", "ext/psych/yaml/LICENSE", "ext/psych/yaml/api.c", "ext/psych/yaml/config.h", "ext/psych/yaml/dumper.c", "ext/psych/yaml/emitter.c", "ext/psych/yaml/loader.c", "ext/psych/yaml/parser.c", "ext/psych/yaml/reader.c", "ext/psych/yaml/scanner.c", "ext/psych/yaml/writer.c", "ext/psych/yaml/yaml.h", "ext/psych/yaml/yaml_private.h", "lib/psych.rb", "lib/psych/class_loader.rb", "lib/psych/coder.rb", "lib/psych/core_ext.rb", "lib/psych/deprecated.rb", "lib/psych/exception.rb", "lib/psych/handler.rb", "lib/psych/handlers/document_stream.rb", "lib/psych/handlers/recorder.rb", "lib/psych/json/ruby_events.rb", "lib/psych/json/stream.rb", "lib/psych/json/tree_builder.rb", "lib/psych/json/yaml_events.rb", "lib/psych/nodes.rb", "lib/psych/nodes/alias.rb", "lib/psych/nodes/document.rb", "lib/psych/nodes/mapping.rb", "lib/psych/nodes/node.rb", "lib/psych/nodes/scalar.rb", "lib/psych/nodes/sequence.rb", "lib/psych/nodes/stream.rb", "lib/psych/omap.rb", "lib/psych/parser.rb", "lib/psych/scalar_scanner.rb", "lib/psych/set.rb", "lib/psych/stream.rb", "lib/psych/streaming.rb", "lib/psych/syntax_error.rb", "lib/psych/tree_builder.rb", "lib/psych/versions.rb", "lib/psych/visitors.rb","lib/psych/visitors/depth_first.rb", "lib/psych/visitors/emitter.rb", "lib/psych/visitors/json_tree.rb", "lib/psych/visitors/to_ruby.rb", "lib/psych/visitors/visitor.rb", "lib/psych/visitors/yaml_tree.rb", "lib/psych/y.rb", "psych.gemspec"]
|
s.files = [".gitignore", ".travis.yml", "CHANGELOG.rdoc", "Gemfile", "Mavenfile", "README.md", "Rakefile", "bin/console", "bin/setup", "ext/psych/.gitignore", "ext/psych/depend", "ext/psych/extconf.rb", "ext/psych/psych.c", "ext/psych/psych.h", "ext/psych/psych_emitter.c", "ext/psych/psych_emitter.h", "ext/psych/psych_parser.c", "ext/psych/psych_parser.h", "ext/psych/psych_to_ruby.c", "ext/psych/psych_to_ruby.h", "ext/psych/psych_yaml_tree.c", "ext/psych/psych_yaml_tree.h", "ext/psych/yaml/LICENSE", "ext/psych/yaml/api.c", "ext/psych/yaml/config.h", "ext/psych/yaml/dumper.c", "ext/psych/yaml/emitter.c", "ext/psych/yaml/loader.c", "ext/psych/yaml/parser.c", "ext/psych/yaml/reader.c", "ext/psych/yaml/scanner.c", "ext/psych/yaml/writer.c", "ext/psych/yaml/yaml.h", "ext/psych/yaml/yaml_private.h", "lib/psych.rb", "lib/psych/class_loader.rb", "lib/psych/coder.rb", "lib/psych/core_ext.rb", "lib/psych/exception.rb", "lib/psych/handler.rb", "lib/psych/handlers/document_stream.rb", "lib/psych/handlers/recorder.rb", "lib/psych/json/ruby_events.rb", "lib/psych/json/stream.rb", "lib/psych/json/tree_builder.rb", "lib/psych/json/yaml_events.rb", "lib/psych/nodes.rb", "lib/psych/nodes/alias.rb", "lib/psych/nodes/document.rb", "lib/psych/nodes/mapping.rb", "lib/psych/nodes/node.rb", "lib/psych/nodes/scalar.rb", "lib/psych/nodes/sequence.rb", "lib/psych/nodes/stream.rb", "lib/psych/omap.rb", "lib/psych/parser.rb", "lib/psych/scalar_scanner.rb", "lib/psych/set.rb", "lib/psych/stream.rb", "lib/psych/streaming.rb", "lib/psych/syntax_error.rb", "lib/psych/tree_builder.rb", "lib/psych/versions.rb", "lib/psych/visitors.rb","lib/psych/visitors/depth_first.rb", "lib/psych/visitors/emitter.rb", "lib/psych/visitors/json_tree.rb", "lib/psych/visitors/to_ruby.rb", "lib/psych/visitors/visitor.rb", "lib/psych/visitors/yaml_tree.rb", "lib/psych/y.rb", "psych.gemspec"]
|
||||||
|
|
||||||
s.rdoc_options = ["--main", "README.md"]
|
s.rdoc_options = ["--main", "README.md"]
|
||||||
s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md"]
|
s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md"]
|
||||||
|
|
|
@ -3504,12 +3504,12 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
|
||||||
{
|
{
|
||||||
if (IS_BLANK(parser->buffer))
|
if (IS_BLANK(parser->buffer))
|
||||||
{
|
{
|
||||||
/* Check for tab character that abuse indentation. */
|
/* Check for tab characters that abuse indentation. */
|
||||||
|
|
||||||
if (leading_blanks && (int)parser->mark.column < indent
|
if (leading_blanks && (int)parser->mark.column < indent
|
||||||
&& IS_TAB(parser->buffer)) {
|
&& IS_TAB(parser->buffer)) {
|
||||||
yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
|
yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
|
||||||
start_mark, "found a tab character that violate indentation");
|
start_mark, "found a tab character that violates indentation");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,10 +50,10 @@ module Psych
|
||||||
def assert_to_yaml( obj, yaml )
|
def assert_to_yaml( obj, yaml )
|
||||||
assert_equal( obj, Psych::load( yaml ) )
|
assert_equal( obj, Psych::load( yaml ) )
|
||||||
assert_equal( obj, Psych::parse( yaml ).transform )
|
assert_equal( obj, Psych::parse( yaml ).transform )
|
||||||
assert_equal( obj, Psych::load( obj.psych_to_yaml ) )
|
assert_equal( obj, Psych::load( obj.to_yaml ) )
|
||||||
assert_equal( obj, Psych::parse( obj.psych_to_yaml ).transform )
|
assert_equal( obj, Psych::parse( obj.to_yaml ).transform )
|
||||||
assert_equal( obj, Psych::load(
|
assert_equal( obj, Psych::load(
|
||||||
obj.psych_to_yaml(
|
obj.to_yaml(
|
||||||
:UseVersion => true, :UseHeader => true, :SortKeys => true
|
:UseVersion => true, :UseHeader => true, :SortKeys => true
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
@ -70,9 +70,15 @@ module Psych
|
||||||
def assert_cycle( obj )
|
def assert_cycle( obj )
|
||||||
v = Visitors::YAMLTree.create
|
v = Visitors::YAMLTree.create
|
||||||
v << obj
|
v << obj
|
||||||
assert_equal(obj, Psych.load(v.tree.yaml))
|
if obj.nil?
|
||||||
assert_equal( obj, Psych::load(Psych.dump(obj)))
|
assert_nil Psych.load(v.tree.yaml)
|
||||||
assert_equal( obj, Psych::load( obj.psych_to_yaml ) )
|
assert_nil Psych::load(Psych.dump(obj))
|
||||||
|
assert_nil Psych::load(obj.to_yaml)
|
||||||
|
else
|
||||||
|
assert_equal(obj, Psych.load(v.tree.yaml))
|
||||||
|
assert_equal(obj, Psych::load(Psych.dump(obj)))
|
||||||
|
assert_equal(obj, Psych::load(obj.to_yaml))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Psych
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_another_subclass_with_attributes
|
def test_another_subclass_with_attributes
|
||||||
y = Y.new.tap {|y| y.val = 1}
|
y = Y.new.tap {|o| o.val = 1}
|
||||||
y << "foo" << "bar"
|
y << "foo" << "bar"
|
||||||
y = Psych.load Psych.dump y
|
y = Psych.load Psych.dump y
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ module Psych
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_subclass_with_attributes
|
def test_subclass_with_attributes
|
||||||
y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
|
y = Psych.load Psych.dump Y.new.tap {|o| o.val = 1}
|
||||||
assert_equal Y, y.class
|
assert_equal Y, y.class
|
||||||
assert_equal 1, y.val
|
assert_equal 1, y.val
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ require 'date'
|
||||||
module Psych
|
module Psych
|
||||||
class TestDateTime < TestCase
|
class TestDateTime < TestCase
|
||||||
def test_negative_year
|
def test_negative_year
|
||||||
time = Time.utc -1, 12, 16
|
time = Time.utc(-1, 12, 16)
|
||||||
assert_cycle time
|
assert_cycle time
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,47 +8,12 @@ module Psych
|
||||||
Psych.domain_types.clear
|
Psych.domain_types.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
class QuickEmitter
|
class QuickEmitter; end
|
||||||
attr_reader :name
|
|
||||||
attr_reader :value
|
|
||||||
|
|
||||||
def initialize
|
|
||||||
@name = 'hello!!'
|
|
||||||
@value = 'Friday!'
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_yaml opts = {}
|
|
||||||
Psych.quick_emit object_id, opts do |out|
|
|
||||||
out.map taguri, to_yaml_style do |map|
|
|
||||||
map.add 'name', @name
|
|
||||||
map.add 'value', nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@qe = QuickEmitter.new
|
|
||||||
@orig_verbose, $VERBOSE = $VERBOSE, false
|
@orig_verbose, $VERBOSE = $VERBOSE, false
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_quick_emit
|
|
||||||
qe2 = Psych.load @qe.to_yaml
|
|
||||||
assert_equal @qe.name, qe2.name
|
|
||||||
assert_instance_of QuickEmitter, qe2
|
|
||||||
assert_nil qe2.value
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_recursive_quick_emit
|
|
||||||
hash = { :qe => @qe }
|
|
||||||
hash2 = Psych.load Psych.dump hash
|
|
||||||
qe = hash2[:qe]
|
|
||||||
|
|
||||||
assert_equal @qe.name, qe.name
|
|
||||||
assert_instance_of QuickEmitter, qe
|
|
||||||
assert_nil qe.value
|
|
||||||
end
|
|
||||||
|
|
||||||
class QuickEmitterEncodeWith
|
class QuickEmitterEncodeWith
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
|
@ -84,30 +49,6 @@ module Psych
|
||||||
assert_nil qe.value
|
assert_nil qe.value
|
||||||
end
|
end
|
||||||
|
|
||||||
class YamlInit
|
|
||||||
attr_reader :name
|
|
||||||
attr_reader :value
|
|
||||||
|
|
||||||
def initialize
|
|
||||||
@name = 'hello!!'
|
|
||||||
@value = 'Friday!'
|
|
||||||
end
|
|
||||||
|
|
||||||
def yaml_initialize tag, vals
|
|
||||||
vals.each { |ivar, val| instance_variable_set "@#{ivar}", 'TGIF!' }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_yaml_initialize
|
|
||||||
hash = { :yi => YamlInit.new }
|
|
||||||
hash2 = Psych.load Psych.dump hash
|
|
||||||
yi = hash2[:yi]
|
|
||||||
|
|
||||||
assert_equal 'TGIF!', yi.name
|
|
||||||
assert_equal 'TGIF!', yi.value
|
|
||||||
assert_instance_of YamlInit, yi
|
|
||||||
end
|
|
||||||
|
|
||||||
class YamlInitAndInitWith
|
class YamlInitAndInitWith
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
|
@ -146,70 +87,5 @@ module Psych
|
||||||
assert_equal 'some string', coder.scalar
|
assert_equal 'some string', coder.scalar
|
||||||
assert_equal :scalar, coder.type
|
assert_equal :scalar, coder.type
|
||||||
end
|
end
|
||||||
|
|
||||||
class YamlAs
|
|
||||||
TestCase.suppress_warning do
|
|
||||||
psych_yaml_as 'helloworld' # this should be yaml_as but to avoid syck
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_yaml_as
|
|
||||||
assert_match(/helloworld/, Psych.dump(YamlAs.new))
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_ruby_type
|
|
||||||
types = []
|
|
||||||
appender = lambda { |*args| types << args }
|
|
||||||
|
|
||||||
Psych.add_ruby_type('foo', &appender)
|
|
||||||
Psych.load <<-eoyml
|
|
||||||
- !ruby.yaml.org,2002/foo bar
|
|
||||||
eoyml
|
|
||||||
|
|
||||||
assert_equal [["tag:ruby.yaml.org,2002:foo", "bar"]], types
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_detect_implicit
|
|
||||||
assert_equal '', Psych.detect_implicit(nil)
|
|
||||||
assert_equal '', Psych.detect_implicit(Object.new)
|
|
||||||
assert_equal '', Psych.detect_implicit(1.2)
|
|
||||||
assert_equal 'null', Psych.detect_implicit('')
|
|
||||||
assert_equal 'string', Psych.detect_implicit('foo')
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_private_type
|
|
||||||
types = []
|
|
||||||
Psych.add_private_type('foo') { |*args| types << args }
|
|
||||||
Psych.load <<-eoyml
|
|
||||||
- !x-private:foo bar
|
|
||||||
eoyml
|
|
||||||
|
|
||||||
assert_equal [["x-private:foo", "bar"]], types
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_tagurize
|
|
||||||
assert_nil Psych.tagurize nil
|
|
||||||
assert_equal Psych, Psych.tagurize(Psych)
|
|
||||||
assert_equal 'tag:yaml.org,2002:foo', Psych.tagurize('foo')
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_read_type_class
|
|
||||||
things = Psych.read_type_class 'tag:yaml.org,2002:int:Psych::TestDeprecated::QuickEmitter', Object
|
|
||||||
assert_equal 'int', things.first
|
|
||||||
assert_equal Psych::TestDeprecated::QuickEmitter, things.last
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_read_type_class_no_class
|
|
||||||
things = Psych.read_type_class 'tag:yaml.org,2002:int', Object
|
|
||||||
assert_equal 'int', things.first
|
|
||||||
assert_equal Object, things.last
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_object_maker
|
|
||||||
thing = Psych.object_maker(Object, { 'a' => 'b', 'c' => 'd' })
|
|
||||||
assert_instance_of(Object, thing)
|
|
||||||
assert_equal 'b', thing.instance_variable_get(:@a)
|
|
||||||
assert_equal 'd', thing.instance_variable_get(:@c)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -121,19 +121,6 @@ module Psych
|
||||||
assert_equal 2, w.bar
|
assert_equal 2, w.bar
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_yaml_properties
|
|
||||||
class << @wups
|
|
||||||
def to_yaml_properties
|
|
||||||
[:@foo]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
w = Psych.load(Psych.dump(@wups))
|
|
||||||
assert_equal @wups, w
|
|
||||||
assert_equal 1, w.foo
|
|
||||||
assert_nil w.bar
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_psych_syntax_error
|
def test_psych_syntax_error
|
||||||
Tempfile.create(['parsefile', 'yml']) do |t|
|
Tempfile.create(['parsefile', 'yml']) do |t|
|
||||||
t.binmode
|
t.binmode
|
||||||
|
|
|
@ -98,8 +98,8 @@ class TestPsych < Psych::TestCase
|
||||||
assert_equal Psych.libyaml_version.join('.'), Psych::LIBYAML_VERSION
|
assert_equal Psych.libyaml_version.join('.'), Psych::LIBYAML_VERSION
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_load_documents
|
def test_load_stream
|
||||||
docs = Psych.load_documents("--- foo\n...\n--- bar\n...")
|
docs = Psych.load_stream("--- foo\n...\n--- bar\n...")
|
||||||
assert_equal %w{ foo bar }, docs
|
assert_equal %w{ foo bar }, docs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -79,15 +79,21 @@ module Psych
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_scan_null
|
def test_scan_null
|
||||||
assert_equal nil, ss.tokenize('null')
|
assert_nil ss.tokenize('null')
|
||||||
assert_equal nil, ss.tokenize('~')
|
assert_nil ss.tokenize('~')
|
||||||
assert_equal nil, ss.tokenize('')
|
assert_nil ss.tokenize('')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_scan_symbol
|
def test_scan_symbol
|
||||||
assert_equal :foo, ss.tokenize(':foo')
|
assert_equal :foo, ss.tokenize(':foo')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_scan_not_sexagesimal
|
||||||
|
assert_equal '00:00:00:00:0f', ss.tokenize('00:00:00:00:0f')
|
||||||
|
assert_equal '00:00:00:00:00', ss.tokenize('00:00:00:00:00')
|
||||||
|
assert_equal '00:00:00:00:00.0', ss.tokenize('00:00:00:00:00.0')
|
||||||
|
end
|
||||||
|
|
||||||
def test_scan_sexagesimal_float
|
def test_scan_sexagesimal_float
|
||||||
assert_equal 685230.15, ss.tokenize('190:20:30.15')
|
assert_equal 685230.15, ss.tokenize('190:20:30.15')
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,28 +33,28 @@ module Psych
|
||||||
def test_doublequotes_when_there_is_a_single
|
def test_doublequotes_when_there_is_a_single
|
||||||
str = "@123'abc"
|
str = "@123'abc"
|
||||||
yaml = Psych.dump str
|
yaml = Psych.dump str
|
||||||
assert_match /---\s*"/, yaml
|
assert_match(/---\s*"/, yaml)
|
||||||
assert_equal str, Psych.load(yaml)
|
assert_equal str, Psych.load(yaml)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_plain_when_shorten_than_line_width_and_no_final_line_break
|
def test_plain_when_shorten_than_line_width_and_no_final_line_break
|
||||||
str = "Lorem ipsum"
|
str = "Lorem ipsum"
|
||||||
yaml = Psych.dump str, line_width: 12
|
yaml = Psych.dump str, line_width: 12
|
||||||
assert_match /---\s*[^>|]+\n/, yaml
|
assert_match(/---\s*[^>|]+\n/, yaml)
|
||||||
assert_equal str, Psych.load(yaml)
|
assert_equal str, Psych.load(yaml)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_plain_when_shorten_than_line_width_and_with_final_line_break
|
def test_plain_when_shorten_than_line_width_and_with_final_line_break
|
||||||
str = "Lorem ipsum\n"
|
str = "Lorem ipsum\n"
|
||||||
yaml = Psych.dump str, line_width: 12
|
yaml = Psych.dump str, line_width: 12
|
||||||
assert_match /---\s*[^>|]+\n/, yaml
|
assert_match(/---\s*[^>|]+\n/, yaml)
|
||||||
assert_equal str, Psych.load(yaml)
|
assert_equal str, Psych.load(yaml)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_folded_when_longer_than_line_width_and_with_final_line_break
|
def test_folded_when_longer_than_line_width_and_with_final_line_break
|
||||||
str = "Lorem ipsum dolor sit\n"
|
str = "Lorem ipsum dolor sit\n"
|
||||||
yaml = Psych.dump str, line_width: 12
|
yaml = Psych.dump str, line_width: 12
|
||||||
assert_match /---\s*>\n(.*\n){2}\Z/, yaml
|
assert_match(/---\s*>\n(.*\n){2}\Z/, yaml)
|
||||||
assert_equal str, Psych.load(yaml)
|
assert_equal str, Psych.load(yaml)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ module Psych
|
||||||
def test_folded_strip_when_longer_than_line_width_and_no_newlines
|
def test_folded_strip_when_longer_than_line_width_and_no_newlines
|
||||||
str = "Lorem ipsum dolor sit amet, consectetur"
|
str = "Lorem ipsum dolor sit amet, consectetur"
|
||||||
yaml = Psych.dump str, line_width: 12
|
yaml = Psych.dump str, line_width: 12
|
||||||
assert_match /---\s*>-\n(.*\n){3}\Z/, yaml
|
assert_match(/---\s*>-\n(.*\n){3}\Z/, yaml)
|
||||||
assert_equal str, Psych.load(yaml)
|
assert_equal str, Psych.load(yaml)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ module Psych
|
||||||
"Lorem ipsum\nZolor\n",
|
"Lorem ipsum\nZolor\n",
|
||||||
].each do |str|
|
].each do |str|
|
||||||
yaml = Psych.dump str, line_width: 12
|
yaml = Psych.dump str, line_width: 12
|
||||||
assert_match /---\s*\|\n(.*\n){2}\Z/, yaml
|
assert_match(/---\s*\|\n(.*\n){2}\Z/, yaml)
|
||||||
assert_equal str, Psych.load(yaml)
|
assert_equal str, Psych.load(yaml)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -84,7 +84,7 @@ module Psych
|
||||||
"Lorem ipsum\nZolor",
|
"Lorem ipsum\nZolor",
|
||||||
].each do |str|
|
].each do |str|
|
||||||
yaml = Psych.dump str, line_width: 12
|
yaml = Psych.dump str, line_width: 12
|
||||||
assert_match /---\s*\|-\n(.*\n){2}\Z/, yaml
|
assert_match(/---\s*\|-\n(.*\n){2}\Z/, yaml)
|
||||||
assert_equal str, Psych.load(yaml)
|
assert_equal str, Psych.load(yaml)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -129,7 +129,7 @@ string: &70121654388580 !ruby/string
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_another_subclass_with_attributes
|
def test_another_subclass_with_attributes
|
||||||
y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1}
|
y = Psych.load Psych.dump Y.new("foo").tap {|o| o.val = 1}
|
||||||
assert_equal "foo", y
|
assert_equal "foo", y
|
||||||
assert_equal Y, y.class
|
assert_equal Y, y.class
|
||||||
assert_equal 1, y.val
|
assert_equal 1, y.val
|
||||||
|
@ -154,7 +154,7 @@ string: &70121654388580 !ruby/string
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_subclass_with_attributes
|
def test_subclass_with_attributes
|
||||||
y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
|
y = Psych.load Psych.dump Y.new.tap {|o| o.val = 1}
|
||||||
assert_equal Y, y.class
|
assert_equal Y, y.class
|
||||||
assert_equal 1, y.val
|
assert_equal 1, y.val
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
# frozen_string_literal: false
|
|
||||||
require_relative 'helper'
|
|
||||||
|
|
||||||
module Psych
|
|
||||||
class TestToYamlProperties < Psych::TestCase
|
|
||||||
class Foo
|
|
||||||
attr_accessor :a, :b, :c
|
|
||||||
def initialize
|
|
||||||
@a = 1
|
|
||||||
@b = 2
|
|
||||||
@c = 3
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_yaml_properties
|
|
||||||
[:@a, :@b]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_object_dump_yaml_properties
|
|
||||||
foo = Psych.load(Psych.dump(Foo.new))
|
|
||||||
assert_equal 1, foo.a
|
|
||||||
assert_equal 2, foo.b
|
|
||||||
assert_nil foo.c
|
|
||||||
end
|
|
||||||
|
|
||||||
class Bar < Struct.new(:foo, :bar)
|
|
||||||
attr_reader :baz
|
|
||||||
def initialize *args
|
|
||||||
super
|
|
||||||
@baz = 'hello'
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_yaml_properties
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_struct_dump_yaml_properties
|
|
||||||
bar = Psych.load(Psych.dump(Bar.new('a', 'b')))
|
|
||||||
assert_equal 'a', bar.foo
|
|
||||||
assert_equal 'b', bar.bar
|
|
||||||
assert_nil bar.baz
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_string_dump
|
|
||||||
string = "okonomiyaki"
|
|
||||||
class << string
|
|
||||||
def to_yaml_properties
|
|
||||||
[:@tastes]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
string.instance_variable_set(:@tastes, 'delicious')
|
|
||||||
v = Psych.load Psych.dump string
|
|
||||||
assert_equal 'delicious', v.instance_variable_get(:@tastes)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_string_load_syck
|
|
||||||
str = Psych.load("--- !str \nstr: okonomiyaki\n:@tastes: delicious\n")
|
|
||||||
assert_equal 'okonomiyaki', str
|
|
||||||
assert_equal 'delicious', str.instance_variable_get(:@tastes)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -512,7 +512,7 @@ EOY
|
||||||
|
|
||||||
def test_spec_log_file
|
def test_spec_log_file
|
||||||
doc_ct = 0
|
doc_ct = 0
|
||||||
Psych::load_documents( <<EOY
|
Psych::load_stream( <<EOY
|
||||||
---
|
---
|
||||||
Time: 2001-11-23 15:01:42 -05:00
|
Time: 2001-11-23 15:01:42 -05:00
|
||||||
User: ed
|
User: ed
|
||||||
|
@ -585,7 +585,7 @@ EOY
|
||||||
|
|
||||||
def test_spec_oneline_docs
|
def test_spec_oneline_docs
|
||||||
doc_ct = 0
|
doc_ct = 0
|
||||||
Psych::load_documents( <<EOY
|
Psych::load_stream( <<EOY
|
||||||
# The following is a sequence of three documents.
|
# The following is a sequence of three documents.
|
||||||
# The first contains an empty mapping, the second
|
# The first contains an empty mapping, the second
|
||||||
# an empty sequence, and the last an empty string.
|
# an empty sequence, and the last an empty string.
|
||||||
|
|
|
@ -165,10 +165,10 @@ module Psych
|
||||||
# http://yaml.org/type/null.html
|
# http://yaml.org/type/null.html
|
||||||
def test_nil
|
def test_nil
|
||||||
assert_cycle nil
|
assert_cycle nil
|
||||||
assert_equal nil, Psych.load('null')
|
assert_nil Psych.load('null')
|
||||||
assert_equal nil, Psych.load('Null')
|
assert_nil Psych.load('Null')
|
||||||
assert_equal nil, Psych.load('NULL')
|
assert_nil Psych.load('NULL')
|
||||||
assert_equal nil, Psych.load('~')
|
assert_nil Psych.load('~')
|
||||||
assert_equal({'foo' => nil}, Psych.load('foo: '))
|
assert_equal({'foo' => nil}, Psych.load('foo: '))
|
||||||
|
|
||||||
assert_cycle 'null'
|
assert_cycle 'null'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue