rubyx/test/vm/test_to_code.rb

56 lines
1.3 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
@statement = s(:field_access, s(:receiver, s(:ivar, :m)), s(:field, s(:ivar, :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(:local, :i), s(:int, 0))
2017-01-15 12:01:44 +01:00
check "LocalAssignment"
end
def test_a_assignment
@statement = s(:a_assignment, s(:arg, :i), s(:int, 0))
2017-01-15 12:01:44 +01:00
check "ArgAssignment"
end
def test_i_assignment
@statement = s(:i_assignment, s(:ivar, :i), s(:int, 0))
2017-01-15 12:01:44 +01:00
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_known
@statement = s(:known, :self)
check "KnownName"
end
def test_ivar
@statement = s(:ivar, :you)
check "InstanceName"
2016-12-10 02:43:44 +01:00
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