aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_call.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-22 06:30:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-22 06:30:12 +0000
commite2ac7b3d8b58816813ad1d05ed86fec8c80973d6 (patch)
treebee931e36267315487d45d5776ae8f4a568feddf /test/ruby/test_call.rb
parentc17cfbea9a4cf6e12d7feae2fdda50457590af6a (diff)
downloadruby-e2ac7b3d8b58816813ad1d05ed86fec8c80973d6.tar.gz
Safe navigation operator
* compile.c (iseq_peephole_optimize): peephole optimization for branchnil jumps. * compile.c (iseq_compile_each): generate save navigation operator code. * insns.def (branchnil): new opcode to pop the tos and branch if it is nil. * parse.y (NEW_QCALL, call_op, parser_yylex): parse token '.?'. [Feature #11537] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_call.rb')
-rw-r--r--test/ruby/test_call.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/ruby/test_call.rb b/test/ruby/test_call.rb
index 5b81eb187a..14b6a6431b 100644
--- a/test/ruby/test_call.rb
+++ b/test/ruby/test_call.rb
@@ -31,4 +31,16 @@ class TestCall < Test::Unit::TestCase
assert_nothing_raised(ArgumentError) {o.foo}
assert_raise_with_message(ArgumentError, e.message, bug9622) {o.foo(100)}
end
+
+ def test_safe_call
+ s = Struct.new(:x, :y)
+ o = s.new("x")
+ assert_equal("X", o.x.?upcase)
+ assert_nil(o.y.?upcase)
+ assert_equal("x", o.x)
+ o.?x = 6
+ assert_equal(6, o.x)
+ o.?x *= 7
+ assert_equal(42, o.x)
+ end
end