fixes parfait/type tests place and guard file accordingly

test were in old directory and guard file broken accordingly
This commit is contained in:
Torsten Ruger
2017-04-23 18:43:32 +03:00
parent dda2ddd9fb
commit e387bdb5f2
6 changed files with 8 additions and 10 deletions

View File

@ -0,0 +1,75 @@
require_relative "../../helper"
class BasicType < MiniTest::Test
def setup
Risc.machine.boot
@space = Parfait.object_space
@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_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_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_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
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

@ -0,0 +1,45 @@
require_relative "../../helper"
class TypeHash < MiniTest::Test
def setup
Risc.machine.boot
@space = Parfait.object_space
@types = @space.instance_variable_get("@types")
@first = @types.values.first
end
def test_hash
assert_equal Parfait::Dictionary , @types.class
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_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_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

View File

@ -0,0 +1,29 @@
require_relative "../../helper"
class TypeMessages < MiniTest::Test
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

@ -0,0 +1,58 @@
require_relative "../../helper"
class TestMethodApi < MiniTest::Test
def setup
Risc.machine.boot
@space = Parfait.object_space
@try_class = @space.create_class( :Try )
@try_type = @try_class.instance_type
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
end
def test_new_methods
assert_equal @try_type.method_names.class, @try_type.methods.class
assert_equal @try_type.method_names.get_length , @try_type.methods.get_length
end
def test_add_method
before = @try_type.methods.get_length
foo = foo_method
assert_equal foo , @try_type.add_method(foo)
assert_equal 1 , @try_type.methods.get_length - before
assert @try_type.method_names.inspect.include?(":foo")
end
def test_remove_method
test_add_method
assert_equal true , @try_type.remove_method(:foo)
end
def test_remove_nothere
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
assert @try_type.method_names.inspect.include?("bar")
end
def test_method_get
test_add_method
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
end

View File

@ -0,0 +1,93 @@
require_relative "../../helper"
class TypeApi < MiniTest::Test
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 4 , 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