diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-21 15:38:38 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-21 15:38:38 +0000 |
commit | 3090169c9b5077ebcd051f9081c3a0baa8ff83e4 (patch) | |
tree | b3738451ebda87adec3c8e997cdf6427de3f1414 /test | |
parent | b867882a1c2a358bb7a46f84365c86a959d35240 (diff) | |
download | ruby-3090169c9b5077ebcd051f9081c3a0baa8ff83e4.tar.gz |
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
Diffstat (limited to 'test')
-rw-r--r-- | test/test_set.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/test_set.rb b/test/test_set.rb index daae12723d..33802410af 100644 --- a/test/test_set.rb +++ b/test/test_set.rb @@ -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 |