rubyx/test/vm/test_to_code.rb

44 lines
1009 B
Ruby
Raw Normal View History

2016-12-10 02:43:44 +01:00
require_relative "helper"
class ToCodeTest < MiniTest::Test
include AST::Sexp
def check clazz
2017-01-14 18:28:44 +01:00
tree = Vm.ast_to_code @statement
assert_equal tree.class , Vm::Tree.const_get( clazz )
2016-12-10 02:43:44 +01:00
end
def test_field_access
2016-12-10 22:07:04 +01:00
@statement = s(:field_access, s(:receiver, s(:name, :m)), s(:field, s(:name, :index)))
2016-12-10 02:43:44 +01:00
check "FieldAccess"
end
def test_simple_while
2016-12-10 22:07:04 +01:00
@statement = s(:while_statement, :false, s(:conditional,s(:int, 1)), s(:statements))
2016-12-10 02:43:44 +01:00
check "WhileStatement"
end
def test_assignment
2016-12-10 22:07:04 +01:00
@statement = s(:assignment, s(:name, :i), s(:int, 0))
2016-12-10 02:43:44 +01:00
check "Assignment"
end
def test_nil
2016-12-10 22:07:04 +01:00
@statement = s(:nil)
2016-12-10 02:43:44 +01:00
check "NilExpression"
end
def test_true
2016-12-10 22:07:04 +01:00
@statement = s(:true)
2016-12-10 02:43:44 +01:00
check "TrueExpression"
end
def test_false
2016-12-10 22:07:04 +01:00
@statement = s(:false)
2016-12-10 02:43:44 +01:00
check "FalseExpression"
end
def test_name
2016-12-10 22:07:04 +01:00
@statement = s(:name, :foo)
2016-12-10 02:43:44 +01:00
check "NameExpression"
end
def test_class_name
2016-12-10 22:07:04 +01:00
@statement =s(:class_name, :FooBar)
2016-12-10 02:43:44 +01:00
check "ClassExpression"
end
end