2017-07-14 02:15:58 -04:00
|
|
|
# frozen_string_literal: true
|
2013-03-26 10:55:04 -04:00
|
|
|
require_relative 'helper'
|
2010-04-09 16:33:10 -04:00
|
|
|
|
|
|
|
module Psych
|
|
|
|
class TestDeprecated < TestCase
|
2010-04-24 00:11:27 -04:00
|
|
|
def teardown
|
2013-04-01 22:14:21 -04:00
|
|
|
$VERBOSE = @orig_verbose
|
2010-04-24 00:11:27 -04:00
|
|
|
Psych.domain_types.clear
|
|
|
|
end
|
|
|
|
|
2017-04-05 09:16:32 -04:00
|
|
|
class QuickEmitter; end
|
2010-04-09 16:33:10 -04:00
|
|
|
|
|
|
|
def setup
|
2013-04-01 22:14:21 -04:00
|
|
|
@orig_verbose, $VERBOSE = $VERBOSE, false
|
2010-04-09 16:33:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class QuickEmitterEncodeWith
|
|
|
|
attr_reader :name
|
|
|
|
attr_reader :value
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@name = 'hello!!'
|
|
|
|
@value = 'Friday!'
|
|
|
|
end
|
|
|
|
|
|
|
|
def encode_with coder
|
|
|
|
coder.map do |map|
|
|
|
|
map.add 'name', @name
|
|
|
|
map.add 'value', nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_yaml opts = {}
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
###
|
|
|
|
# An object that defines both to_yaml and encode_with should only call
|
|
|
|
# encode_with.
|
|
|
|
def test_recursive_quick_emit_encode_with
|
|
|
|
qeew = QuickEmitterEncodeWith.new
|
|
|
|
hash = { :qe => qeew }
|
2021-05-10 12:50:06 -04:00
|
|
|
hash2 = Psych.unsafe_load Psych.dump hash
|
2010-04-09 16:33:10 -04:00
|
|
|
qe = hash2[:qe]
|
|
|
|
|
|
|
|
assert_equal qeew.name, qe.name
|
|
|
|
assert_instance_of QuickEmitterEncodeWith, qe
|
|
|
|
assert_nil qe.value
|
|
|
|
end
|
|
|
|
|
|
|
|
class YamlInitAndInitWith
|
|
|
|
attr_reader :name
|
|
|
|
attr_reader :value
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@name = 'shaners'
|
|
|
|
@value = 'Friday!'
|
|
|
|
end
|
|
|
|
|
|
|
|
def init_with coder
|
|
|
|
coder.map.each { |ivar, val| instance_variable_set "@#{ivar}", 'TGIF!' }
|
|
|
|
end
|
|
|
|
|
|
|
|
def yaml_initialize tag, vals
|
|
|
|
raise
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
###
|
|
|
|
# An object that implements both yaml_initialize and init_with should not
|
|
|
|
# receive the yaml_initialize call.
|
|
|
|
def test_yaml_initialize_and_init_with
|
|
|
|
hash = { :yi => YamlInitAndInitWith.new }
|
2021-05-10 12:50:06 -04:00
|
|
|
hash2 = Psych.unsafe_load Psych.dump hash
|
2010-04-09 16:33:10 -04:00
|
|
|
yi = hash2[:yi]
|
|
|
|
|
|
|
|
assert_equal 'TGIF!', yi.name
|
|
|
|
assert_equal 'TGIF!', yi.value
|
|
|
|
assert_instance_of YamlInitAndInitWith, yi
|
|
|
|
end
|
2010-04-16 16:27:51 -04:00
|
|
|
|
|
|
|
def test_coder_scalar
|
|
|
|
coder = Psych::Coder.new 'foo'
|
|
|
|
coder.scalar('tag', 'some string', :plain)
|
|
|
|
assert_equal 'tag', coder.tag
|
|
|
|
assert_equal 'some string', coder.scalar
|
|
|
|
assert_equal :scalar, coder.type
|
|
|
|
end
|
2010-04-09 16:33:10 -04:00
|
|
|
end
|
|
|
|
end
|