create rubyx dir and move previous vool_compiler there
This commit is contained in:
@ -1 +0,0 @@
|
||||
require_relative "../helper"
|
@ -1,19 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestArray < MiniTest::Test
|
||||
|
||||
def test_empty
|
||||
lst = RubyCompiler.compile( "[]")
|
||||
assert_equal ArrayStatement , lst.class
|
||||
end
|
||||
def test_one
|
||||
lst = RubyCompiler.compile( "[1]")
|
||||
assert_equal ArrayStatement , lst.class
|
||||
end
|
||||
def test_two
|
||||
lst = RubyCompiler.compile( "[1,2]")
|
||||
assert_equal ArrayStatement , lst.class
|
||||
end
|
||||
end
|
||||
end
|
@ -1,77 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestBasicValues < MiniTest::Test
|
||||
|
||||
def test_self
|
||||
lst = RubyCompiler.compile( "self")
|
||||
assert_equal SelfExpression , lst.class
|
||||
end
|
||||
def test_nil
|
||||
lst = RubyCompiler.compile( "nil")
|
||||
assert_equal NilConstant , lst.class
|
||||
end
|
||||
def test_false
|
||||
lst = RubyCompiler.compile( "false")
|
||||
assert_equal FalseConstant , lst.class
|
||||
end
|
||||
def test_true
|
||||
lst = RubyCompiler.compile( "true")
|
||||
assert_equal TrueConstant , lst.class
|
||||
end
|
||||
def test_integer
|
||||
lst = RubyCompiler.compile( "123")
|
||||
assert_equal IntegerConstant , lst.class
|
||||
end
|
||||
def test_string
|
||||
lst = RubyCompiler.compile( "'string'")
|
||||
assert_equal StringConstant , lst.class , lst.inspect
|
||||
end
|
||||
def test_sym
|
||||
lst = RubyCompiler.compile( ":symbol")
|
||||
assert_equal SymbolConstant , lst.class , lst.inspect
|
||||
end
|
||||
def test_dstr
|
||||
assert_raises RuntimeError do
|
||||
RubyCompiler.compile( '"dstr#{self}"')
|
||||
end
|
||||
end
|
||||
|
||||
def test_scope
|
||||
lst = RubyCompiler.compile( "begin ; 1 ; end")
|
||||
assert_equal ScopeStatement , lst.class , lst.inspect
|
||||
end
|
||||
def test_scope_contents
|
||||
lst = RubyCompiler.compile( "begin ; 1 ; end")
|
||||
assert_equal 1 , lst.statements.first.value
|
||||
end
|
||||
end
|
||||
class TestBasicTypes < MiniTest::Test
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
end
|
||||
def compile( input )
|
||||
lst = RubyCompiler.compile( input )
|
||||
lst.ct_type
|
||||
end
|
||||
def test_integer
|
||||
assert_equal "Integer_Type" , compile( "123").name
|
||||
end
|
||||
def test_string
|
||||
assert_equal "Word_Type" , compile( "'string'").name
|
||||
end
|
||||
def test_sym
|
||||
assert_equal "Word_Type" , compile( ":symbol").name
|
||||
end
|
||||
# classes fot these are not implemented in parfait yet
|
||||
def pest_nil
|
||||
assert_equal "Nil_Type" , compile( "nil").name
|
||||
end
|
||||
def pest_false
|
||||
assert_equal "False_Type" , compile( "false").name
|
||||
end
|
||||
def pest_true
|
||||
assert_equal "True_Type" , compile( "true").name
|
||||
end
|
||||
end
|
||||
end
|
@ -1,29 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestBlockStatement < MiniTest::Test
|
||||
|
||||
def setup()
|
||||
input = "plus_one{|arg1| arg1 + 1 } "
|
||||
@lst = RubyCompiler.compile( input )
|
||||
end
|
||||
def test_method
|
||||
assert_equal SendStatement , @lst.class
|
||||
end
|
||||
def test_block
|
||||
assert_equal BlockStatement , @lst.block.class
|
||||
end
|
||||
|
||||
def test_method_name
|
||||
assert_equal :plus_one , @lst.name
|
||||
end
|
||||
|
||||
def test_block_args
|
||||
assert_equal [:arg1] , @lst.block.args
|
||||
end
|
||||
def test_block_body
|
||||
assert_equal SendStatement , @lst.block.body.class
|
||||
assert_equal 1 , @lst.block.body.arguments.length
|
||||
end
|
||||
end
|
||||
end
|
@ -1,42 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestEmptyClassStatement < MiniTest::Test
|
||||
|
||||
def setup
|
||||
input = "class Tryout < Base;end"
|
||||
@lst = RubyCompiler.compile( input )
|
||||
end
|
||||
|
||||
def test_compile_class
|
||||
assert_equal ClassStatement , @lst.class
|
||||
end
|
||||
|
||||
def test_compile_class_name
|
||||
assert_equal :Tryout , @lst.name
|
||||
end
|
||||
|
||||
def test_compile_class_super
|
||||
assert_equal :Base , @lst.super_class_name
|
||||
end
|
||||
|
||||
def test_compile_class_body
|
||||
assert_nil @lst.body
|
||||
end
|
||||
|
||||
end
|
||||
class TestBasicClassStatement < MiniTest::Test
|
||||
include CompilerHelper
|
||||
|
||||
def test_compile_one_method
|
||||
lst = RubyCompiler.compile( in_Test("@ivar = 4") )
|
||||
assert_equal IvarAssignment , lst.body.class
|
||||
end
|
||||
def test_compile_two_methods
|
||||
lst = RubyCompiler.compile( in_Test("false; true;") )
|
||||
assert_equal ScopeStatement , lst.body.class
|
||||
assert_equal TrueConstant , lst.body.statements[1].class
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,35 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class HashArray < MiniTest::Test
|
||||
|
||||
def test_empty
|
||||
lst = RubyCompiler.compile( "{}")
|
||||
assert_equal HashStatement , lst.class
|
||||
end
|
||||
def test_empty_length
|
||||
lst = RubyCompiler.compile( "{}")
|
||||
assert_equal 0 , lst.length
|
||||
end
|
||||
def test_one
|
||||
lst = RubyCompiler.compile( "{ 1 => 2}")
|
||||
assert_equal HashStatement , lst.class
|
||||
end
|
||||
def test_one_length
|
||||
lst = RubyCompiler.compile( "{ 1 => 2}")
|
||||
assert_equal 1 , lst.length
|
||||
end
|
||||
def test_one_pair
|
||||
lst = RubyCompiler.compile( "{ 1 => 2}")
|
||||
assert_equal 1 , lst.hash.keys.first.value
|
||||
end
|
||||
def test_two_length
|
||||
lst = RubyCompiler.compile( "{ sym: :works , 'string_too' => 2}")
|
||||
assert_equal 2 , lst.length
|
||||
end
|
||||
def test_two_key_one
|
||||
lst = RubyCompiler.compile( "{ sym: :works , 'string_too' => 2}")
|
||||
assert_equal :sym , lst.hash.keys.first.value
|
||||
end
|
||||
end
|
||||
end
|
@ -1,91 +0,0 @@
|
||||
require_relative 'helper'
|
||||
|
||||
module Vool
|
||||
class TestIfStatement < MiniTest::Test
|
||||
|
||||
def basic_if
|
||||
"if(10 < 12) ; true ; end"
|
||||
end
|
||||
def test_if_basic
|
||||
lst = RubyCompiler.compile( basic_if )
|
||||
assert_equal IfStatement , lst.class
|
||||
end
|
||||
def test_if_basic_cond
|
||||
lst = RubyCompiler.compile( basic_if )
|
||||
assert_equal ScopeStatement , lst.condition.class
|
||||
end
|
||||
def test_if_basic_branches
|
||||
lst = RubyCompiler.compile( basic_if )
|
||||
assert_equal TrueConstant , lst.if_true.class
|
||||
assert_nil lst.if_false
|
||||
end
|
||||
|
||||
def double_if
|
||||
"if(false) ; true ; else ; false; end"
|
||||
end
|
||||
def test_if_double
|
||||
lst = RubyCompiler.compile( double_if )
|
||||
assert_equal IfStatement , lst.class
|
||||
end
|
||||
def test_if_double_cond
|
||||
lst = RubyCompiler.compile( double_if )
|
||||
assert_equal ScopeStatement , lst.condition.class
|
||||
end
|
||||
def test_if_double_branches
|
||||
lst = RubyCompiler.compile( double_if )
|
||||
assert_equal TrueConstant , lst.if_true.class
|
||||
assert_equal FalseConstant, lst.if_false.class
|
||||
end
|
||||
|
||||
def reverse_if
|
||||
"true if(false)"
|
||||
end
|
||||
def test_if_reverse
|
||||
lst = RubyCompiler.compile( reverse_if )
|
||||
assert_equal IfStatement , lst.class
|
||||
end
|
||||
def test_if_reverse_cond
|
||||
lst = RubyCompiler.compile( reverse_if )
|
||||
assert_equal FalseConstant , lst.condition.class
|
||||
end
|
||||
def test_if_reverse_branches
|
||||
lst = RubyCompiler.compile( reverse_if )
|
||||
assert_equal TrueConstant , lst.if_true.class
|
||||
assert_nil lst.if_false
|
||||
end
|
||||
|
||||
def reverse_unless
|
||||
"true unless(false)"
|
||||
end
|
||||
def test_if_reverse
|
||||
lst = RubyCompiler.compile( reverse_unless )
|
||||
assert_equal IfStatement , lst.class
|
||||
end
|
||||
def test_if_reverse_cond
|
||||
lst = RubyCompiler.compile( reverse_unless )
|
||||
assert_equal ScopeStatement , lst.condition.class
|
||||
end
|
||||
def test_if_reverse_branches
|
||||
lst = RubyCompiler.compile( reverse_unless )
|
||||
assert_nil lst.if_true
|
||||
assert_equal TrueConstant ,lst.if_false.class
|
||||
end
|
||||
|
||||
def ternary
|
||||
"false ? true : false"
|
||||
end
|
||||
def test_if_ternary
|
||||
lst = RubyCompiler.compile( ternary )
|
||||
assert_equal IfStatement , lst.class
|
||||
end
|
||||
def test_if_ternary_cond
|
||||
lst = RubyCompiler.compile( ternary )
|
||||
assert_equal FalseConstant , lst.condition.class
|
||||
end
|
||||
def test_if_ternary_branches
|
||||
lst = RubyCompiler.compile( ternary )
|
||||
assert_equal TrueConstant , lst.if_true.class
|
||||
assert_equal FalseConstant, lst.if_false.class
|
||||
end
|
||||
end
|
||||
end
|
@ -1,31 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestIvarAssignment < MiniTest::Test
|
||||
|
||||
def test_local
|
||||
lst = RubyCompiler.compile( "foo = bar")
|
||||
assert_equal LocalAssignment , lst.class
|
||||
end
|
||||
def test_local_name
|
||||
lst = RubyCompiler.compile( "foo = bar")
|
||||
assert_equal :foo , lst.name
|
||||
end
|
||||
|
||||
def test_instance
|
||||
lst = RubyCompiler.compile( "@foo = bar")
|
||||
assert_equal IvarAssignment , lst.class
|
||||
end
|
||||
def test_instance_name
|
||||
lst = RubyCompiler.compile( "@foo = bar")
|
||||
assert_equal :foo , lst.name
|
||||
end
|
||||
|
||||
def test_const
|
||||
lst = RubyCompiler.compile( "@foo = 5")
|
||||
assert_equal IvarAssignment , lst.class
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
@ -1,25 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestLocalAssignment < MiniTest::Test
|
||||
|
||||
def test_local
|
||||
lst = RubyCompiler.compile( "foo = bar")
|
||||
assert_equal LocalAssignment , lst.class
|
||||
end
|
||||
def test_local_name
|
||||
lst = RubyCompiler.compile( "foo = bar")
|
||||
assert_equal :foo , lst.name
|
||||
end
|
||||
def test_local_const
|
||||
lst = RubyCompiler.compile( "foo = 5")
|
||||
assert_equal LocalAssignment , lst.class
|
||||
end
|
||||
def test_local_ivar
|
||||
lst = RubyCompiler.compile( "foo = @iv")
|
||||
assert_equal LocalAssignment , lst.class
|
||||
assert_equal InstanceVariable , lst.value.class
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,40 +0,0 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Vool
|
||||
class TestLogical < MiniTest::Test
|
||||
|
||||
def simple
|
||||
RubyCompiler.compile( "@a and @b")
|
||||
end
|
||||
def test_simple
|
||||
lst = simple
|
||||
assert_equal LogicalStatement , lst.class
|
||||
end
|
||||
def test_simple_name
|
||||
lst = simple
|
||||
assert_equal :and , lst.name
|
||||
end
|
||||
def test_simple_left
|
||||
lst = simple
|
||||
assert_equal InstanceVariable , lst.left.class
|
||||
end
|
||||
def test_simple_right
|
||||
lst = simple
|
||||
assert_equal InstanceVariable , lst.right.class
|
||||
end
|
||||
|
||||
def test_or
|
||||
lst = RubyCompiler.compile( "@a or @b")
|
||||
assert_equal :or , lst.name
|
||||
end
|
||||
|
||||
def test_or2
|
||||
lst = RubyCompiler.compile( "@a || @b")
|
||||
assert_equal :or , lst.name
|
||||
end
|
||||
def test_and2
|
||||
lst = RubyCompiler.compile( "@a && @b")
|
||||
assert_equal :and , lst.name
|
||||
end
|
||||
end
|
||||
end
|
@ -1,40 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestMethodStatement < MiniTest::Test
|
||||
|
||||
def basic_setup()
|
||||
input = "def tryout(arg1, arg2) ; true ; false ; end "
|
||||
@lst = RubyCompiler.compile( input )
|
||||
end
|
||||
def test_method
|
||||
basic_setup
|
||||
assert_equal MethodStatement , @lst.class
|
||||
end
|
||||
|
||||
def test_method_name
|
||||
basic_setup
|
||||
assert_equal :tryout , @lst.name
|
||||
end
|
||||
|
||||
def test_method_args
|
||||
basic_setup
|
||||
assert_equal [:arg1, :arg2] , @lst.args
|
||||
end
|
||||
def test_basic_body
|
||||
basic_setup
|
||||
assert_equal ScopeStatement , @lst.body.class
|
||||
assert_equal 2 , @lst.body.length
|
||||
end
|
||||
def test_body_is_scope_one_statement
|
||||
input = "def tryout(arg1, arg2) ; a = true ; end "
|
||||
lst = RubyCompiler.compile( input )
|
||||
assert_equal LocalAssignment , lst.body.class
|
||||
end
|
||||
def test_body_is_scope_zero_statement
|
||||
input = "def tryout(arg1, arg2) ; arg1 = arg2 ; end "
|
||||
lst = RubyCompiler.compile( input )
|
||||
assert_equal LocalAssignment , lst.body.class
|
||||
end
|
||||
end
|
||||
end
|
@ -1,39 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
module OpAss
|
||||
def test_local_name
|
||||
assert_equal :foo , @lst.name
|
||||
end
|
||||
def test_local_value
|
||||
assert_equal SendStatement , @lst.value.class
|
||||
end
|
||||
def test_local_method
|
||||
assert_equal :+ , @lst.value.name
|
||||
end
|
||||
def test_local_receiver
|
||||
assert_equal :foo , @lst.value.receiver.name
|
||||
end
|
||||
def test_local_receiver
|
||||
assert_equal 5 , @lst.value.arguments.first.value
|
||||
end
|
||||
end
|
||||
class TestLocalOpAssign < MiniTest::Test
|
||||
include OpAss
|
||||
def setup
|
||||
@lst = RubyCompiler.compile( "foo += 5")
|
||||
end
|
||||
def test_local_ass
|
||||
assert_equal LocalAssignment , @lst.class
|
||||
end
|
||||
end
|
||||
class TestIvarOpAssign < MiniTest::Test
|
||||
include OpAss
|
||||
def setup
|
||||
@lst = RubyCompiler.compile( "@foo += 5")
|
||||
end
|
||||
def test_ivar_ass
|
||||
assert_equal IvarAssignment , @lst.class
|
||||
end
|
||||
end
|
||||
end
|
@ -1,23 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestReturnStatement < MiniTest::Test
|
||||
|
||||
def test_return_const
|
||||
lst = RubyCompiler.compile( "return 1" )
|
||||
assert_equal ReturnStatement , lst.class
|
||||
end
|
||||
|
||||
def test_return_value
|
||||
lst = RubyCompiler.compile( "return 1" )
|
||||
assert_equal 1 , lst.return_value.value
|
||||
end
|
||||
|
||||
def test_return_send
|
||||
lst = RubyCompiler.compile( "return foo" )
|
||||
assert_equal SendStatement , lst.return_value.class
|
||||
assert_equal :foo , lst.return_value.name
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,79 +0,0 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Vool
|
||||
class TestSend < MiniTest::Test
|
||||
|
||||
def test_simple
|
||||
lst = RubyCompiler.compile( "foo")
|
||||
assert_equal SendStatement , lst.class
|
||||
end
|
||||
def test_simple_name
|
||||
lst = RubyCompiler.compile( "foo")
|
||||
assert_equal :foo , lst.name
|
||||
end
|
||||
def test_simple_receiver
|
||||
lst = RubyCompiler.compile( "foo")
|
||||
assert_equal SelfExpression , lst.receiver.class
|
||||
end
|
||||
def test_simple_args
|
||||
lst = RubyCompiler.compile( "foo")
|
||||
assert_equal [] , lst.arguments
|
||||
end
|
||||
|
||||
def test_one_arg
|
||||
lst = RubyCompiler.compile( "bar(1)")
|
||||
assert_equal SendStatement , lst.class
|
||||
end
|
||||
def test_one_arg_name
|
||||
lst = RubyCompiler.compile( "bar(1)")
|
||||
assert_equal :bar , lst.name
|
||||
end
|
||||
def test_one_arg_receiver
|
||||
lst = RubyCompiler.compile( "bar(1)")
|
||||
assert_equal SelfExpression , lst.receiver.class
|
||||
end
|
||||
def test_one_arg_args
|
||||
lst = RubyCompiler.compile( "bar(1)")
|
||||
assert_equal 1 , lst.arguments.first.value
|
||||
end
|
||||
|
||||
def test_super0_receiver
|
||||
lst = RubyCompiler.compile( "super")
|
||||
assert_equal SuperExpression , lst.receiver.class
|
||||
end
|
||||
def test_super0
|
||||
lst = RubyCompiler.compile( "super")
|
||||
assert_equal SendStatement , lst.class
|
||||
end
|
||||
|
||||
def test_super_receiver
|
||||
lst = RubyCompiler.compile( "super(1)")
|
||||
assert_equal SuperExpression , lst.receiver.class
|
||||
end
|
||||
def test_super_args
|
||||
lst = RubyCompiler.compile( "super(1)")
|
||||
assert_equal 1 , lst.arguments.first.value
|
||||
end
|
||||
def test_super_name #is nil
|
||||
lst = RubyCompiler.compile( "super(1)")
|
||||
assert_nil lst.name
|
||||
end
|
||||
end
|
||||
class TestSendReceiverType < MiniTest::Test
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
end
|
||||
|
||||
def test_int_receiver
|
||||
sent = RubyCompiler.compile( "5.div4")
|
||||
assert_equal Parfait::Type , sent.receiver.ct_type.class
|
||||
assert_equal "Integer_Type" , sent.receiver.ct_type.name
|
||||
end
|
||||
def test_string_receiver
|
||||
sent = RubyCompiler.compile( "'5'.putstring")
|
||||
assert_equal Parfait::Type , sent.receiver.ct_type.class
|
||||
assert_equal "Word_Type" , sent.receiver.ct_type.name
|
||||
end
|
||||
end
|
||||
end
|
@ -1,57 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestVariables < MiniTest::Test
|
||||
|
||||
# "free standing" local can not be tested as it will result in send
|
||||
# in other words ther is no way of knowing if a name is variable or method
|
||||
# one needs an assignemnt first, to "tell" the parser it's a local
|
||||
def test_local_basic
|
||||
lst = RubyCompiler.compile( "foo = 1 ; foo")
|
||||
assert_equal ScopeStatement , lst.class
|
||||
assert_equal LocalVariable , lst.statements[1].class
|
||||
end
|
||||
|
||||
def test_local_nane
|
||||
lst = RubyCompiler.compile( "foo = 1 ; foo")
|
||||
assert_equal LocalVariable , lst.statements[1].class
|
||||
end
|
||||
|
||||
def test_instance_basic
|
||||
lst = RubyCompiler.compile( "@var" )
|
||||
assert_equal InstanceVariable , lst.class
|
||||
assert_equal :var , lst.name
|
||||
end
|
||||
|
||||
def test_instance_return
|
||||
lst = RubyCompiler.compile( "return @var" )
|
||||
assert_equal InstanceVariable , lst.return_value.class
|
||||
end
|
||||
|
||||
def test_class_basic
|
||||
lst = RubyCompiler.compile( "@@var" )
|
||||
assert_equal ClassVariable , lst.class
|
||||
assert_equal :var , lst.name
|
||||
end
|
||||
|
||||
def test_class_return
|
||||
lst = RubyCompiler.compile( "return @@var" )
|
||||
assert_equal ClassVariable , lst.return_value.class
|
||||
end
|
||||
|
||||
def test_module_basic
|
||||
lst = RubyCompiler.compile( "Module" )
|
||||
assert_equal ModuleName , lst.class
|
||||
assert_equal :Module , lst.name
|
||||
end
|
||||
|
||||
def test_module_base_scoped
|
||||
lst = RubyCompiler.compile( "::Module" )
|
||||
assert_equal ModuleName , lst.class
|
||||
assert_equal :Module , lst.name
|
||||
end
|
||||
def test_module_module_scoped
|
||||
assert_raises {RubyCompiler.compile( "M::Module" ) }
|
||||
end
|
||||
end
|
||||
end
|
@ -1,39 +0,0 @@
|
||||
require_relative 'helper'
|
||||
|
||||
module Vool
|
||||
class TestWhileStatement < MiniTest::Test
|
||||
|
||||
def basic_while
|
||||
"while(10 < 12) ; true ; end"
|
||||
end
|
||||
def test_while_basic
|
||||
lst = RubyCompiler.compile( basic_while )
|
||||
assert_equal WhileStatement , lst.class
|
||||
end
|
||||
def test_while_basic_cond
|
||||
lst = RubyCompiler.compile( basic_while )
|
||||
assert_equal ScopeStatement , lst.condition.class
|
||||
end
|
||||
def test_while_basic_branches
|
||||
lst = RubyCompiler.compile( basic_while )
|
||||
assert_equal TrueConstant , lst.body.class
|
||||
end
|
||||
|
||||
def reverse_while
|
||||
"true while(false)"
|
||||
end
|
||||
def test_while_reverse_branches
|
||||
lst = RubyCompiler.compile( reverse_while )
|
||||
assert_equal WhileStatement , lst.class
|
||||
end
|
||||
def test_while_reverse_cond
|
||||
lst = RubyCompiler.compile( reverse_while )
|
||||
assert_equal ScopeStatement , lst.condition.class
|
||||
end
|
||||
def test_while_reverse_branches
|
||||
lst = RubyCompiler.compile( reverse_while )
|
||||
assert_equal TrueConstant , lst.body.class
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,27 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestYieldStatement < MiniTest::Test
|
||||
|
||||
def setup()
|
||||
input = "def plus_one; yield(0) ; end "
|
||||
@lst = RubyCompiler.compile( input )
|
||||
end
|
||||
def test_method
|
||||
assert_equal MethodStatement , @lst.class
|
||||
end
|
||||
def test_block
|
||||
assert_equal YieldStatement , @lst.body.class
|
||||
end
|
||||
def test_block_args
|
||||
assert_equal IntegerConstant , @lst.body.arguments.first.class
|
||||
end
|
||||
def test_method_yield?
|
||||
assert_equal true , @lst.has_yield?
|
||||
end
|
||||
def test_method_args
|
||||
Risc.machine.boot
|
||||
assert_equal 2 , @lst.make_arg_type.get_length
|
||||
end
|
||||
end
|
||||
end
|
@ -1,72 +0,0 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestClassCompiler < MiniTest::Test
|
||||
include CompilerHelper
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
end
|
||||
|
||||
def compile_in_test input
|
||||
vool = VoolCompiler.ruby_to_vool in_Test(input)
|
||||
vool.to_mom(nil)
|
||||
itest = Parfait.object_space.get_class_by_name(:Test)
|
||||
assert itest
|
||||
itest
|
||||
end
|
||||
|
||||
def test_compile_class_one
|
||||
itest = compile_in_test "def meth; @ivar = 5; end"
|
||||
assert itest.instance_type.names.include?(:ivar) , itest.instance_type.names.inspect
|
||||
end
|
||||
|
||||
def test_compile_class_two
|
||||
itest = compile_in_test "def meth; @ivar = 5; end;def meth2(arg); @trivar = 5; end"
|
||||
assert itest.instance_type.names.include?(:trivar) , itest.instance_type.names.inspect
|
||||
end
|
||||
|
||||
def test_doesnt_create_existing_clas
|
||||
space_class = Parfait.object_space.get_class_by_name(:Space)
|
||||
VoolCompiler.ruby_to_vool "class Space ; end"
|
||||
clazz = Parfait.object_space.get_class_by_name(:Space)
|
||||
assert_equal clazz , space_class
|
||||
end
|
||||
|
||||
def test_class_body_is_scope
|
||||
clazz = VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5 ;end")
|
||||
assert_equal MethodStatement , clazz.body.class
|
||||
end
|
||||
|
||||
def test_creates_class_without_deriviation
|
||||
vool = VoolCompiler.ruby_to_vool "class Testing ; end"
|
||||
vool.to_mom(nil)
|
||||
clazz = Parfait.object_space.get_class_by_name(:Testing)
|
||||
assert clazz , "No classes created"
|
||||
assert_equal :Object , clazz.super_class_name
|
||||
end
|
||||
|
||||
def test_creates_class_with_deriviation
|
||||
vool = VoolCompiler.ruby_to_vool "class Test2 < List ;end"
|
||||
vool.to_mom(nil)
|
||||
clazz = Parfait.object_space.get_class_by_name(:Test2)
|
||||
assert clazz, "No classes created"
|
||||
assert_equal :List , clazz.super_class_name
|
||||
end
|
||||
|
||||
def test_space_is_unchanged_by_compile
|
||||
space1 = Parfait.object_space.get_class_by_name(:Space)
|
||||
VoolCompiler.ruby_to_vool "class Space ;end"
|
||||
space2 = Parfait.object_space.get_class_by_name(:Space)
|
||||
assert_equal space1 , space2
|
||||
end
|
||||
|
||||
def test_space_type_is_unchanged_by_compile
|
||||
space1 = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||
VoolCompiler.ruby_to_vool "class Space ;end"
|
||||
space2 = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||
assert_equal space1 , space2
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user