More assignment test
This commit is contained in:
parent
129f9f5c57
commit
aaed2ed5a1
@ -16,7 +16,7 @@ class TestNodes < MiniTest::Test
|
|||||||
def check
|
def check
|
||||||
syntax = @parser.parse(@input)
|
syntax = @parser.parse(@input)
|
||||||
tree = @transform.apply(syntax)
|
tree = @transform.apply(syntax)
|
||||||
assert tree
|
# puts tree.inspect
|
||||||
assert_equal @expected , tree
|
assert_equal @expected , tree
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -110,4 +110,14 @@ HERE
|
|||||||
@parser = @parser.function_definition
|
@parser = @parser.function_definition
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
def test_function_assignment
|
||||||
|
@input = <<HERE
|
||||||
|
def foo(x)
|
||||||
|
abba = 5
|
||||||
end
|
end
|
||||||
|
HERE
|
||||||
|
@expected = Parser::FunctionExpression.new( "foo", [Parser::NameExpression.new("x")],
|
||||||
|
[Parser::AssignmentExpression.new( "abba", Parser::IntegerExpression.new(5) ) ])
|
||||||
|
check
|
||||||
|
end
|
||||||
|
end
|
@ -106,6 +106,20 @@ HERE
|
|||||||
check
|
check
|
||||||
end
|
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
|
def test_assignment
|
||||||
@input = "a = 5"
|
@input = "a = 5"
|
||||||
@expected = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }
|
@expected = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }
|
||||||
|
@ -6,21 +6,21 @@ class TransformTest < MiniTest::Test
|
|||||||
@transform = Parser::Transform.new
|
@transform = Parser::Transform.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_equals
|
def check
|
||||||
is = @transform.apply @input
|
is = @transform.apply @input
|
||||||
assert_equal @expected , is
|
assert_equal @expected , is
|
||||||
end
|
end
|
||||||
def test_number
|
def test_number
|
||||||
@input = {:integer => '42'}
|
@input = {:integer => '42'}
|
||||||
@expected = Parser::IntegerExpression.new(42)
|
@expected = Parser::IntegerExpression.new(42)
|
||||||
check_equals
|
check
|
||||||
assert_equal 42 , @expected.value
|
assert_equal 42 , @expected.value
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_name
|
def test_name
|
||||||
@input = {:name => 'foo'}
|
@input = {:name => 'foo'}
|
||||||
@expected = Parser::NameExpression.new('foo')
|
@expected = Parser::NameExpression.new('foo')
|
||||||
check_equals
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_argument_list
|
def test_argument_list
|
||||||
@ -28,7 +28,7 @@ class TransformTest < MiniTest::Test
|
|||||||
{:argument => {:name => 'foo'}}]}
|
{:argument => {:name => 'foo'}}]}
|
||||||
@expected = [Parser::IntegerExpression.new(42),
|
@expected = [Parser::IntegerExpression.new(42),
|
||||||
Parser::NameExpression.new('foo')]
|
Parser::NameExpression.new('foo')]
|
||||||
check_equals
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_single_argument
|
def test_single_argument
|
||||||
@ -36,7 +36,7 @@ class TransformTest < MiniTest::Test
|
|||||||
:argument_list => {:argument => {:integer => '42'} } }
|
:argument_list => {:argument => {:integer => '42'} } }
|
||||||
@expected = Parser::FuncallExpression.new 'foo', [Parser::IntegerExpression.new(42)]
|
@expected = Parser::FuncallExpression.new 'foo', [Parser::IntegerExpression.new(42)]
|
||||||
|
|
||||||
check_equals
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multi_argument
|
def test_multi_argument
|
||||||
@ -46,7 +46,7 @@ class TransformTest < MiniTest::Test
|
|||||||
@expected = Parser::FuncallExpression.new 'baz', [Parser::IntegerExpression.new(42),
|
@expected = Parser::FuncallExpression.new 'baz', [Parser::IntegerExpression.new(42),
|
||||||
Parser::NameExpression.new('foo')]
|
Parser::NameExpression.new('foo')]
|
||||||
|
|
||||||
check_equals
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_conditional
|
def test_conditional
|
||||||
@ -56,18 +56,18 @@ class TransformTest < MiniTest::Test
|
|||||||
@expected = Parser::ConditionalExpression.new( Parser::IntegerExpression.new(0),
|
@expected = Parser::ConditionalExpression.new( Parser::IntegerExpression.new(0),
|
||||||
[Parser::IntegerExpression.new(42)],
|
[Parser::IntegerExpression.new(42)],
|
||||||
[Parser::IntegerExpression.new(667)])
|
[Parser::IntegerExpression.new(667)])
|
||||||
check_equals
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parmeter
|
def test_parmeter
|
||||||
@input = {:parmeter => { :name => "foo"}}
|
@input = {:parmeter => { :name => "foo"}}
|
||||||
@expected = Parser::NameExpression.new('foo')
|
@expected = Parser::NameExpression.new('foo')
|
||||||
check_equals
|
check
|
||||||
end
|
end
|
||||||
def test_parmeter_list
|
def test_parmeter_list
|
||||||
@input = {:parmeter_list => [{:parmeter => { :name => "foo"}}]}
|
@input = {:parmeter_list => [{:parmeter => { :name => "foo"}}]}
|
||||||
@expected = [Parser::NameExpression.new('foo')]
|
@expected = [Parser::NameExpression.new('foo')]
|
||||||
check_equals
|
check
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_function_definition
|
def test_function_definition
|
||||||
@ -77,12 +77,22 @@ class TransformTest < MiniTest::Test
|
|||||||
@expected = Parser::FunctionExpression.new('foo',
|
@expected = Parser::FunctionExpression.new('foo',
|
||||||
[Parser::NameExpression.new('x')],
|
[Parser::NameExpression.new('x')],
|
||||||
[Parser::IntegerExpression.new(5)])
|
[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
|
end
|
||||||
|
|
||||||
def test_assignment
|
def test_assignment
|
||||||
@input = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }
|
@input = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }
|
||||||
@expected = Parser::AssignmentExpression.new("a", Parser::IntegerExpression.new(5) )
|
@expected = Parser::AssignmentExpression.new("a", Parser::IntegerExpression.new(5) )
|
||||||
check_equals
|
check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user