summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2025-04-29 00:38:35 +0900
committerGitHub <noreply@github.com>2025-04-28 08:38:35 -0700
commit926411171d296859839745a536aa86bc1e18aa76 (patch)
treebcdd6470cb594af4906e57bdedcf9d97f5e64362 /test/ruby
parent80a1a1bb8ae8435b916ae4f66a483e91ad31356a (diff)
Support Marshal.{dump,load} for core Set
This was missed when adding core Set, because it's handled implicitly for T_OBJECT. Keep marshal compatibility between core Set and stdlib Set, so you can unmarshal core Set with stdlib Set and vice versa. Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13185 Merged-By: jeremyevans <code@jeremyevans.net>
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_set.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/ruby/test_set.rb b/test/ruby/test_set.rb
index 565946096e..fd3ac4d9b6 100644
--- a/test/ruby/test_set.rb
+++ b/test/ruby/test_set.rb
@@ -6,6 +6,32 @@ class TC_Set < Test::Unit::TestCase
class Set2 < Set
end
+ def test_marshal
+ set = Set[1, 2, 3]
+ mset = Marshal.load(Marshal.dump(set))
+ assert_equal(set, mset)
+ assert_equal(set.compare_by_identity?, mset.compare_by_identity?)
+
+ set.compare_by_identity
+ mset = Marshal.load(Marshal.dump(set))
+ assert_equal(set, mset)
+ assert_equal(set.compare_by_identity?, mset.compare_by_identity?)
+
+ set.instance_variable_set(:@a, 1)
+ mset = Marshal.load(Marshal.dump(set))
+ assert_equal(set, mset)
+ assert_equal(set.compare_by_identity?, mset.compare_by_identity?)
+ assert_equal(1, mset.instance_variable_get(:@a))
+
+ old_stdlib_set_data = "\x04\bo:\bSet\x06:\n@hash}\bi\x06Ti\aTi\bTF".b
+ set = Marshal.load(old_stdlib_set_data)
+ assert_equal(Set[1, 2, 3], set)
+
+ old_stdlib_set_cbi_data = "\x04\bo:\bSet\x06:\n@hashC:\tHash}\ai\x06Ti\aTF".b
+ set = Marshal.load(old_stdlib_set_cbi_data)
+ assert_equal(Set[1, 2].compare_by_identity, set)
+ end
+
def test_aref
assert_nothing_raised {
Set[]