move conditional and expression test to new model
This commit is contained in:
parent
76055575a1
commit
afce197797
24
test/parser/test_conditional.rb
Normal file
24
test/parser/test_conditional.rb
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
class TestBasic < MiniTest::Test
|
||||||
|
# include the magic (setup and parse -> test method translation), see there
|
||||||
|
include ParserHelper
|
||||||
|
|
||||||
|
def test_conditional
|
||||||
|
@string_input = <<HERE
|
||||||
|
if (0)
|
||||||
|
42
|
||||||
|
else
|
||||||
|
667
|
||||||
|
end
|
||||||
|
HERE
|
||||||
|
@parse_output = { :conditional => { :integer => "0"},
|
||||||
|
:if_true => { :expressions => [ { :integer => "42" } ] } ,
|
||||||
|
:if_false => { :expressions => [ { :integer => "667" } ] } }
|
||||||
|
@transform_output = Parser::ConditionalExpression.new( Parser::IntegerExpression.new(0),
|
||||||
|
[Parser::IntegerExpression.new(42)], [Parser::IntegerExpression.new(667)])
|
||||||
|
|
||||||
|
@parser = @parser.conditional
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
38
test/parser/test_expressions.rb
Normal file
38
test/parser/test_expressions.rb
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
class TestBasic < MiniTest::Test
|
||||||
|
# include the magic (setup and parse -> test method translation), see there
|
||||||
|
include ParserHelper
|
||||||
|
|
||||||
|
def test_expression_else
|
||||||
|
@string_input = <<HERE
|
||||||
|
4
|
||||||
|
5
|
||||||
|
else
|
||||||
|
HERE
|
||||||
|
@parse_output = {:expressions=>[{:integer=>"4"}, {:integer=>"5"}]}
|
||||||
|
@transform_output = {:expressions=>[ Parser::IntegerExpression.new(4), Parser::IntegerExpression.new(5)]}
|
||||||
|
@parser = @parser.expressions_else
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_expression_end
|
||||||
|
@string_input = <<HERE
|
||||||
|
5
|
||||||
|
name
|
||||||
|
call(4,6)
|
||||||
|
end
|
||||||
|
HERE
|
||||||
|
@parse_output = {:expressions => [ { :integer => "5" },
|
||||||
|
{ :name => "name" },
|
||||||
|
{ :function_call => { :name => "call" } ,
|
||||||
|
:argument_list => [ {:argument => { :integer => "4" } } ,
|
||||||
|
{:argument => { :integer => "6" } } ] } ]}
|
||||||
|
args = [ Parser::IntegerExpression.new(4) , Parser::IntegerExpression.new(6) ]
|
||||||
|
@transform_output = {:expressions=>[ Parser::IntegerExpression.new(5),
|
||||||
|
Parser::NameExpression.new("name") ,
|
||||||
|
Parser::FuncallExpression.new("call", args ) ] }
|
||||||
|
|
||||||
|
@parser = @parser.expressions_end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -18,46 +18,6 @@ class TestAst < MiniTest::Test
|
|||||||
assert_equal @transform_output , tree
|
assert_equal @transform_output , tree
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_expression_else
|
|
||||||
@string_input = <<HERE
|
|
||||||
4
|
|
||||||
5
|
|
||||||
else
|
|
||||||
HERE
|
|
||||||
@transform_output = {:expressions=>[ Parser::IntegerExpression.new(4), Parser::IntegerExpression.new(5)]}
|
|
||||||
|
|
||||||
@parser = @parser.expressions_else
|
|
||||||
check
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_expression_end
|
|
||||||
@string_input = <<HERE
|
|
||||||
5
|
|
||||||
name
|
|
||||||
call(4,6)
|
|
||||||
end
|
|
||||||
HERE
|
|
||||||
@transform_output = {:expressions=> [Parser::IntegerExpression.new(5), Parser::NameExpression.new("name"),
|
|
||||||
Parser::FuncallExpression.new("call", [Parser::IntegerExpression.new(4), Parser::IntegerExpression.new(6) ]) ] }
|
|
||||||
@parser = @parser.expressions_end
|
|
||||||
check
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_conditional
|
|
||||||
@string_input = <<HERE
|
|
||||||
if (0)
|
|
||||||
42
|
|
||||||
else
|
|
||||||
667
|
|
||||||
end
|
|
||||||
HERE
|
|
||||||
@transform_output = Parser::ConditionalExpression.new( Parser::IntegerExpression.new(0),
|
|
||||||
[Parser::IntegerExpression.new(42)],
|
|
||||||
[Parser::IntegerExpression.new(667)])
|
|
||||||
@parser = @parser.conditional
|
|
||||||
check
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_function_definition
|
def test_function_definition
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
def foo(x)
|
def foo(x)
|
||||||
|
@ -32,49 +32,6 @@ class ParserTest < MiniTest::Test
|
|||||||
assert_equal @parse_output , is
|
assert_equal @parse_output , is
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_expression_else
|
|
||||||
@string_input = <<HERE
|
|
||||||
4
|
|
||||||
5
|
|
||||||
else
|
|
||||||
HERE
|
|
||||||
@parse_output = {:expressions=>[{:integer=>"4"}, {:integer=>"5"}]}
|
|
||||||
|
|
||||||
@parser = @parser.expressions_else
|
|
||||||
check
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_expression_end
|
|
||||||
@string_input = <<HERE
|
|
||||||
5
|
|
||||||
name
|
|
||||||
call(4,6)
|
|
||||||
end
|
|
||||||
HERE
|
|
||||||
@parse_output = {:expressions => [ { :integer => "5" },
|
|
||||||
{ :name => "name" },
|
|
||||||
{ :function_call => { :name => "call" } ,
|
|
||||||
:argument_list => [ {:argument => { :integer => "4" } } ,
|
|
||||||
{:argument => { :integer => "6" } } ] } ]}
|
|
||||||
@parser = @parser.expressions_end
|
|
||||||
check
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_conditional
|
|
||||||
@string_input = <<HERE
|
|
||||||
if (0)
|
|
||||||
42
|
|
||||||
else
|
|
||||||
667
|
|
||||||
end
|
|
||||||
HERE
|
|
||||||
@parse_output = { :conditional => { :integer => "0"},
|
|
||||||
:if_true => { :expressions => [ { :integer => "42" } ] } ,
|
|
||||||
:if_false => { :expressions => [ { :integer => "667" } ] } }
|
|
||||||
@parser = @parser.conditional
|
|
||||||
check
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_function_definition
|
def test_function_definition
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
def foo(x)
|
def foo(x)
|
||||||
|
@ -14,16 +14,6 @@ class TransformTest < MiniTest::Test
|
|||||||
assert_equal @transform_output , is
|
assert_equal @transform_output , is
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_conditional
|
|
||||||
@input = { :conditional => { :integer => "0"},
|
|
||||||
:if_true => { :expressions => [ { :integer => "42" } ] } ,
|
|
||||||
:if_false => { :expressions => [ { :integer => "667" } ] } }
|
|
||||||
@transform_output = Parser::ConditionalExpression.new( Parser::IntegerExpression.new(0),
|
|
||||||
[Parser::IntegerExpression.new(42)],
|
|
||||||
[Parser::IntegerExpression.new(667)])
|
|
||||||
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