2014-04-24 14:53:48 +02:00
|
|
|
require_relative 'helper'
|
2014-04-24 14:43:20 +02:00
|
|
|
|
2014-04-24 20:03:11 +02:00
|
|
|
class TransformTest < MiniTest::Test
|
|
|
|
|
|
|
|
def setup
|
2014-04-27 14:44:34 +02:00
|
|
|
@transform = Parser::Transform.new
|
2014-04-24 14:43:20 +02:00
|
|
|
end
|
|
|
|
|
2014-04-28 21:07:35 +02:00
|
|
|
def check
|
2014-04-24 20:03:11 +02:00
|
|
|
is = @transform.apply @input
|
2014-04-28 15:07:34 +02:00
|
|
|
assert_equal @expected , is
|
2014-04-24 20:03:11 +02:00
|
|
|
end
|
|
|
|
def test_number
|
2014-04-27 17:13:34 +02:00
|
|
|
@input = {:integer => '42'}
|
2014-04-28 20:21:12 +02:00
|
|
|
@expected = Parser::IntegerExpression.new(42)
|
2014-04-28 21:07:35 +02:00
|
|
|
check
|
2014-04-24 20:03:11 +02:00
|
|
|
assert_equal 42 , @expected.value
|
2014-04-24 14:43:20 +02:00
|
|
|
end
|
|
|
|
|
2014-04-24 20:03:11 +02:00
|
|
|
def test_name
|
|
|
|
@input = {:name => 'foo'}
|
2014-04-28 20:21:12 +02:00
|
|
|
@expected = Parser::NameExpression.new('foo')
|
2014-04-28 21:07:35 +02:00
|
|
|
check
|
2014-04-24 14:43:20 +02:00
|
|
|
end
|
|
|
|
|
2014-04-24 20:03:11 +02:00
|
|
|
def test_argument_list
|
2014-04-27 20:12:42 +02:00
|
|
|
@input = {:argument_list => [{:argument => {:integer => '42'}},
|
|
|
|
{:argument => {:name => 'foo'}}]}
|
2014-04-28 20:21:12 +02:00
|
|
|
@expected = [Parser::IntegerExpression.new(42),
|
|
|
|
Parser::NameExpression.new('foo')]
|
2014-04-28 21:07:35 +02:00
|
|
|
check
|
2014-04-24 14:43:20 +02:00
|
|
|
end
|
|
|
|
|
2014-04-24 20:03:11 +02:00
|
|
|
def test_single_argument
|
2014-04-27 20:12:42 +02:00
|
|
|
@input = {:function_call => {:name => 'foo'},
|
2014-04-27 20:41:38 +02:00
|
|
|
:argument_list => {:argument => {:integer => '42'} } }
|
2014-04-28 20:21:12 +02:00
|
|
|
@expected = Parser::FuncallExpression.new 'foo', [Parser::IntegerExpression.new(42)]
|
2014-04-24 14:43:20 +02:00
|
|
|
|
2014-04-28 21:07:35 +02:00
|
|
|
check
|
2014-04-24 14:43:20 +02:00
|
|
|
end
|
|
|
|
|
2014-04-24 20:03:11 +02:00
|
|
|
def test_multi_argument
|
2014-04-27 20:12:42 +02:00
|
|
|
@input = {:function_call => {:name => 'baz'},
|
|
|
|
:argument_list => [{:argument => {:integer => '42'}},
|
|
|
|
{:argument => {:name => 'foo'}}]}
|
2014-04-28 20:21:12 +02:00
|
|
|
@expected = Parser::FuncallExpression.new 'baz', [Parser::IntegerExpression.new(42),
|
|
|
|
Parser::NameExpression.new('foo')]
|
2014-04-24 14:43:20 +02:00
|
|
|
|
2014-04-28 21:07:35 +02:00
|
|
|
check
|
2014-04-24 14:43:20 +02:00
|
|
|
end
|
|
|
|
|
2014-04-24 20:03:11 +02:00
|
|
|
def test_conditional
|
2014-04-28 15:07:34 +02:00
|
|
|
@input = { :conditional => { :integer => "0"},
|
|
|
|
:if_true => { :expressions => [ { :integer => "42" } ] } ,
|
|
|
|
:if_false => { :expressions => [ { :integer => "667" } ] } }
|
2014-04-28 20:21:12 +02:00
|
|
|
@expected = Parser::ConditionalExpression.new( Parser::IntegerExpression.new(0),
|
|
|
|
[Parser::IntegerExpression.new(42)],
|
|
|
|
[Parser::IntegerExpression.new(667)])
|
2014-04-28 21:07:35 +02:00
|
|
|
check
|
2014-04-24 14:43:20 +02:00
|
|
|
end
|
|
|
|
|
2014-04-27 20:41:38 +02:00
|
|
|
def test_parmeter
|
|
|
|
@input = {:parmeter => { :name => "foo"}}
|
2014-04-28 20:21:12 +02:00
|
|
|
@expected = Parser::NameExpression.new('foo')
|
2014-04-28 21:07:35 +02:00
|
|
|
check
|
2014-04-27 20:12:42 +02:00
|
|
|
end
|
2014-04-27 20:41:38 +02:00
|
|
|
def test_parmeter_list
|
|
|
|
@input = {:parmeter_list => [{:parmeter => { :name => "foo"}}]}
|
2014-04-28 20:21:12 +02:00
|
|
|
@expected = [Parser::NameExpression.new('foo')]
|
2014-04-28 21:07:35 +02:00
|
|
|
check
|
2014-04-27 20:12:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_function_definition
|
2014-04-28 15:07:34 +02:00
|
|
|
@input = {:function_definition => {:name => 'foo'},
|
|
|
|
:parmeter_list => {:parmeter => {:name => 'x'}},
|
|
|
|
:expressions => [{:integer => '5'}]}
|
2014-04-28 20:21:12 +02:00
|
|
|
@expected = Parser::FunctionExpression.new('foo',
|
|
|
|
[Parser::NameExpression.new('x')],
|
|
|
|
[Parser::IntegerExpression.new(5)])
|
2014-04-28 21:07:35 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_function_assignment
|
|
|
|
@input = { :function_definition => { :name => "foo" } ,
|
|
|
|
:parmeter_list => { :parmeter => { :name => "x" } },
|
|
|
|
:expressions => [ { :asignee => { :name => "abba" }, :asigned => { :integer => "5" } } ]
|
|
|
|
}
|
|
|
|
@expected = Parser::FunctionExpression.new( "foo", [Parser::NameExpression.new("x")],
|
|
|
|
[Parser::AssignmentExpression.new( "abba", Parser::IntegerExpression.new(5) ) ])
|
|
|
|
check
|
2014-04-28 20:21:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_assignment
|
|
|
|
@input = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }
|
|
|
|
@expected = Parser::AssignmentExpression.new("a", Parser::IntegerExpression.new(5) )
|
2014-04-28 21:07:35 +02:00
|
|
|
check
|
2014-04-24 14:43:20 +02:00
|
|
|
end
|
|
|
|
end
|