rubyx/test/parser/test_function_definition.rb

36 lines
1.2 KiB
Ruby
Raw Normal View History

require_relative "helper"
2014-04-24 14:43:20 +02:00
class TestFunctionDefinition < MiniTest::Test
# include the magic (setup and parse -> test method translation), see there
include ParserHelper
def test_simplest_function
@string_input = <<HERE
def foo(x)
5
end
HERE
@parse_output = {:function_definition => {:name => 'foo'},
:parmeter_list => [{:parmeter => {:name => 'x'}}],
:expressions => [{:integer => '5'}]}
@transform_output = Parser::FunctionExpression.new('foo',
[Parser::NameExpression.new('x')],
[Parser::IntegerExpression.new(5)])
2014-04-28 21:07:35 +02:00
end
def test_function_assignment
@string_input = <<HERE
def foo(x)
abba = 5
end
HERE
@parse_output = { :function_definition => { :name => "foo" } ,
:parmeter_list => [{ :parmeter => { :name => "x" } }],
2014-04-28 21:07:35 +02:00
:expressions => [ { :asignee => { :name => "abba" }, :asigned => { :integer => "5" } } ]
}
@transform_output = Parser::FunctionExpression.new( "foo", [Parser::NameExpression.new("x")],
2014-04-28 21:07:35 +02:00
[Parser::AssignmentExpression.new( "abba", Parser::IntegerExpression.new(5) ) ])
end
end