move argument and parameter tests to new framework

This commit is contained in:
Torsten Ruger 2014-04-29 16:22:39 +03:00
parent 90e2658bc0
commit 1af45334b7
5 changed files with 57 additions and 69 deletions

View File

@ -0,0 +1,37 @@
require_relative "helper"
class TestArguments < MiniTest::Test
# include the magic (setup and parse -> test method translation), see there
include ParserHelper
def test_one_argument
@string_input = '(42)'
@parse_output = {:argument_list => [{:argument => {:integer => '42'}}] }
@transform_output = [Parser::IntegerExpression.new(42) ]
@parser = @parser.argument_list
end
def test_argument_list
@string_input = '(42, foo)'
@parse_output = {:argument_list => [{:argument => {:integer => '42'}},
{:argument => {:name => 'foo'}}]}
@transform_output = [Parser::IntegerExpression.new(42), Parser::NameExpression.new('foo')]
@parser = @parser.argument_list
end
def test_parmeter
@string_input = "(foo)"
@parse_output = {:parmeter_list => [{:parmeter => { :name => "foo"}} ]}
@transform_output = [Parser::NameExpression.new('foo')]
@parser = @parser.parmeter_list
end
def test_parmeter_list
@string_input = "( foo , bar)"
@parse_output = {:parmeter_list => [{:parmeter => { :name => "foo"}},
{:parmeter => { :name => "bar"}} ]}
@transform_output = [Parser::NameExpression.new('foo') , Parser::NameExpression.new('bar')]
@parser = @parser.parmeter_list
end
end

View File

@ -4,21 +4,21 @@ class TestBasic < MiniTest::Test
# include the magic (setup and parse -> test method translation), see there
include ParserHelper
def parse_number
def test_number
@string_input = '42 '
@parse_output = {:integer => '42'}
@transform_output = Parser::IntegerExpression.new(42)
@parser = @parser.integer
end
def parse_name
def test_name
@string_input = 'foo '
@parse_output = {:name => 'foo'}
@transform_output = Parser::NameExpression.new('foo')
@parser = @parser.name
end
def parse_string
def test_string
@string_input = <<HERE
"hello"
HERE

View File

@ -12,29 +12,14 @@ class TestAst < MiniTest::Test
end
def check
syntax = @parser.parse(@input)
syntax = @parser.parse(@string_input)
tree = @transform.apply(syntax)
# puts tree.inspect
assert_equal @transform_output , tree
end
def test_one_argument
@input = '(42)'
@transform_output = { :argument_list => Parser::IntegerExpression.new(42) }
@parser = @parser.argument_list
check
end
def test_argument_list
@input = '(42, foo)'
@transform_output = [Parser::IntegerExpression.new(42),
Parser::NameExpression.new('foo')]
@parser = @parser.argument_list
check
end
def test_function_call
@input = 'baz(42, foo)'
@string_input = 'baz(42, foo)'
@transform_output = Parser::FuncallExpression.new 'baz', [Parser::IntegerExpression.new(42),
Parser::NameExpression.new('foo')]
@ -43,7 +28,7 @@ class TestAst < MiniTest::Test
end
def test_expression_else
@input = <<HERE
@string_input = <<HERE
4
5
else
@ -55,7 +40,7 @@ HERE
end
def test_expression_end
@input = <<HERE
@string_input = <<HERE
5
name
call(4,6)
@ -68,7 +53,7 @@ HERE
end
def test_conditional
@input = <<HERE
@string_input = <<HERE
if (0)
42
else
@ -83,7 +68,7 @@ HERE
end
def test_function_definition
@input = <<HERE
@string_input = <<HERE
def foo(x)
5
end
@ -95,7 +80,7 @@ HERE
check
end
def test_function_assignment
@input = <<HERE
@string_input = <<HERE
def foo(x)
abba = 5
end

View File

@ -12,7 +12,7 @@ require_relative 'helper'
# Ast tests both steps in one. Ie string input to ast classes output
# All threee classes are layed out quite similarly in that they use a check method and
# each test assigns @input and @parse_output which the check methods then checks
# each test assigns @string_input and @parse_output which the check methods then checks
# The check methods have a pust in it (to be left) which is very handy for checking
# also the output of parser.check can actually be used as the input of transform
@ -27,28 +27,13 @@ class ParserTest < MiniTest::Test
end
def check
is = @parser.parse(@input)
is = @parser.parse(@string_input)
#puts is.inspect
assert_equal @parse_output , is
end
def test_one_argument
@input = '(42)'
@parse_output = {:argument_list => {:argument => {:integer => '42'}} }
@parser = @parser.argument_list
check
end
def test_argument_list
@input = '(42, foo)'
@parse_output = {:argument_list => [{:argument => {:integer => '42'}},
{:argument => {:name => 'foo'}}]}
@parser = @parser.argument_list
check
end
def test_function_call
@input = 'baz(42, foo)'
@string_input = 'baz(42, foo)'
@parse_output = {:function_call => {:name => 'baz' },
:argument_list => [{:argument => {:integer => '42'}},
{:argument => {:name => 'foo'}}]}
@ -58,7 +43,7 @@ class ParserTest < MiniTest::Test
end
def test_function_call_string
@input = <<HERE
@string_input = <<HERE
puts( "hello")
HERE
@parse_output = {:function_call => {:name => 'baz' },
@ -70,7 +55,7 @@ HERE
end
def test_expression_else
@input = <<HERE
@string_input = <<HERE
4
5
else
@ -82,7 +67,7 @@ HERE
end
def test_expression_end
@input = <<HERE
@string_input = <<HERE
5
name
call(4,6)
@ -98,7 +83,7 @@ HERE
end
def test_conditional
@input = <<HERE
@string_input = <<HERE
if (0)
42
else
@ -113,7 +98,7 @@ HERE
end
def test_function_definition
@input = <<HERE
@string_input = <<HERE
def foo(x)
5
end
@ -126,7 +111,7 @@ HERE
end
def test_function_assignment
@input = <<HERE
@string_input = <<HERE
def foo(x)
abba = 5
end
@ -140,7 +125,7 @@ HERE
end
def test_assignment
@input = "a = 5"
@string_input = "a = 5"
@parse_output = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }
@parser = @parser.assignment
check

View File

@ -14,14 +14,6 @@ class TransformTest < MiniTest::Test
assert_equal @transform_output , is
end
def test_argument_list
@input = {:argument_list => [{:argument => {:integer => '42'}},
{:argument => {:name => 'foo'}}]}
@transform_output = [Parser::IntegerExpression.new(42),
Parser::NameExpression.new('foo')]
check
end
def test_single_argument
@input = {:function_call => {:name => 'foo'},
:argument_list => {:argument => {:integer => '42'} } }
@ -49,17 +41,6 @@ class TransformTest < MiniTest::Test
[Parser::IntegerExpression.new(667)])
check
end
def test_parmeter
@input = {:parmeter => { :name => "foo"}}
@transform_output = Parser::NameExpression.new('foo')
check
end
def test_parmeter_list
@input = {:parmeter_list => [{:parmeter => { :name => "foo"}}]}
@transform_output = [Parser::NameExpression.new('foo')]
check
end
def test_function_definition
@input = {:function_definition => {:name => 'foo'},