rename
This commit is contained in:
1
test/vool/ruby_compiler/helper.rb
Normal file
1
test/vool/ruby_compiler/helper.rb
Normal file
@ -0,0 +1 @@
|
||||
require_relative "../helper"
|
19
test/vool/ruby_compiler/test_array_statement.rb
Normal file
19
test/vool/ruby_compiler/test_array_statement.rb
Normal file
@ -0,0 +1,19 @@
|
||||
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
|
77
test/vool/ruby_compiler/test_basic_values.rb
Normal file
77
test/vool/ruby_compiler/test_basic_values.rb
Normal file
@ -0,0 +1,77 @@
|
||||
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
|
44
test/vool/ruby_compiler/test_class_statement.rb
Normal file
44
test/vool/ruby_compiler/test_class_statement.rb
Normal file
@ -0,0 +1,44 @@
|
||||
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_equal 0 , @lst.body.length
|
||||
assert_equal ScopeStatement , @lst.body.class
|
||||
end
|
||||
|
||||
end
|
||||
class TestBasicClassStatement < MiniTest::Test
|
||||
include CompilerHelper
|
||||
|
||||
def test_compile_one_method
|
||||
lst = RubyCompiler.compile( in_Test("@ivar") )
|
||||
assert_equal ScopeStatement , lst.body.class
|
||||
assert_equal InstanceVariable , lst.body.statements.first.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
|
35
test/vool/ruby_compiler/test_hash_statement.rb
Normal file
35
test/vool/ruby_compiler/test_hash_statement.rb
Normal file
@ -0,0 +1,35 @@
|
||||
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
|
91
test/vool/ruby_compiler/test_if_statement.rb
Normal file
91
test/vool/ruby_compiler/test_if_statement.rb
Normal file
@ -0,0 +1,91 @@
|
||||
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 SendStatement , 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 FalseConstant , 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 FalseConstant , 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
|
31
test/vool/ruby_compiler/test_ivar.rb
Normal file
31
test/vool/ruby_compiler/test_ivar.rb
Normal file
@ -0,0 +1,31 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestAssignment < 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
|
20
test/vool/ruby_compiler/test_local.rb
Normal file
20
test/vool/ruby_compiler/test_local.rb
Normal file
@ -0,0 +1,20 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestLocal < 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
|
||||
|
||||
end
|
||||
end
|
40
test/vool/ruby_compiler/test_logical_statement.rb
Normal file
40
test/vool/ruby_compiler/test_logical_statement.rb
Normal file
@ -0,0 +1,40 @@
|
||||
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
|
40
test/vool/ruby_compiler/test_method_statement.rb
Normal file
40
test/vool/ruby_compiler/test_method_statement.rb
Normal file
@ -0,0 +1,40 @@
|
||||
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) ; true ; end "
|
||||
lst = RubyCompiler.compile( input )
|
||||
assert_equal ScopeStatement , lst.body.class
|
||||
end
|
||||
def test_body_is_scope_zero_statement
|
||||
input = "def tryout(arg1, arg2) ; ; end "
|
||||
lst = RubyCompiler.compile( input )
|
||||
assert_equal ScopeStatement , lst.body.class
|
||||
end
|
||||
end
|
||||
end
|
23
test/vool/ruby_compiler/test_return_statement.rb
Normal file
23
test/vool/ruby_compiler/test_return_statement.rb
Normal file
@ -0,0 +1,23 @@
|
||||
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
|
79
test/vool/ruby_compiler/test_send_statement.rb
Normal file
79
test/vool/ruby_compiler/test_send_statement.rb
Normal file
@ -0,0 +1,79 @@
|
||||
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.mod4")
|
||||
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
|
57
test/vool/ruby_compiler/test_variables.rb
Normal file
57
test/vool/ruby_compiler/test_variables.rb
Normal file
@ -0,0 +1,57 @@
|
||||
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
|
39
test/vool/ruby_compiler/test_while_statement.rb
Normal file
39
test/vool/ruby_compiler/test_while_statement.rb
Normal file
@ -0,0 +1,39 @@
|
||||
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 SendStatement , lst.condition.class
|
||||
end
|
||||
def test_while_basic_branches
|
||||
lst = RubyCompiler.compile( basic_while )
|
||||
assert_equal TrueConstant , lst.statements.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 FalseConstant , lst.condition.class
|
||||
end
|
||||
def test_while_reverse_branches
|
||||
lst = RubyCompiler.compile( reverse_while )
|
||||
assert_equal TrueConstant , lst.statements.class
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user