rubyx/test/vm/test_to_code.rb

52 lines
1.2 KiB
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
2017-01-15 12:01:44 +01:00
def test_l_assignment
@statement = s(:l_assignment, s(:name, :i), s(:int, 0))
check "LocalAssignment"
end
def test_a_assignment
@statement = s(:a_assignment, s(:name, :i), s(:int, 0))
check "ArgAssignment"
end
def test_i_assignment
@statement = s(:i_assignment, s(:name, :i), s(:int, 0))
check "IvarAssignment"
2016-12-10 02:43:44 +01:00
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