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
|
@ -17,47 +17,7 @@ class TestAst < MiniTest::Test
|
||||
# puts tree.inspect
|
||||
assert_equal @transform_output , tree
|
||||
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
|
||||
@string_input = <<HERE
|
||||
def foo(x)
|
||||
|
@ -32,49 +32,6 @@ class ParserTest < MiniTest::Test
|
||||
assert_equal @parse_output , is
|
||||
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
|
||||
@string_input = <<HERE
|
||||
def foo(x)
|
||||
|
@ -13,16 +13,6 @@ class TransformTest < MiniTest::Test
|
||||
#puts is.transform
|
||||
assert_equal @transform_output , is
|
||||
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
|
||||
@input = {:function_definition => {:name => 'foo'},
|
||||
|
Loading…
Reference in New Issue
Block a user