2014-04-29 15:47:33 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2014-04-29 16:02:38 +02:00
|
|
|
class TestConditional < MiniTest::Test
|
2014-04-29 15:47:33 +02:00
|
|
|
# include the magic (setup and parse -> test method translation), see there
|
|
|
|
include ParserHelper
|
|
|
|
|
|
|
|
def test_conditional
|
|
|
|
@string_input = <<HERE
|
2014-05-08 18:49:15 +02:00
|
|
|
if(0)
|
2014-04-29 15:47:33 +02:00
|
|
|
42
|
|
|
|
else
|
|
|
|
667
|
|
|
|
end
|
|
|
|
HERE
|
2014-05-11 17:38:02 +02:00
|
|
|
@parse_output = {:if=>"if", :conditional=>{:integer=>"0"},
|
|
|
|
:if_true=>{:expressions=>[{:integer=>"42"}], :else=>"else"},
|
|
|
|
:if_false=>{:expressions=>[{:integer=>"667"}], :end=>"end"}}
|
2014-05-05 08:51:16 +02:00
|
|
|
@transform_output = Ast::ConditionalExpression.new( Ast::IntegerExpression.new(0),
|
|
|
|
[Ast::IntegerExpression.new(42)], [Ast::IntegerExpression.new(667)])
|
2014-04-29 15:47:33 +02:00
|
|
|
|
|
|
|
@parser = @parser.conditional
|
|
|
|
end
|
2014-05-10 18:02:51 +02:00
|
|
|
|
|
|
|
def test_while
|
|
|
|
@string_input = <<HERE
|
|
|
|
while 1 do
|
|
|
|
tmp = a
|
2014-05-12 11:14:04 +02:00
|
|
|
puts(b)
|
2014-05-10 18:02:51 +02:00
|
|
|
end
|
|
|
|
HERE
|
|
|
|
|
2014-05-11 17:38:02 +02:00
|
|
|
@parse_output = {:while=>"while",
|
2014-05-12 11:14:04 +02:00
|
|
|
:while_cond=>{:expressions=>[{:integer=>"1"}],
|
|
|
|
:do=>"do"},
|
|
|
|
:body=>{:expressions=>[{:l=>{:name=>"tmp"}, :o=>"= ", :r=>{:name=>"a"}},
|
|
|
|
{:function_call=>{:name=>"puts"}, :argument_list=>[{:argument=>{:name=>"b"}}]}], :end=>"end"}}
|
2014-05-10 18:02:51 +02:00
|
|
|
@transform_output = Ast::WhileExpression.new(
|
2014-05-12 11:14:04 +02:00
|
|
|
[Ast::IntegerExpression.new(1)],
|
|
|
|
[Ast::OperatorExpression.new("=", Ast::NameExpression.new("tmp"),Ast::NameExpression.new("a")),
|
|
|
|
Ast::FuncallExpression.new("puts", [Ast::NameExpression.new("b")] )] )
|
|
|
|
@parser = @parser.while_do
|
2014-05-10 18:02:51 +02:00
|
|
|
end
|
2014-04-29 15:47:33 +02:00
|
|
|
end
|