2014-04-29 15:36:29 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2014-05-13 20:15:02 +02:00
|
|
|
class TestCallSite < MiniTest::Test
|
2014-04-29 15:36:29 +02:00
|
|
|
# include the magic (setup and parse -> test method translation), see there
|
|
|
|
include ParserHelper
|
|
|
|
|
|
|
|
def test_single_argument
|
|
|
|
@string_input = 'foo(42)'
|
2014-05-13 20:15:02 +02:00
|
|
|
@parse_output = {:call_site => {:name => 'foo'},
|
2014-04-29 15:36:29 +02:00
|
|
|
:argument_list => [{:argument => {:integer => '42'} }] }
|
2014-05-13 20:15:02 +02:00
|
|
|
@transform_output = Ast::CallSiteExpression.new 'foo', [Ast::IntegerExpression.new(42)]
|
|
|
|
@parser = @parser.call_site
|
2014-04-29 15:36:29 +02:00
|
|
|
end
|
|
|
|
|
2014-05-13 20:15:02 +02:00
|
|
|
def test_call_site_multi
|
2014-04-29 15:36:29 +02:00
|
|
|
@string_input = 'baz(42, foo)'
|
2014-05-13 20:15:02 +02:00
|
|
|
@parse_output = {:call_site => {:name => 'baz' },
|
2014-04-29 15:36:29 +02:00
|
|
|
:argument_list => [{:argument => {:integer => '42'}},
|
|
|
|
{:argument => {:name => 'foo'}}]}
|
2014-05-13 20:15:02 +02:00
|
|
|
@transform_output = Ast::CallSiteExpression.new 'baz',
|
2014-05-05 08:51:16 +02:00
|
|
|
[Ast::IntegerExpression.new(42), Ast::NameExpression.new("foo") ]
|
2014-05-13 20:15:02 +02:00
|
|
|
@parser = @parser.call_site
|
2014-04-29 15:36:29 +02:00
|
|
|
end
|
|
|
|
|
2014-05-13 20:15:02 +02:00
|
|
|
def test_call_site_string
|
2014-04-29 15:36:29 +02:00
|
|
|
@string_input = 'puts( "hello")'
|
2014-05-13 20:15:02 +02:00
|
|
|
@parse_output = {:call_site => {:name => 'puts' },
|
2014-05-09 12:51:47 +02:00
|
|
|
:argument_list => [{:argument =>
|
|
|
|
{:string=>[{:char=>"h"}, {:char=>"e"}, {:char=>"l"}, {:char=>"l"}, {:char=>"o"}]}}]}
|
2014-05-13 20:15:02 +02:00
|
|
|
@transform_output = Ast::CallSiteExpression.new "puts", [Ast::StringExpression.new("hello")]
|
|
|
|
@parser = @parser.call_site
|
2014-04-29 15:36:29 +02:00
|
|
|
end
|
|
|
|
|
2014-05-28 14:22:37 +02:00
|
|
|
def test_call_operator
|
|
|
|
@string_input = 'puts( 3 + 5)'
|
|
|
|
@parse_output = {:call_site=>{:name=>"puts"}, :argument_list=>[{:argument=>{:l=>{:integer=>"3"}, :o=>"+ ", :r=>{:integer=>"5"}}}]}
|
|
|
|
@transform_output = Ast::CallSiteExpression.new(:puts, [Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(3),Ast::IntegerExpression.new(5))] )
|
|
|
|
@parser = @parser.call_site
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_call_two_operators
|
|
|
|
@string_input = 'puts(3 + 5 , a - 3)'
|
|
|
|
@parse_output = {:call_site=>{:name=>"puts"}, :argument_list=>[{:argument=>{:l=>{:integer=>"3"}, :o=>"+ ", :r=>{:integer=>"5"}}}, {:argument=>{:l=>{:name=>"a"}, :o=>"- ", :r=>{:integer=>"3"}}}]}
|
|
|
|
@transform_output = Ast::CallSiteExpression.new(:puts, [Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(3),Ast::IntegerExpression.new(5)),Ast::OperatorExpression.new("-", Ast::NameExpression.new("a"),Ast::IntegerExpression.new(3))] )
|
|
|
|
@parser = @parser.call_site
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_call_chaining
|
|
|
|
@string_input = 'puts(putint(3 + 5 ), a - 3)'
|
|
|
|
@parse_output = {:call_site=>{:name=>"puts"}, :argument_list=>[{:argument=>{:call_site=>{:name=>"putint"}, :argument_list=>[{:argument=>{:l=>{:integer=>"3"}, :o=>"+ ", :r=>{:integer=>"5"}}}]}}, {:argument=>{:l=>{:name=>"a"}, :o=>"- ", :r=>{:integer=>"3"}}}]}
|
|
|
|
@transform_output = Ast::CallSiteExpression.new(:puts, [Ast::CallSiteExpression.new(:putint, [Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(3),Ast::IntegerExpression.new(5))] ),Ast::OperatorExpression.new("-", Ast::NameExpression.new("a"),Ast::IntegerExpression.new(3))] )
|
|
|
|
@parser = @parser.call_site
|
|
|
|
end
|
|
|
|
|
2014-04-29 15:36:29 +02:00
|
|
|
end
|