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

ruby-changes:40157

From: nobu <ko1@a...>
Date: Fri, 23 Oct 2015 13:51:44 +0900 (JST)
Subject: [ruby-changes:40157] nobu:r52238 (trunk): test_call.rb: add tests

nobu	2015-10-23 13:51:35 +0900 (Fri, 23 Oct 2015)

  New Revision: 52238

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

  Log:
    test_call.rb: add tests
    
    * test_call.rb (test_safe_call): Add test cases for safe
      navigation operator assignment.  [Fix GH-1064]
      Validate:
      * can assign an attribute which is `nil`
      * can "or assign" an attribute which is `nil`

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_call.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52237)
+++ ChangeLog	(revision 52238)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct 23 13:51:33 2015  yui-knk  <spiketeika@g...>
+
+	* test_call.rb (test_safe_call): Add test cases for safe
+	  navigation operator assignment.  [Fix GH-1064]
+	  Validate:
+	  * can assign an attribute which is `nil`
+	  * can "or assign" an attribute which is `nil`
+
 Fri Oct 23 11:58:21 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* compile.c (iseq_peephole_optimize): optimize lengthy safe
Index: test/ruby/test_call.rb
===================================================================
--- test/ruby/test_call.rb	(revision 52237)
+++ test/ruby/test_call.rb	(revision 52238)
@@ -33,7 +33,7 @@ class TestCall < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_call.rb#L33
   end
 
   def test_safe_call
-    s = Struct.new(:x, :y)
+    s = Struct.new(:x, :y, :z)
     o = s.new("x")
     assert_equal("X", o.x.?upcase)
     assert_nil(o.y.?upcase)
@@ -42,6 +42,10 @@ class TestCall < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_call.rb#L42
     assert_equal(6, o.x)
     o.?x *= 7
     assert_equal(42, o.x)
+    o.?y = 5
+    assert_equal(5, o.y)
+    o.?z ||= 6
+    assert_equal(6, o.z)
 
     o = nil
     assert_nil(o.?x)

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

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