[前][次][番号順一覧][スレッド一覧]

ruby-changes:28970

From: knu <ko1@a...>
Date: Sat, 1 Jun 2013 18:02:11 +0900 (JST)
Subject: [ruby-changes:28970] knu:r41022 (trunk): * lib/set.rb (Set#freeze, taint, untaint): Save a "self" by

knu	2013-06-01 18:01:16 +0900 (Sat, 01 Jun 2013)

  New Revision: 41022

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41022

  Log:
    * lib/set.rb (Set#freeze, taint, untaint): Save a "self" by
      utilizing super returning self, and add tests while at it.

  Modified files:
    trunk/ChangeLog
    trunk/lib/set.rb
    trunk/test/test_set.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41021)
+++ ChangeLog	(revision 41022)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun  1 17:58:13 2013  Akinori MUSHA  <knu@i...>
+
+	* 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  <nobu@r...>
 
 	* compile.c (iseq_set_arguments): not a simple single argument if any
Index: lib/set.rb
===================================================================
--- lib/set.rb	(revision 41021)
+++ lib/set.rb	(revision 41022)
@@ -99,21 +99,18 @@ class Set https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L99
   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.
Index: test/test_set.rb
===================================================================
--- test/test_set.rb	(revision 41021)
+++ test/test_set.rb	(revision 41022)
@@ -528,6 +528,27 @@ class TC_Set < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_set.rb#L528
     }
   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]
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]