wrap parfait tests in module and boot

This commit is contained in:
Torsten Ruger
2018-04-26 12:31:37 +03:00
parent 30ba626cf9
commit a7207a9984
18 changed files with 1001 additions and 976 deletions

View File

@ -1,75 +1,76 @@
require_relative "../../helper"
require_relative "../helper"
class BasicType < MiniTest::Test
module Parfait
class BasicType < ParfaitTest
def setup
Risc.machine.boot
@space = Parfait.object_space
@mess = @space.first_message
assert @mess
@type = @mess.get_type()
end
def setup
super
@mess = @space.first_message
assert @mess
@type = @mess.get_type()
end
def test_type_index
assert_equal @mess.get_type , @mess.get_internal_word(Parfait::TYPE_INDEX) , "mess"
end
def test_type_index
assert_equal @mess.get_type , @mess.get_internal_word(Parfait::TYPE_INDEX) , "mess"
end
def test_type_is_first
type = @mess.get_type
assert_equal 1 , type.variable_index(:type)
end
def test_type_is_first
type = @mess.get_type
assert_equal 1 , type.variable_index(:type)
end
def test_length
assert @mess
assert @mess.get_type
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
end
def test_length
assert @mess
assert @mess.get_type
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
end
def test_names
assert @type.names
end
def test_types
assert @type.types
end
def test_names
assert @type.names
end
def test_types
assert @type.types
end
def test_type_length
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
end
def test_type_length
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
end
def test_type_length_index
type = @mess.get_type.get_type
assert_equal 5 , type.variable_index(:methods)
assert_equal type.object_class , type.get_internal_word(4)
end
def test_type_length_index
type = @mess.get_type.get_type
assert_equal 5 , type.variable_index(:methods)
assert_equal type.object_class , type.get_internal_word(4)
end
def test_no_index_below_1
type = @mess.get_type
names = type.names
assert_equal 9 , names.get_length , names.inspect
names.each do |n|
assert type.variable_index(n) >= 1
def test_no_index_below_1
type = @mess.get_type
names = type.names
assert_equal 9 , names.get_length , names.inspect
names.each do |n|
assert type.variable_index(n) >= 1
end
end
def test_attribute_set
@mess.set_receiver( 55)
assert_equal 55 , @mess.receiver
end
# not really parfait test, but related and no other place currently
def test_reg_index
message_ind = Risc.resolve_to_index( :message , :receiver )
assert_equal 3 , message_ind
@mess.set_receiver( 55)
assert_equal 55 , @mess.get_internal_word(message_ind)
end
def test_instance_type
assert_equal 2 , @mess.get_type.variable_index(:next_message)
end
def test_remove_me
type = @mess.get_type
assert_equal type , @mess.get_internal_word(1)
end
end
def test_attribute_set
@mess.set_receiver( 55)
assert_equal 55 , @mess.receiver
end
# not really parfait test, but related and no other place currently
def test_reg_index
message_ind = Risc.resolve_to_index( :message , :receiver )
assert_equal 3 , message_ind
@mess.set_receiver( 55)
assert_equal 55 , @mess.get_internal_word(message_ind)
end
def test_instance_type
assert_equal 2 , @mess.get_type.variable_index(:next_message)
end
def test_remove_me
type = @mess.get_type
assert_equal type , @mess.get_internal_word(1)
end
end

View File

@ -1,45 +1,46 @@
require_relative "../../helper"
require_relative "../helper"
class TypeHash < MiniTest::Test
module Parfait
class TypeHash < ParfaitTest
def setup
Risc.machine.boot
@space = Parfait.object_space
@types = @space.instance_variable_ged("@types")
@first = @types.values.first
end
def setup
super
@types = @space.instance_variable_ged("@types")
@first = @types.values.first
end
def test_hash
assert_equal Parfait::Dictionary , @types.class
end
def test_hash
assert_equal Parfait::Dictionary , @types.class
end
def test_length
assert @types.length > 11
end
def test_length
assert @types.length > 11
end
def test_two_hashs_not_equal
assert @types.keys.last != @types.keys.first
end
def test_two_hashs_not_equal
assert @types.keys.last != @types.keys.first
end
def test_name
assert_equal "Word_Type" , @types.values.first.name
end
def test_name
assert_equal "Word_Type" , @types.values.first.name
end
def test_to_hash
hash = @first.to_hash
assert_equal hash[:type] , :Type
assert_equal 2 , hash.length
end
def test_add_is_different
type = @first.add_instance_variable :random , :Integer
assert type != @first , "new: #{type.inspect} , old: #{@first.inspect}"
assert @first.hash != type.hash
end
def test_to_hash
hash = @first.to_hash
assert_equal hash[:type] , :Type
assert_equal 2 , hash.length
end
def test_add_is_different
type = @first.add_instance_variable :random , :Integer
assert type != @first , "new: #{type.inspect} , old: #{@first.inspect}"
assert @first.hash != type.hash
end
def test_hash_for_no_ivars
list = @space.get_class_by_name(:NamedList )
t1 = Parfait::Type.for_hash( list , type: :NewInt)
t2 = Parfait::Type.for_hash( list , type: :NewObj)
assert t1.hash != t2.hash , "Hashes should differ"
def test_hash_for_no_ivars
list = @space.get_class_by_name(:NamedList )
t1 = Parfait::Type.for_hash( list , type: :NewInt)
t2 = Parfait::Type.for_hash( list , type: :NewObj)
assert t1.hash != t2.hash , "Hashes should differ"
end
end
end

View File

@ -1,29 +1,30 @@
require_relative "../../helper"
require_relative "../helper"
class TypeMessages < MiniTest::Test
module Parfait
class TypeMessages < ParfaitTest
def setup
super
@mess = @space.first_message
end
def test_message_type
type = @mess.get_type
assert type
assert @mess.instance_variable_defined :next_message
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
end
def test_message_by_index
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
index = @mess.get_type.variable_index :next_message
assert_equal 2 , index
assert_equal @mess.next_message , @mess.get_internal_word(index)
end
def test_type_methods
assert_equal 5 , @mess.get_type.get_type.variable_index(:methods)
end
def setup
Risc.machine.boot
@space = Parfait.object_space
@mess = @space.first_message
end
def test_message_type
type = @mess.get_type
assert type
assert @mess.instance_variable_defined :next_message
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
end
def test_message_by_index
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
index = @mess.get_type.variable_index :next_message
assert_equal 2 , index
assert_equal @mess.next_message , @mess.get_internal_word(index)
end
def test_type_methods
assert_equal 5 , @mess.get_type.get_type.variable_index(:methods)
end
end

View File

@ -1,82 +1,83 @@
require_relative "../../helper"
require_relative "../helper"
class TestMethodApi < MiniTest::Test
module Parfait
class TestMethodApi < ParfaitTest
def setup
Risc.machine.boot
@space = Parfait.object_space
@try_class = @space.create_class( :Try )
@try_type = @try_class.instance_type
end
def setup
super
@try_class = @space.create_class( :Try )
@try_type = @try_class.instance_type
end
def empty_frame
Parfait::Type.for_hash( @try_class , { })
end
def foo_method( for_class = :Try)
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
::Parfait::TypedMethod.new( @space.get_class_by_name(for_class).instance_type , :foo , args,empty_frame)
end
def add_foo_to( clazz = :Try )
foo = foo_method( clazz )
assert_equal foo , @space.get_class_by_name(clazz).instance_type.add_method(foo)
foo
end
def object_type
@space.get_class_by_name(:Object).instance_type
end
def test_new_methods
assert_equal Parfait::List , @try_type.method_names.class
assert_equal @try_type.method_names.get_length , @try_type.methods_length
end
def test_add_method
before = @try_type.methods_length
add_foo_to
assert_equal 1 , @try_type.methods_length - before
assert @try_type.method_names.inspect.include?(":foo")
end
def test_remove_method
add_foo_to
assert @try_type.remove_method(:foo)
end
def test_remove_not_there
assert_raises RuntimeError do
@try_type.remove_method(:foo)
def empty_frame
Parfait::Type.for_hash( @try_class , { })
end
def foo_method( for_class = :Try)
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
::Parfait::TypedMethod.new( @space.get_class_by_name(for_class).instance_type , :foo , args,empty_frame)
end
def add_foo_to( clazz = :Try )
foo = foo_method( clazz )
assert_equal foo , @space.get_class_by_name(clazz).instance_type.add_method(foo)
foo
end
def object_type
@space.get_class_by_name(:Object).instance_type
end
def test_new_methods
assert_equal Parfait::List , @try_type.method_names.class
assert_equal @try_type.method_names.get_length , @try_type.methods_length
end
def test_add_method
before = @try_type.methods_length
add_foo_to
assert_equal 1 , @try_type.methods_length - before
assert @try_type.method_names.inspect.include?(":foo")
end
def test_remove_method
add_foo_to
assert @try_type.remove_method(:foo)
end
def test_remove_not_there
assert_raises RuntimeError do
@try_type.remove_method(:foo)
end
end
def test_create_method
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
@try_type.create_method :bar, args , empty_frame
assert @try_type.method_names.inspect.include?("bar")
end
def test_method_get
add_foo_to
assert_equal Parfait::TypedMethod , @try_type.get_method(:foo).class
end
def test_method_get_nothere
assert_nil @try_type.get_method(:foo)
test_remove_method
assert_nil @try_type.get_method(:foo)
end
def test_get_instance
foo = foo_method :Object
type = @space.get_class_by_name(:Object).instance_type
type.add_method(foo)
assert_equal :foo , type.get_method(:foo).name
end
def test_resolve_on_object
add_foo_to :Object
assert_equal :foo , object_type.resolve_method( :foo ).name
end
def test_resolve_super
add_foo_to :Object
assert_equal :foo , @try_class.instance_type.resolve_method( :foo ).name
end
def test_resolve_is_get
add_foo_to
assert_equal :foo , @try_class.instance_type.resolve_method( :foo ).name
assert_equal :foo , @try_class.instance_type.get_method( :foo ).name
end
def test_resolve_fail
assert_nil object_type.resolve_method( :foo )
end
end
def test_create_method
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
@try_type.create_method :bar, args , empty_frame
assert @try_type.method_names.inspect.include?("bar")
end
def test_method_get
add_foo_to
assert_equal Parfait::TypedMethod , @try_type.get_method(:foo).class
end
def test_method_get_nothere
assert_nil @try_type.get_method(:foo)
test_remove_method
assert_nil @try_type.get_method(:foo)
end
def test_get_instance
foo = foo_method :Object
type = @space.get_class_by_name(:Object).instance_type
type.add_method(foo)
assert_equal :foo , type.get_method(:foo).name
end
def test_resolve_on_object
add_foo_to :Object
assert_equal :foo , object_type.resolve_method( :foo ).name
end
def test_resolve_super
add_foo_to :Object
assert_equal :foo , @try_class.instance_type.resolve_method( :foo ).name
end
def test_resolve_is_get
add_foo_to
assert_equal :foo , @try_class.instance_type.resolve_method( :foo ).name
assert_equal :foo , @try_class.instance_type.get_method( :foo ).name
end
def test_resolve_fail
assert_nil object_type.resolve_method( :foo )
end
end

View File

@ -1,93 +1,94 @@
require_relative "../../helper"
require_relative "../helper"
class TypeApi < MiniTest::Test
module Parfait
class TypeApi < ParfaitTest
def setup
Risc.machine.boot
@space = Parfait.object_space
tc = @space.get_class_by_name( :NamedList )
@type = tc.instance_type
end
def test_inspect
assert @type.inspect.start_with?("Type")
end
def test_class_type
oc = @space.get_class_by_name( :Object )
assert_equal Parfait::Class , oc.class
type = oc.instance_type
assert_equal Parfait::Type , type.class
assert_equal 1 , type.names.get_length , type.names.inspect
assert_equal type.names.first , :type
end
def test_class_space
space = Parfait.object_space
assert_equal Parfait::Space , space.class
type = space.get_type
assert_equal Parfait::Type , type.class
assert_equal 8 , type.names.get_length
assert_equal type.object_class.class , Parfait::Class
assert_equal type.object_class.name , :Space
end
def test_add_name
t = @type.add_instance_variable( :boo , :Object)
assert t
t
end
def test_added_name_length
type = test_add_name
assert_equal 2 , type.names.get_length , type.inspect
assert_equal :type , type.names.get(1)
assert_equal :boo , type.names.get(2)
end
def test_added_name_index
type = test_add_name
assert_equal 2 , type.variable_index(:boo)
assert_equal :Object , type.type_at(2)
end
def test_basic_var_index
assert_equal 1 , @type.variable_index(:type)
end
def test_basic_type_index
assert_equal :Type , @type.type_at(1)
end
def test_inspect_added
type = test_add_name
assert type.inspect.include?("boo") , type.inspect
end
def test_added_names
type = test_add_name
assert_equal :type , type.names.get(1)
assert_equal :boo , type.names.get(2)
assert_equal 2 , type.names.get_length
end
def test_each_name
type = test_add_name
assert_equal 2 , type.get_length
counter = [ :boo , :type ]
type.names.each do |item|
assert_equal item , counter.delete(item)
def setup
super
tc = @space.get_class_by_name( :NamedList )
@type = tc.instance_type
end
assert counter.empty? , counter.inspect
end
def test_each_type
type = test_add_name
assert_equal 2 , type.get_length
counter = [ :Object , :Type]
type.types.each do |item|
assert_equal item , counter.delete(item)
def test_inspect
assert @type.inspect.start_with?("Type")
end
assert counter.empty? , counter.inspect
end
def test_class_type
oc = @space.get_class_by_name( :Object )
assert_equal Parfait::Class , oc.class
type = oc.instance_type
assert_equal Parfait::Type , type.class
assert_equal 1 , type.names.get_length , type.names.inspect
assert_equal type.names.first , :type
end
def test_class_space
space = Parfait.object_space
assert_equal Parfait::Space , space.class
type = space.get_type
assert_equal Parfait::Type , type.class
assert_equal 8 , type.names.get_length
assert_equal type.object_class.class , Parfait::Class
assert_equal type.object_class.name , :Space
end
def test_add_name
t = @type.add_instance_variable( :boo , :Object)
assert t
t
end
def test_added_name_length
type = test_add_name
assert_equal 2 , type.names.get_length , type.inspect
assert_equal :type , type.names.get(1)
assert_equal :boo , type.names.get(2)
end
def test_added_name_index
type = test_add_name
assert_equal 2 , type.variable_index(:boo)
assert_equal :Object , type.type_at(2)
end
def test_basic_var_index
assert_equal 1 , @type.variable_index(:type)
end
def test_basic_type_index
assert_equal :Type , @type.type_at(1)
end
def test_inspect_added
type = test_add_name
assert type.inspect.include?("boo") , type.inspect
end
def test_added_names
type = test_add_name
assert_equal :type , type.names.get(1)
assert_equal :boo , type.names.get(2)
assert_equal 2 , type.names.get_length
end
def test_each_name
type = test_add_name
assert_equal 2 , type.get_length
counter = [ :boo , :type ]
type.names.each do |item|
assert_equal item , counter.delete(item)
end
assert counter.empty? , counter.inspect
end
def test_each_type
type = test_add_name
assert_equal 2 , type.get_length
counter = [ :Object , :Type]
type.types.each do |item|
assert_equal item , counter.delete(item)
end
assert counter.empty? , counter.inspect
end
end
end