mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00

Since `Set` no longer is a regular object class holding a Hash
it needs to be specially handled.
c2d185d27c
36 lines
718 B
Ruby
36 lines
718 B
Ruby
# encoding: UTF-8
|
|
# frozen_string_literal: true
|
|
require_relative 'helper'
|
|
require 'set' unless defined?(Set)
|
|
|
|
module Psych
|
|
class TestSet < TestCase
|
|
def setup
|
|
@set = ::Set.new([1, 2, 3])
|
|
end
|
|
|
|
def test_dump
|
|
assert_equal <<~YAML, Psych.dump(@set)
|
|
--- !ruby/object:Set
|
|
hash:
|
|
1: true
|
|
2: true
|
|
3: true
|
|
YAML
|
|
end
|
|
|
|
def test_load
|
|
assert_equal @set, Psych.load(<<~YAML, permitted_classes: [::Set])
|
|
--- !ruby/object:Set
|
|
hash:
|
|
1: true
|
|
2: true
|
|
3: true
|
|
YAML
|
|
end
|
|
|
|
def test_roundtrip
|
|
assert_equal @set, Psych.load(Psych.dump(@set), permitted_classes: [::Set])
|
|
end
|
|
end
|
|
end
|