From 76055575a17cae49cdf35d0a2cfeb2dee78ec89c Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 29 Apr 2014 16:36:29 +0300 Subject: [PATCH] moves the function call tests to new model --- test/parser/test_function_call.rb | 32 +++++++++++++++++++++++++++++++ test/test_ast.rb | 9 --------- test/test_parser.rb | 22 --------------------- test/test_transform.rb | 18 ----------------- 4 files changed, 32 insertions(+), 49 deletions(-) create mode 100644 test/parser/test_function_call.rb diff --git a/test/parser/test_function_call.rb b/test/parser/test_function_call.rb new file mode 100644 index 00000000..ddb5efd8 --- /dev/null +++ b/test/parser/test_function_call.rb @@ -0,0 +1,32 @@ +require_relative "helper" + +class TestFunctionCall < MiniTest::Test + # include the magic (setup and parse -> test method translation), see there + include ParserHelper + + def test_single_argument + @string_input = 'foo(42)' + @parse_output = {:function_call => {:name => 'foo'}, + :argument_list => [{:argument => {:integer => '42'} }] } + @transform_output = Parser::FuncallExpression.new 'foo', [Parser::IntegerExpression.new(42)] + end + + def test_function_call_multi + @string_input = 'baz(42, foo)' + @parse_output = {:function_call => {:name => 'baz' }, + :argument_list => [{:argument => {:integer => '42'}}, + {:argument => {:name => 'foo'}}]} + @transform_output = Parser::FuncallExpression.new 'baz', + [Parser::IntegerExpression.new(42), Parser::NameExpression.new("foo") ] + @parser = @parser.function_call + end + + def test_function_call_string + @string_input = 'puts( "hello")' + @parse_output = {:function_call => {:name => 'puts' }, + :argument_list => [{:argument => {:string => 'hello'}}]} + @transform_output = Parser::FuncallExpression.new "puts", [Parser::StringExpression.new("hello")] + @parser = @parser.function_call + end + +end \ No newline at end of file diff --git a/test/test_ast.rb b/test/test_ast.rb index 796e1953..013edb2f 100644 --- a/test/test_ast.rb +++ b/test/test_ast.rb @@ -18,15 +18,6 @@ class TestAst < MiniTest::Test assert_equal @transform_output , tree end - def test_function_call - @string_input = 'baz(42, foo)' - @transform_output = Parser::FuncallExpression.new 'baz', [Parser::IntegerExpression.new(42), - Parser::NameExpression.new('foo')] - - @parser = @parser.function_call - check - end - def test_expression_else @string_input = < {:name => 'baz' }, - :argument_list => [{:argument => {:integer => '42'}}, - {:argument => {:name => 'foo'}}]} - - @parser = @parser.function_call - check - end - - def test_function_call_string - @string_input = < {:name => 'baz' }, - :argument_list => [{:argument => {:integer => '42'}}, - {:argument => {:name => 'foo'}}]} - - @parser = @parser.function_call - check - end - def test_expression_else @string_input = < {:name => 'foo'}, - :argument_list => {:argument => {:integer => '42'} } } - @transform_output = Parser::FuncallExpression.new 'foo', [Parser::IntegerExpression.new(42)] - - check - end - - def test_multi_argument - @input = {:function_call => {:name => 'baz'}, - :argument_list => [{:argument => {:integer => '42'}}, - {:argument => {:name => 'foo'}}]} - @transform_output = Parser::FuncallExpression.new 'baz', [Parser::IntegerExpression.new(42), - Parser::NameExpression.new('foo')] - - check - end - def test_conditional @input = { :conditional => { :integer => "0"}, :if_true => { :expressions => [ { :integer => "42" } ] } ,