require_relative "helper" # testing that parsing strings that we know to be correct returns the nodes we expect # in a way the combination of test_parser and test_transform require_relative 'helper' class TestNodes < MiniTest::Test def setup @parser = Parser::Composed.new @transform = Parser::Transform.new end def check syntax = @parser.parse(@input) tree = @transform.apply(syntax) assert tree assert_equal @expected , tree end def test_number @input = '42 ' @expected = Parser::IntegerExpression.new(42) @parser = @parser.integer check end def test_name @input = 'foo ' @expected = Parser::NameExpression.new('foo') @parser = @parser.name check end def test_one_argument @input = '(42)' @expected = { :argument_list => Parser::IntegerExpression.new(42) } @parser = @parser.argument_list check end def test_argument_list @input = '(42, foo)' @expected = [Parser::IntegerExpression.new(42), Parser::NameExpression.new('foo')] @parser = @parser.argument_list check end def test_function_call @input = 'baz(42, foo)' @expected = Parser::FuncallExpression.new 'baz', [Parser::IntegerExpression.new(42), Parser::NameExpression.new('foo')] @parser = @parser.function_call check end def test_expression_else @input = <[ Parser::IntegerExpression.new(4), Parser::IntegerExpression.new(5)]} @parser = @parser.expressions_else check end def test_expression_end @input = < [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 @input = <