2014-04-24 16:38:06 +02:00
|
|
|
require_relative "helper"
|
2014-04-24 14:43:20 +02:00
|
|
|
|
|
|
|
|
2014-04-24 18:45:22 +02: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 16:17:17 +02:00
|
|
|
|
2014-04-24 18:45:22 +02:00
|
|
|
class NodesCase < MiniTest::Test
|
2014-04-24 16:38:06 +02:00
|
|
|
|
2014-04-24 18:45:22 +02:00
|
|
|
def setup
|
|
|
|
@parser = Vm::Parser.new
|
|
|
|
@transform = Vm::Transform.new
|
2014-04-24 16:17:17 +02:00
|
|
|
end
|
2014-04-24 18:45:22 +02:00
|
|
|
|
|
|
|
def parse string
|
|
|
|
syntax = @parser.parse(string)
|
|
|
|
tree = @transform.apply(syntax)
|
|
|
|
tree
|
2014-04-24 16:17:17 +02:00
|
|
|
end
|
2014-04-24 18:45:22 +02:00
|
|
|
|
|
|
|
def test_number
|
|
|
|
tree = parse "42"
|
|
|
|
assert tree.is_a? Vm::NumberExpression
|
|
|
|
assert_equal 42 , tree.value
|
2014-04-24 16:17:17 +02:00
|
|
|
end
|
2014-04-24 18:45:22 +02:00
|
|
|
def test_args
|
|
|
|
tree = parse "( 42 )"
|
|
|
|
assert tree.is_a? Hash
|
|
|
|
assert tree[:args].is_a? Vm::NumberExpression
|
|
|
|
assert_equal 42 , tree[:args].value
|
2014-04-24 16:17:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-24 14:43:20 +02:00
|
|
|
|