had forgotten calls on instance variables. corrected + tests
This commit is contained in:
parent
9ea0acf2e3
commit
1d10c2c03e
@ -40,6 +40,10 @@ module Ast
|
||||
def initialize name
|
||||
super( :_get_instance_variable , [StringExpression.new(name)] )
|
||||
end
|
||||
def inspect
|
||||
self.class.name + ".new(" + args[0].string.inspect + ")"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -9,7 +9,7 @@ module Parser
|
||||
space? >> right_parenthesis
|
||||
}
|
||||
|
||||
rule(:call_site) { ((module_name|name).as(:receiver) >> str(".")).maybe >> #possibly qualified
|
||||
rule(:call_site) { ((module_name|instance_variable|name).as(:receiver) >> str(".")).maybe >> #possibly qualified
|
||||
name.as(:call_site) >> argument_list >> comment.maybe}
|
||||
|
||||
|
||||
|
@ -8,14 +8,21 @@ class TestCallSite < MiniTest::Test
|
||||
@string_input = 'foo(42)'
|
||||
@parse_output = {:call_site => {:name => 'foo'},
|
||||
:argument_list => [{:argument => {:integer => '42'} }] }
|
||||
@transform_output = Ast::CallSiteExpression.new 'foo', [Ast::IntegerExpression.new(42)]
|
||||
@transform_output = Ast::CallSiteExpression.new :foo, [Ast::IntegerExpression.new(42)]
|
||||
@parser = @parser.call_site
|
||||
end
|
||||
|
||||
def test_single_self
|
||||
@string_input = 'self.foo(42)'
|
||||
@parse_output = {:receiver=>{:name=>"self"}, :call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"42"}}]}
|
||||
@transform_output = Ast::CallSiteExpression.new 'foo', [Ast::IntegerExpression.new(42)]
|
||||
@transform_output = Ast::CallSiteExpression.new :foo, [Ast::IntegerExpression.new(42)]
|
||||
@parser = @parser.call_site
|
||||
end
|
||||
|
||||
def test_single_instance
|
||||
@string_input = '@var.foo(42)'
|
||||
@parse_output = {:receiver=>{:instance_variable=>{:name=>"var"}}, :call_site=>{:name=>"foo"}, :argument_list=>[{:argument=>{:integer=>"42"}}]}
|
||||
@transform_output = Ast::CallSiteExpression.new(:foo, [Ast::IntegerExpression.new(42)] ,Ast::VariableExpression.new("var"))
|
||||
@parser = @parser.call_site
|
||||
end
|
||||
|
||||
@ -38,7 +45,7 @@ class TestCallSite < MiniTest::Test
|
||||
@parse_output = {:call_site => {:name => 'baz' },
|
||||
:argument_list => [{:argument => {:integer => '42'}},
|
||||
{:argument => {:name => 'foo'}}]}
|
||||
@transform_output = Ast::CallSiteExpression.new 'baz',
|
||||
@transform_output = Ast::CallSiteExpression.new :baz,
|
||||
[Ast::IntegerExpression.new(42), Ast::NameExpression.new("foo") ]
|
||||
@parser = @parser.call_site
|
||||
end
|
||||
@ -86,5 +93,11 @@ class TestCallSite < MiniTest::Test
|
||||
@transform_output = Ast::CallSiteExpression.new(:new, [Ast::CallSiteExpression.new(:get, [Ast::IntegerExpression.new(4)] ,Ast::NameExpression.new("self"))] ,Ast::ModuleName.new("Class"))
|
||||
@parser = @parser.call_site
|
||||
end
|
||||
def test_call_chaining_instance
|
||||
@string_input = '@class.new(self.get(4))'
|
||||
@parse_output = {:receiver=>{:instance_variable=>{:name=>"class"}}, :call_site=>{:name=>"new"}, :argument_list=>[{:argument=>{:receiver=>{:name=>"self"}, :call_site=>{:name=>"get"}, :argument_list=>[{:argument=>{:integer=>"4"}}]}}]}
|
||||
@transform_output = Ast::CallSiteExpression.new(:new, [Ast::CallSiteExpression.new(:get, [Ast::IntegerExpression.new(4)] ,Ast::NameExpression.new("self"))] ,Ast::VariableExpression.new("class"))
|
||||
@parser = @parser.call_site
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user