More assignment test

This commit is contained in:
Torsten Ruger 2014-04-28 22:07:35 +03:00
parent 129f9f5c57
commit aaed2ed5a1
3 changed files with 46 additions and 12 deletions

View File

@ -16,7 +16,7 @@ class TestNodes < MiniTest::Test
def check
syntax = @parser.parse(@input)
tree = @transform.apply(syntax)
assert tree
# puts tree.inspect
assert_equal @expected , tree
end
@ -110,4 +110,14 @@ HERE
@parser = @parser.function_definition
check
end
def test_function_assignment
@input = <<HERE
def foo(x)
abba = 5
end
HERE
@expected = Parser::FunctionExpression.new( "foo", [Parser::NameExpression.new("x")],
[Parser::AssignmentExpression.new( "abba", Parser::IntegerExpression.new(5) ) ])
check
end
end

View File

@ -106,6 +106,20 @@ HERE
check
end
def test_function_assignment
@input = <<HERE
def foo(x)
abba = 5
end
HERE
@expected = { :function_definition => { :name => "foo" } ,
:parmeter_list => { :parmeter => { :name => "x" } },
:expressions => [ { :asignee => { :name => "abba" }, :asigned => { :integer => "5" } } ]
}
@parser = @parser.function_definition
check
end
def test_assignment
@input = "a = 5"
@expected = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }

View File

@ -6,21 +6,21 @@ class TransformTest < MiniTest::Test
@transform = Parser::Transform.new
end
def check_equals
def check
is = @transform.apply @input
assert_equal @expected , is
end
def test_number
@input = {:integer => '42'}
@expected = Parser::IntegerExpression.new(42)
check_equals
check
assert_equal 42 , @expected.value
end
def test_name
@input = {:name => 'foo'}
@expected = Parser::NameExpression.new('foo')
check_equals
check
end
def test_argument_list
@ -28,7 +28,7 @@ class TransformTest < MiniTest::Test
{:argument => {:name => 'foo'}}]}
@expected = [Parser::IntegerExpression.new(42),
Parser::NameExpression.new('foo')]
check_equals
check
end
def test_single_argument
@ -36,7 +36,7 @@ class TransformTest < MiniTest::Test
:argument_list => {:argument => {:integer => '42'} } }
@expected = Parser::FuncallExpression.new 'foo', [Parser::IntegerExpression.new(42)]
check_equals
check
end
def test_multi_argument
@ -46,7 +46,7 @@ class TransformTest < MiniTest::Test
@expected = Parser::FuncallExpression.new 'baz', [Parser::IntegerExpression.new(42),
Parser::NameExpression.new('foo')]
check_equals
check
end
def test_conditional
@ -56,18 +56,18 @@ class TransformTest < MiniTest::Test
@expected = Parser::ConditionalExpression.new( Parser::IntegerExpression.new(0),
[Parser::IntegerExpression.new(42)],
[Parser::IntegerExpression.new(667)])
check_equals
check
end
def test_parmeter
@input = {:parmeter => { :name => "foo"}}
@expected = Parser::NameExpression.new('foo')
check_equals
check
end
def test_parmeter_list
@input = {:parmeter_list => [{:parmeter => { :name => "foo"}}]}
@expected = [Parser::NameExpression.new('foo')]
check_equals
check
end
def test_function_definition
@ -77,12 +77,22 @@ class TransformTest < MiniTest::Test
@expected = Parser::FunctionExpression.new('foo',
[Parser::NameExpression.new('x')],
[Parser::IntegerExpression.new(5)])
check_equals
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
end
def test_assignment
@input = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }
@expected = Parser::AssignmentExpression.new("a", Parser::IntegerExpression.new(5) )
check_equals
check
end
end