move argument and parameter tests to new framework
This commit is contained in:
parent
90e2658bc0
commit
1af45334b7
37
test/parser/test_arguments.rb
Normal file
37
test/parser/test_arguments.rb
Normal 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
|
@ -4,21 +4,21 @@ class TestBasic < MiniTest::Test
|
|||||||
# include the magic (setup and parse -> test method translation), see there
|
# include the magic (setup and parse -> test method translation), see there
|
||||||
include ParserHelper
|
include ParserHelper
|
||||||
|
|
||||||
def parse_number
|
def test_number
|
||||||
@string_input = '42 '
|
@string_input = '42 '
|
||||||
@parse_output = {:integer => '42'}
|
@parse_output = {:integer => '42'}
|
||||||
@transform_output = Parser::IntegerExpression.new(42)
|
@transform_output = Parser::IntegerExpression.new(42)
|
||||||
@parser = @parser.integer
|
@parser = @parser.integer
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_name
|
def test_name
|
||||||
@string_input = 'foo '
|
@string_input = 'foo '
|
||||||
@parse_output = {:name => 'foo'}
|
@parse_output = {:name => 'foo'}
|
||||||
@transform_output = Parser::NameExpression.new('foo')
|
@transform_output = Parser::NameExpression.new('foo')
|
||||||
@parser = @parser.name
|
@parser = @parser.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_string
|
def test_string
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
"hello"
|
"hello"
|
||||||
HERE
|
HERE
|
||||||
|
@ -12,29 +12,14 @@ class TestAst < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def check
|
def check
|
||||||
syntax = @parser.parse(@input)
|
syntax = @parser.parse(@string_input)
|
||||||
tree = @transform.apply(syntax)
|
tree = @transform.apply(syntax)
|
||||||
# puts tree.inspect
|
# puts tree.inspect
|
||||||
assert_equal @transform_output , tree
|
assert_equal @transform_output , tree
|
||||||
end
|
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
|
def test_function_call
|
||||||
@input = 'baz(42, foo)'
|
@string_input = 'baz(42, foo)'
|
||||||
@transform_output = Parser::FuncallExpression.new 'baz', [Parser::IntegerExpression.new(42),
|
@transform_output = Parser::FuncallExpression.new 'baz', [Parser::IntegerExpression.new(42),
|
||||||
Parser::NameExpression.new('foo')]
|
Parser::NameExpression.new('foo')]
|
||||||
|
|
||||||
@ -43,7 +28,7 @@ class TestAst < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_expression_else
|
def test_expression_else
|
||||||
@input = <<HERE
|
@string_input = <<HERE
|
||||||
4
|
4
|
||||||
5
|
5
|
||||||
else
|
else
|
||||||
@ -55,7 +40,7 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_expression_end
|
def test_expression_end
|
||||||
@input = <<HERE
|
@string_input = <<HERE
|
||||||
5
|
5
|
||||||
name
|
name
|
||||||
call(4,6)
|
call(4,6)
|
||||||
@ -68,7 +53,7 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_conditional
|
def test_conditional
|
||||||
@input = <<HERE
|
@string_input = <<HERE
|
||||||
if (0)
|
if (0)
|
||||||
42
|
42
|
||||||
else
|
else
|
||||||
@ -83,7 +68,7 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_function_definition
|
def test_function_definition
|
||||||
@input = <<HERE
|
@string_input = <<HERE
|
||||||
def foo(x)
|
def foo(x)
|
||||||
5
|
5
|
||||||
end
|
end
|
||||||
@ -95,7 +80,7 @@ HERE
|
|||||||
check
|
check
|
||||||
end
|
end
|
||||||
def test_function_assignment
|
def test_function_assignment
|
||||||
@input = <<HERE
|
@string_input = <<HERE
|
||||||
def foo(x)
|
def foo(x)
|
||||||
abba = 5
|
abba = 5
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ require_relative 'helper'
|
|||||||
# Ast tests both steps in one. Ie string input to ast classes output
|
# 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
|
# 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
|
# 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
|
# also the output of parser.check can actually be used as the input of transform
|
||||||
|
|
||||||
@ -27,28 +27,13 @@ class ParserTest < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def check
|
def check
|
||||||
is = @parser.parse(@input)
|
is = @parser.parse(@string_input)
|
||||||
#puts is.inspect
|
#puts is.inspect
|
||||||
assert_equal @parse_output , is
|
assert_equal @parse_output , is
|
||||||
end
|
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
|
def test_function_call
|
||||||
@input = 'baz(42, foo)'
|
@string_input = 'baz(42, foo)'
|
||||||
@parse_output = {:function_call => {:name => 'baz' },
|
@parse_output = {:function_call => {:name => 'baz' },
|
||||||
:argument_list => [{:argument => {:integer => '42'}},
|
:argument_list => [{:argument => {:integer => '42'}},
|
||||||
{:argument => {:name => 'foo'}}]}
|
{:argument => {:name => 'foo'}}]}
|
||||||
@ -58,7 +43,7 @@ class ParserTest < MiniTest::Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_function_call_string
|
def test_function_call_string
|
||||||
@input = <<HERE
|
@string_input = <<HERE
|
||||||
puts( "hello")
|
puts( "hello")
|
||||||
HERE
|
HERE
|
||||||
@parse_output = {:function_call => {:name => 'baz' },
|
@parse_output = {:function_call => {:name => 'baz' },
|
||||||
@ -70,7 +55,7 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_expression_else
|
def test_expression_else
|
||||||
@input = <<HERE
|
@string_input = <<HERE
|
||||||
4
|
4
|
||||||
5
|
5
|
||||||
else
|
else
|
||||||
@ -82,7 +67,7 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_expression_end
|
def test_expression_end
|
||||||
@input = <<HERE
|
@string_input = <<HERE
|
||||||
5
|
5
|
||||||
name
|
name
|
||||||
call(4,6)
|
call(4,6)
|
||||||
@ -98,7 +83,7 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_conditional
|
def test_conditional
|
||||||
@input = <<HERE
|
@string_input = <<HERE
|
||||||
if (0)
|
if (0)
|
||||||
42
|
42
|
||||||
else
|
else
|
||||||
@ -113,7 +98,7 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_function_definition
|
def test_function_definition
|
||||||
@input = <<HERE
|
@string_input = <<HERE
|
||||||
def foo(x)
|
def foo(x)
|
||||||
5
|
5
|
||||||
end
|
end
|
||||||
@ -126,7 +111,7 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_function_assignment
|
def test_function_assignment
|
||||||
@input = <<HERE
|
@string_input = <<HERE
|
||||||
def foo(x)
|
def foo(x)
|
||||||
abba = 5
|
abba = 5
|
||||||
end
|
end
|
||||||
@ -140,7 +125,7 @@ HERE
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_assignment
|
def test_assignment
|
||||||
@input = "a = 5"
|
@string_input = "a = 5"
|
||||||
@parse_output = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }
|
@parse_output = { :asignee => { :name=>"a" } , :asigned => { :integer => "5" } }
|
||||||
@parser = @parser.assignment
|
@parser = @parser.assignment
|
||||||
check
|
check
|
||||||
|
@ -14,14 +14,6 @@ class TransformTest < MiniTest::Test
|
|||||||
assert_equal @transform_output , is
|
assert_equal @transform_output , is
|
||||||
end
|
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
|
def test_single_argument
|
||||||
@input = {:function_call => {:name => 'foo'},
|
@input = {:function_call => {:name => 'foo'},
|
||||||
:argument_list => {:argument => {:integer => '42'} } }
|
:argument_list => {:argument => {:integer => '42'} } }
|
||||||
@ -50,17 +42,6 @@ class TransformTest < MiniTest::Test
|
|||||||
check
|
check
|
||||||
end
|
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
|
def test_function_definition
|
||||||
@input = {:function_definition => {:name => 'foo'},
|
@input = {:function_definition => {:name => 'foo'},
|
||||||
:parmeter_list => {:parmeter => {:name => 'x'}},
|
:parmeter_list => {:parmeter => {:name => 'x'}},
|
||||||
|
Loading…
Reference in New Issue
Block a user