From aaed2ed5a1d08ffd8f990ff71a3d3f4a12644ab1 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 28 Apr 2014 22:07:35 +0300 Subject: [PATCH] More assignment test --- test/test_nodes.rb | 12 +++++++++++- test/test_parser.rb | 14 ++++++++++++++ test/test_transform.rb | 32 +++++++++++++++++++++----------- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/test/test_nodes.rb b/test/test_nodes.rb index 3ce62343..f0e86947 100644 --- a/test/test_nodes.rb +++ b/test/test_nodes.rb @@ -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 = < { :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" } } diff --git a/test/test_transform.rb b/test/test_transform.rb index e3739d70..bf5b943e 100644 --- a/test/test_transform.rb +++ b/test/test_transform.rb @@ -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