mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Allow a SortedSet to be frozen and still functional [Bug #12091]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b867882a1c
commit
3090169c9b
2 changed files with 44 additions and 0 deletions
|
@ -723,6 +723,11 @@ class SortedSet < Set
|
|||
(@keys = @hash.keys).sort! unless @keys
|
||||
@keys
|
||||
end
|
||||
|
||||
def freeze
|
||||
to_a
|
||||
super
|
||||
end
|
||||
END
|
||||
end
|
||||
module_eval {
|
||||
|
|
|
@ -829,6 +829,45 @@ class TC_SortedSet < Test::Unit::TestCase
|
|||
set << 42
|
||||
assert_equal(7, e.size)
|
||||
end
|
||||
|
||||
def test_freeze
|
||||
orig = set = SortedSet[3,2,1]
|
||||
assert_equal false, set.frozen?
|
||||
set << 4
|
||||
assert_same orig, set.freeze
|
||||
assert_equal true, set.frozen?
|
||||
assert_raise(RuntimeError) {
|
||||
set << 5
|
||||
}
|
||||
assert_equal 4, set.size
|
||||
|
||||
# https://bugs.ruby-lang.org/issues/12091
|
||||
assert_nothing_raised {
|
||||
assert_equal [1,2,3,4], set.to_a
|
||||
}
|
||||
end
|
||||
|
||||
def test_freeze_dup
|
||||
set1 = SortedSet[1,2,3]
|
||||
set1.freeze
|
||||
set2 = set1.dup
|
||||
|
||||
assert_not_predicate set2, :frozen?
|
||||
assert_nothing_raised {
|
||||
set2.add 4
|
||||
}
|
||||
end
|
||||
|
||||
def test_freeze_clone
|
||||
set1 = SortedSet[1,2,3]
|
||||
set1.freeze
|
||||
set2 = set1.clone
|
||||
|
||||
assert_predicate set2, :frozen?
|
||||
assert_raise(RuntimeError) {
|
||||
set2.add 5
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
class TC_Enumerable < Test::Unit::TestCase
|
||||
|
|
Loading…
Reference in a new issue