Permalink
Browse files

add test case for ".?" method calling syntax.

  • Loading branch information...
Mekajiki committed Mar 4, 2012
1 parent 96b1fbf commit e949fd2ae294abd823cf665212a6bf5861e1e3eb
Showing with 76 additions and 3 deletions.
  1. +15 −3 parse.y
  2. +61 −0 test/ruby/test_parse.rb
View
18 parse.y
@@ -1344,7 +1344,7 @@ block_command : block_call
/*%%%*/
$$ = rb_new_node_qdot_call($1,$3,$4);
/*%
- $$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
+ $$ = dispatch3(call, $1, ripper_id2sym(".?"), $3);
$$ = method_arg($$, $4);
%*/
}
@@ -1417,7 +1417,7 @@ command : operation command_args %prec tLOWEST
$$ = rb_new_node_qdot_call($1, $3, $4);
fixpos($$, $1);
/*%
- $$ = dispatch4(command_call, $1, ripper_id2sym('.'), $3, $4);
+ $$ = dispatch4(command_call, $1, ripper_id2sym(".?"), $3, $4);
%*/
}
| primary_value '.' operation2 command_args cmd_brace_block
@@ -1432,6 +1432,18 @@ command : operation command_args %prec tLOWEST
$$ = method_add_block($$, $5);
%*/
}
+ | primary_value tQDOT operation2 command_args cmd_brace_block
+ {
+ /*%%%*/
+ block_dup_check($4,$5);
+ $5->nd_iter = rb_new_node_qdot_call($1, $3, $4);
+ $$ = $5;
+ fixpos($$, $1);
+ /*%
+ $$ = dispatch4(command_call, $1, ripper_id2sym(".?"), $3, $4);
+ $$ = method_add_block($$, $5);
+ %*/
+ }
| primary_value tCOLON2 operation2 command_args %prec tLOWEST
{
/*%%%*/
@@ -3892,7 +3904,7 @@ block_call : command do_block
/*%%%*/
$$ = rb_new_node_qdot_call($1, $3, $4)
/*%
- $$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
+ $$ = dispatch3(call, $1, ripper_id2sym(".?"), $3);
$$ = method_optarg($$, $4);
%*/
}
View
@@ -839,4 +839,65 @@ def test_method_block_location
actual = e.backtrace.first[/\A#{Regexp.quote(__FILE__)}:(\d+):/o, 1].to_i
assert_equal(expected, actual, bug5614)
end
+
+ def test_command_call_qdot
+ t = Object.new
+ def t.foo(x); x; end
+
+ a = b = c = d = nil
+ assert_nothing_raised do
+ eval <<-END
+ a = t.?foo 42
+ b = t.?foo(42)
+ c = t.?fooo 42
+ d = t.?fooo(42)
+ END
+ end
+ assert_equal([42, 42, nil, nil], [a, b, c, d])
+
+ t = Object.new
+ def t.foo(x, y); x + y; end
+ a = b = c = d = nil
+ assert_nothing_raised do
+ eval <<-END
+ a = t.?foo 39, 3
+ b = t.?foo(39, 3)
+ c = t.?fooo 39, 3
+ d = t.?fooo(39, 3)
+ END
+ end
+
+ assert_equal([42, 42, nil, nil], [a, b, c, d])
+
+ o = Object.new
+ class << o
+ attr_accessor :bar, :Bar, :qux
+ end
+ o.bar = o.Bar = o::qux = 1
+ a = b = c = d = e = 0
+ assert_nothing_raised do
+ eval <<-END
+ a = o.?bar
+ b = o.?Bar
+ c = o.?qux
+ d = o.?barr
+ e = 0.?Barr
+ END
+ end
+ assert_equal([1,1,1,nil,nil], [a,b,c,d,e])
+
+ o = Object.new
+ def o.foo(x); x + yield; end
+
+ a = b = nil
+ assert_nothing_raised do
+ o.instance_eval <<-END
+ a = foo 1 do 42 end.?to_s
+ b = foo 1 do 42 end.?to_ss
+ END
+ end
+ assert_equal("43", a)
+ assert_equal(nil, b)
+
+ end
end

0 comments on commit e949fd2

Please sign in to comment.