rubyx/test/parser/test_conditional.rb

31 lines
801 B
Ruby
Raw Normal View History

require_relative "helper"
class TestConditional < MiniTest::Test
# include the magic (setup and parse -> test method translation), see there
include ParserHelper
2014-05-12 12:57:24 +02:00
def test_conditional_brackets
check("(0)")
end
def test_conditional_no_brackets
check("0")
end
2014-05-12 12:57:24 +02:00
def check cond
input = <<HERE
42
else
667
end
HERE
2014-05-12 12:57:24 +02:00
@string_input = "if #{cond} " + input.chop!
@parse_output = {:if=>"if", :conditional=>{:integer=>"0"},
:if_true=>{:expressions=>[{:integer=>"42"}], :else=>"else"},
:if_false=>{:expressions=>[{:integer=>"667"}], :end=>"end"}}
2014-05-24 09:18:54 +02:00
@transform_output = Ast::IfExpression.new( Ast::IntegerExpression.new(0),
2014-05-05 08:51:16 +02:00
[Ast::IntegerExpression.new(42)], [Ast::IntegerExpression.new(667)])
@parser = @parser.conditional
end
end