2014-04-24 17:38:06 +03:00
|
|
|
require_relative "helper"
|
2014-04-24 15:43:20 +03:00
|
|
|
|
|
|
|
|
2014-04-24 19:45:22 +03:00
|
|
|
#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
|
2014-04-24 17:17:17 +03:00
|
|
|
|
2014-04-27 15:56:22 +03:00
|
|
|
class TestNodes < MiniTest::Test
|
2014-04-24 17:38:06 +03:00
|
|
|
|
2014-04-24 19:45:22 +03:00
|
|
|
def setup
|
2014-04-27 16:30:32 +03:00
|
|
|
@parser = Parser::Composed.new
|
2014-04-27 15:44:34 +03:00
|
|
|
@transform = Parser::Transform.new
|
2014-04-24 17:17:17 +03:00
|
|
|
end
|
2014-04-24 19:45:22 +03:00
|
|
|
|
|
|
|
def parse string
|
|
|
|
syntax = @parser.parse(string)
|
|
|
|
tree = @transform.apply(syntax)
|
|
|
|
tree
|
2014-04-24 17:17:17 +03:00
|
|
|
end
|
2014-04-24 19:45:22 +03:00
|
|
|
|
|
|
|
def test_number
|
|
|
|
tree = parse "42"
|
2014-04-27 16:09:22 +03:00
|
|
|
assert_kind_of Vm::NumberExpression , tree
|
2014-04-24 19:45:22 +03:00
|
|
|
assert_equal 42 , tree.value
|
2014-04-24 17:17:17 +03:00
|
|
|
end
|
2014-04-24 19:45:22 +03:00
|
|
|
def test_args
|
|
|
|
tree = parse "( 42 )"
|
2014-04-27 16:09:22 +03:00
|
|
|
assert_kind_of Hash , tree
|
|
|
|
assert_kind_of Vm::NumberExpression , tree[:args]
|
2014-04-24 19:45:22 +03:00
|
|
|
assert_equal 42 , tree[:args].value
|
2014-04-24 17:17:17 +03:00
|
|
|
end
|
2014-04-25 11:56:53 +03:00
|
|
|
def test_arg_list
|
|
|
|
@parser = @parser.args
|
|
|
|
tree = parse "(42, foo)"
|
2014-04-27 16:09:22 +03:00
|
|
|
assert_instance_of Array , tree
|
2014-04-25 11:56:53 +03:00
|
|
|
assert_equal 42 , tree.first.value
|
|
|
|
assert_equal "foo" , tree.last.name
|
|
|
|
end
|
2014-04-24 17:17:17 +03:00
|
|
|
end
|
|
|
|
|
2014-04-24 15:43:20 +03:00
|
|
|
|