From 8151ed6b9d929981f21a4b65b71b3d10a918d294 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 29 Apr 2014 16:57:36 +0300 Subject: [PATCH] moe the last (function) tests to new test model --- .../test_function_definition.rb} | 43 +++++++------ test/test_ast.rb | 43 ------------- test/test_parser.rb | 62 ------------------- 3 files changed, 21 insertions(+), 127 deletions(-) rename test/{test_transform.rb => parser/test_function_definition.rb} (50%) delete mode 100644 test/test_ast.rb delete mode 100644 test/test_parser.rb diff --git a/test/test_transform.rb b/test/parser/test_function_definition.rb similarity index 50% rename from test/test_transform.rb rename to test/parser/test_function_definition.rb index 60685337..cbd14743 100644 --- a/test/test_transform.rb +++ b/test/parser/test_function_definition.rb @@ -1,37 +1,36 @@ -require_relative 'helper' +require_relative "helper" -# Please read note in test_parser - -class TransformTest < MiniTest::Test - - def setup - @transform = Parser::Transform.new - end - - def check - is = @transform.apply @input - #puts is.transform - assert_equal @transform_output , is - end +class TestFunctionDefinition < MiniTest::Test + # include the magic (setup and parse -> test method translation), see there + include ParserHelper - def test_function_definition - @input = {:function_definition => {:name => 'foo'}, - :parmeter_list => {:parmeter => {:name => 'x'}}, + def test_simplest_function + @string_input = < {:name => 'foo'}, + :parmeter_list => [{:parmeter => {:name => 'x'}}], :expressions => [{:integer => '5'}]} @transform_output = Parser::FunctionExpression.new('foo', [Parser::NameExpression.new('x')], [Parser::IntegerExpression.new(5)]) - check end def test_function_assignment - @input = { :function_definition => { :name => "foo" } , - :parmeter_list => { :parmeter => { :name => "x" } }, + @string_input = < { :name => "foo" } , + :parmeter_list => [{ :parmeter => { :name => "x" } }], :expressions => [ { :asignee => { :name => "abba" }, :asigned => { :integer => "5" } } ] } @transform_output = Parser::FunctionExpression.new( "foo", [Parser::NameExpression.new("x")], [Parser::AssignmentExpression.new( "abba", Parser::IntegerExpression.new(5) ) ]) - check end -end + +end \ No newline at end of file diff --git a/test/test_ast.rb b/test/test_ast.rb deleted file mode 100644 index a260469e..00000000 --- a/test/test_ast.rb +++ /dev/null @@ -1,43 +0,0 @@ -require_relative "helper" - -# Please read note in test_parser - -require_relative 'helper' - -class TestAst < MiniTest::Test - - def setup - @parser = Parser::Composed.new - @transform = Parser::Transform.new - end - - def check - syntax = @parser.parse(@string_input) - tree = @transform.apply(syntax) - # puts tree.inspect - assert_equal @transform_output , tree - end - - def test_function_definition - @string_input = < {:name => 'foo'}, - :parmeter_list => {:parmeter => {:name => 'x'}}, - :expressions => [{:integer => '5'}]} - @parser = @parser.function_definition - check - end - - def test_function_assignment - @string_input = < { :name => "foo" } , - :parmeter_list => { :parmeter => { :name => "x" } }, - :expressions => [ { :asignee => { :name => "abba" }, :asigned => { :integer => "5" } } ] - } - @parser = @parser.function_definition - check - end - -end