1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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`

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-10-23 04:51:35 +00:00
parent ae8f8fddb0
commit 1d3c07633c
2 changed files with 13 additions and 1 deletions

View file

@ -1,3 +1,11 @@
Fri Oct 23 13:51:33 2015 yui-knk <spiketeika@gmail.com>
* 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@ruby-lang.org> Fri Oct 23 11:58:21 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c (iseq_peephole_optimize): optimize lengthy safe * compile.c (iseq_peephole_optimize): optimize lengthy safe

View file

@ -33,7 +33,7 @@ class TestCall < Test::Unit::TestCase
end end
def test_safe_call def test_safe_call
s = Struct.new(:x, :y) s = Struct.new(:x, :y, :z)
o = s.new("x") o = s.new("x")
assert_equal("X", o.x.?upcase) assert_equal("X", o.x.?upcase)
assert_nil(o.y.?upcase) assert_nil(o.y.?upcase)
@ -42,6 +42,10 @@ class TestCall < Test::Unit::TestCase
assert_equal(6, o.x) assert_equal(6, o.x)
o.?x *= 7 o.?x *= 7
assert_equal(42, o.x) assert_equal(42, o.x)
o.?y = 5
assert_equal(5, o.y)
o.?z ||= 6
assert_equal(6, o.z)
o = nil o = nil
assert_nil(o.?x) assert_nil(o.?x)