diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-01 09:01:16 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-01 09:01:16 +0000 |
commit | 6bdfe415df2ef15487ba932762c028640b8ff71a (patch) | |
tree | 7b97e0a7804c57c23191d7bf3d708e2aee1df6ab | |
parent | 4a223fb67f31a1a85a0b4fb019a1106532a541ce (diff) |
* lib/set.rb (Set#freeze, taint, untaint): Save a "self" by
utilizing super returning self, and add tests while at it.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/set.rb | 9 | ||||
-rw-r--r-- | test/test_set.rb | 21 |
3 files changed, 29 insertions, 6 deletions
@@ -1,3 +1,8 @@ +Sat Jun 1 17:58:13 2013 Akinori MUSHA <[email protected]> + + * lib/set.rb (Set#freeze, taint, untaint): Save a "self" by + utilizing super returning self, and add tests while at it. + Sat Jun 1 17:24:47 2013 Nobuyoshi Nakada <[email protected]> * compile.c (iseq_set_arguments): not a simple single argument if any diff --git a/lib/set.rb b/lib/set.rb index cc7542f223..a9aa7e7936 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -99,21 +99,18 @@ class Set end def freeze # :nodoc: - super @hash.freeze - self + super end def taint # :nodoc: - super @hash.taint - self + super end def untaint # :nodoc: - super @hash.untaint - self + super end # Returns the number of elements. diff --git a/test/test_set.rb b/test/test_set.rb index 904118250c..26950c3e30 100644 --- a/test/test_set.rb +++ b/test/test_set.rb @@ -528,6 +528,27 @@ class TC_Set < Test::Unit::TestCase } end + def test_taintness + orig = set = Set[1,2,3] + assert_equal false, set.tainted? + assert_same orig, set.taint + assert_equal true, set.tainted? + assert_same orig, set.untaint + assert_equal false, set.tainted? + end + + def test_freeze + orig = set = Set[1,2,3] + assert_equal false, set.frozen? + set << 4 + assert_same orig, set.freeze + assert_equal true, set.frozen? + assert_raises(RuntimeError) { + set << 5 + } + assert_equal 4, set.size + end + def test_inspect set1 = Set[1] |