require_relative 'helper' class ParserTest < MiniTest::Test def setup @parser = Parser::Composed.new end def check is = @parser.parse(@@input) assert is assert_equal @expected , is end def test_number @input = '42 ' @expected = {:number => '42'} @parser = @parser.number end def test_name @input = 'foo ' @expected = {:name => 'foo'} @parser = @parser.name end def test_argument_list @input = '(42, foo)' @expected = {:args => [{:arg => {:number => '42'}}, {:arg => {:name => 'foo'}}]} @parser = @parser.args end def test_function_call @input = 'baz(42, foo)' @expected = {:funcall => {:name => 'baz' }, :args => [{:arg => {:number => '42'}}, {:arg => {:name => 'foo'}}]} @parser = @parser.funcall end def test_conditional @input = < {:number => '0'}, :if_true => {:body => {:number => '42'}}, :if_false => {:body => {:number => '667'}}} @parser = @parser.cond end def test_function_definition @input = < {:name => 'foo'}, :params => {:param => {:name => 'x'}}, :body => {:number => '5'}} @parser = @parser.func end end