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

ruby-changes:32013

From: nobu <ko1@a...>
Date: Mon, 9 Dec 2013 16:13:42 +0900 (JST)
Subject: [ruby-changes:32013] nobu:r44092 (trunk): test_weakmap.rb: add

nobu	2013-12-09 16:13:38 +0900 (Mon, 09 Dec 2013)

  New Revision: 44092

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

  Log:
    test_weakmap.rb: add
    
    * test/ruby/test_weakmap.rb: test for ObjectSpace::WeakMap.

  Added files:
    trunk/test/ruby/test_weakmap.rb
Index: test/ruby/test_weakmap.rb
===================================================================
--- test/ruby/test_weakmap.rb	(revision 0)
+++ test/ruby/test_weakmap.rb	(revision 44092)
@@ -0,0 +1,96 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_weakmap.rb#L1
+require 'test/unit'
+require_relative 'envutil'
+
+class TestWeakMap < Test::Unit::TestCase
+  def setup
+    @wm = ObjectSpace::WeakMap.new
+  end
+
+  def test_map
+    x = Object.new
+    k = "foo"
+    @wm[k] = x
+    assert_same(x, @wm[k])
+    assert_not_same(x, @wm["FOO".downcase])
+  end
+
+  def test_include?
+    m = __callee__[/test_(.*)/, 1]
+    x = Object.new
+    k = "foo"
+    @wm[k] = x
+    assert_send([@wm, m, k])
+    assert_not_send([@wm, m, "FOO".downcase])
+    x = nil
+    GC.start
+    assert_not_send([@wm, m, k])
+  end
+  alias test_member? test_include?
+  alias test_key? test_include?
+
+  def test_each
+    m = __callee__[/test_(.*)/, 1]
+    x1 = Object.new
+    k1 = "foo"
+    @wm[k1] = x1
+    x2 = Object.new
+    k2 = "bar"
+    @wm[k2] = x2
+    n = 0
+    @wm.__send__(m) do |k, v|
+      assert_match(/\A(?:foo|bar)\z/, k)
+      case k
+      when /foo/
+        assert_same(k1, k)
+        assert_same(x1, v)
+      when /bar/
+        assert_same(k2, k)
+        assert_same(x2, v)
+      end
+      n += 1
+    end
+    assert_equal(2, n)
+  end
+
+  def test_each_key
+    x1 = Object.new
+    k1 = "foo"
+    @wm[k1] = x1
+    x2 = Object.new
+    k2 = "bar"
+    @wm[k2] = x2
+    n = 0
+    @wm.each_key do |k|
+      assert_match(/\A(?:foo|bar)\z/, k)
+      case k
+      when /foo/
+        assert_same(k1, k)
+      when /bar/
+        assert_same(k2, k)
+      end
+      n += 1
+    end
+    assert_equal(2, n)
+  end
+
+  def test_each_value
+    x1 = "foo"
+    k1 = Object.new
+    @wm[k1] = x1
+    x2 = "bar"
+    k2 = Object.new
+    @wm[k2] = x2
+    n = 0
+    @wm.each_value do |v|
+      assert_match(/\A(?:foo|bar)\z/, v)
+      case v
+      when /foo/
+        assert_same(x1, v)
+      when /bar/
+        assert_same(x2, v)
+      end
+      n += 1
+    end
+    assert_equal(2, n)
+  end
+end

Property changes on: test/ruby/test_weakmap.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


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

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