summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/psych/test_psych_set.rb57
-rw-r--r--test/psych/test_set.rb61
2 files changed, 77 insertions, 41 deletions
diff --git a/test/psych/test_psych_set.rb b/test/psych/test_psych_set.rb
new file mode 100644
index 0000000000..c72cd73f18
--- /dev/null
+++ b/test/psych/test_psych_set.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+require_relative 'helper'
+
+module Psych
+ class TestPsychSet < TestCase
+ def setup
+ super
+ @set = Psych::Set.new
+ @set['foo'] = 'bar'
+ @set['bar'] = 'baz'
+ end
+
+ def test_dump
+ assert_match(/!set/, Psych.dump(@set))
+ end
+
+ def test_roundtrip
+ assert_cycle(@set)
+ end
+
+ ###
+ # FIXME: Syck should also support !!set as shorthand
+ def test_load_from_yaml
+ loaded = Psych.unsafe_load(<<-eoyml)
+--- !set
+foo: bar
+bar: baz
+ eoyml
+ assert_equal(@set, loaded)
+ end
+
+ def test_loaded_class
+ assert_instance_of(Psych::Set, Psych.unsafe_load(Psych.dump(@set)))
+ end
+
+ def test_set_shorthand
+ loaded = Psych.unsafe_load(<<-eoyml)
+--- !!set
+foo: bar
+bar: baz
+ eoyml
+ assert_instance_of(Psych::Set, loaded)
+ end
+
+ def test_set_self_reference
+ @set['self'] = @set
+ assert_cycle(@set)
+ end
+
+ def test_stringify_names
+ @set[:symbol] = :value
+
+ assert_match(/^:symbol: :value/, Psych.dump(@set))
+ assert_match(/^symbol: :value/, Psych.dump(@set, stringify_names: true))
+ end
+ end
+end
diff --git a/test/psych/test_set.rb b/test/psych/test_set.rb
index b4968d3425..ccd591c626 100644
--- a/test/psych/test_set.rb
+++ b/test/psych/test_set.rb
@@ -1,57 +1,36 @@
+# encoding: UTF-8
# frozen_string_literal: true
require_relative 'helper'
+require 'set' unless defined?(Set)
module Psych
class TestSet < TestCase
def setup
- super
- @set = Psych::Set.new
- @set['foo'] = 'bar'
- @set['bar'] = 'baz'
+ @set = ::Set.new([1, 2, 3])
end
def test_dump
- assert_match(/!set/, Psych.dump(@set))
+ assert_equal <<~YAML, Psych.dump(@set)
+ --- !ruby/object:Set
+ hash:
+ 1: true
+ 2: true
+ 3: true
+ YAML
end
- def test_roundtrip
- assert_cycle(@set)
- end
-
- ###
- # FIXME: Syck should also support !!set as shorthand
- def test_load_from_yaml
- loaded = Psych.unsafe_load(<<-eoyml)
---- !set
-foo: bar
-bar: baz
- eoyml
- assert_equal(@set, loaded)
+ 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_loaded_class
- assert_instance_of(Psych::Set, Psych.unsafe_load(Psych.dump(@set)))
- end
-
- def test_set_shorthand
- loaded = Psych.unsafe_load(<<-eoyml)
---- !!set
-foo: bar
-bar: baz
- eoyml
- assert_instance_of(Psych::Set, loaded)
- end
-
- def test_set_self_reference
- @set['self'] = @set
- assert_cycle(@set)
- end
-
- def test_stringify_names
- @set[:symbol] = :value
-
- assert_match(/^:symbol: :value/, Psych.dump(@set))
- assert_match(/^symbol: :value/, Psych.dump(@set, stringify_names: true))
+ def test_roundtrip
+ assert_equal @set, Psych.load(Psych.dump(@set), permitted_classes: [::Set])
end
end
end