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

11
test/parfait/helper.rb Normal file
View File

@ -0,0 +1,11 @@
require_relative "../helper"
module Parfait
class ParfaitTest < MiniTest::Test
def setup
@machine = Risc.machine.boot
@space = Parfait.object_space
end
end
end

View File

@ -1,40 +1,41 @@
require_relative "../helper" require_relative "helper"
class TestAttributes < MiniTest::Test module Parfait
class TestAttributes < ParfaitTest
def setup def setup
Risc.machine.boot super
@space = Parfait.object_space @mess = @space.first_message
@mess = @space.first_message @type = @mess.get_type
@type = @mess.get_type end
end
def test_message_get_type def test_message_get_type
assert_equal Parfait::Type , @type.class assert_equal Parfait::Type , @type.class
end end
def test_message_name_nil def test_message_name_nil
last = @type.names.last last = @type.names.last
assert_equal :arguments , last , @type.names.inspect assert_equal :arguments , last , @type.names.inspect
assert_nil @mess.name assert_nil @mess.name
end end
def test_message_next_set def test_message_next_set
@mess.next_message = :next_message @mess.next_message = :next_message
assert_equal :next_message , @mess.next_message assert_equal :next_message , @mess.next_message
end end
def test_message_type_set def test_message_type_set
@mess.set_type @type @mess.set_type @type
assert_equal @type , @mess.get_type assert_equal @type , @mess.get_type
end end
def test_attribute_index def test_attribute_index
@mess.next_message = :message @mess.next_message = :message
assert_equal Parfait::Type , @mess.get_type.class assert_equal Parfait::Type , @mess.get_type.class
end end
def test_type_type def test_type_type
assert_equal Parfait::Type , @type.get_type.get_type.class assert_equal Parfait::Type , @type.get_type.get_type.class
end end
def test_type_type_type def test_type_type_type
assert_equal Parfait::Type , @type.get_type.get_type.get_type.class assert_equal Parfait::Type , @type.get_type.get_type.get_type.class
end
end end
end end

View File

@ -1,10 +1,10 @@
require_relative "../helper" require_relative "helper"
module Parfait module Parfait
class TestBinaryCode < MiniTest::Test class TestBinaryCode < ParfaitTest
def setup def setup
Risc.machine.boot super
@code = BinaryCode.new(10) @code = BinaryCode.new(10)
end end

View File

@ -1,49 +1,50 @@
require_relative "../helper" require_relative "helper"
class TestClass < MiniTest::Test module Parfait
class TestClass < ParfaitTest
def setup def setup
Risc.machine.boot super
@space = Parfait.object_space @try = @space.create_class :Try , :Object
@try = @space.create_class :Try , :Object end
end
def test_type_forclass def test_type_forclass
assert_equal "Class(Space)" , @space.get_type.object_class.inspect assert_equal "Class(Space)" , @space.get_type.object_class.inspect
assert_equal :Space , @space.get_type.object_class.name assert_equal :Space , @space.get_type.object_class.name
end end
def test_new_superclass_name def test_new_superclass_name
assert_equal :Object , @try.super_class_name assert_equal :Object , @try.super_class_name
end end
def test_new_superclass def test_new_superclass
assert_equal "Class(Object)" , @try.super_class!.inspect assert_equal "Class(Object)" , @try.super_class!.inspect
assert_equal "Class(Object)" , @try.super_class.inspect assert_equal "Class(Object)" , @try.super_class.inspect
end end
def test_new_methods def test_new_methods
assert_equal @try.method_names.class, @try.instance_methods.class assert_equal @try.method_names.class, @try.instance_methods.class
assert_equal @try.method_names.get_length , @try.instance_methods.get_length assert_equal @try.method_names.get_length , @try.instance_methods.get_length
end end
def test_remove_nothere def test_remove_nothere
assert !@try.remove_instance_method(:foo) assert !@try.remove_instance_method(:foo)
end end
def test_resolve def test_resolve
assert_nil @try.resolve_method :foo assert_nil @try.resolve_method :foo
end end
def test_remove_method def test_remove_method
assert_equal false , @try.remove_instance_method( :foo) assert_equal false , @try.remove_instance_method( :foo)
end end
def test_add_nil_method_raises def test_add_nil_method_raises
assert_raises{ @try.add_instance_method(nil)} assert_raises{ @try.add_instance_method(nil)}
end end
def test_add_instance_variable_changes_type def test_add_instance_variable_changes_type
before = @space.get_class.instance_type before = @space.get_class.instance_type
@space.get_class.add_instance_variable(:counter , :Integer) @space.get_class.add_instance_variable(:counter , :Integer)
assert before != @space.get_class.instance_type assert before != @space.get_class.instance_type
end end
def test_add_instance_variable_changes_type_hash def test_add_instance_variable_changes_type_hash
before = @space.get_class.instance_type.hash before = @space.get_class.instance_type.hash
@space.get_class.add_instance_variable(:counter , :Integer) @space.get_class.add_instance_variable(:counter , :Integer)
assert before != @space.get_class.instance_type.hash assert before != @space.get_class.instance_type.hash
end end
end
end end

View File

@ -1,76 +1,79 @@
require_relative "../helper" require_relative "helper"
class TestDictionary < MiniTest::Test module Parfait
class TestDictionary < ParfaitTest
def setup def setup
@lookup = ::Parfait::Dictionary.new super
end @lookup = ::Parfait::Dictionary.new
def test_dict_create
assert_equal 0 , @lookup.length
assert @lookup.empty?
end
def test_empty_dict_doesnt_return
assert_nil @lookup.get(3)
assert_nil @lookup.get(:any)
end
def test_one_set1
assert_equal 1 , @lookup.set(1,1)
assert_equal 1 , @lookup.length
end
def test_one_double
assert_equal 1 , @lookup.set(1,1)
assert_equal 3 , @lookup.set(1,3)
assert_equal 1 , @lookup.length
end
def test_one_double2
assert_equal 1 , @lookup.set(:one,1)
assert_equal 3 , @lookup.set(:one,3)
assert_equal 1 , @lookup.length
end
def test_one_set2
assert_equal :some , @lookup.set(1,:some)
end
def test_two_sets
assert_equal 1 , @lookup.set(1,1)
assert_equal :some , @lookup.set(1,:some)
end
def test_one_get1
test_one_set1
assert_equal 1 , @lookup.get(1)
end
def test_one_get2
test_one_set2
assert_equal :some , @lookup.get(1)
end
def test_inspect1
@lookup[:key] = :value
assert_equal "Dictionary{key => value ,}" , @lookup.inspect
end
def test_inspect2
@lookup[:key1] = :value1
@lookup[:key2] = :value2
assert_equal "Dictionary{key1 => value1 ,key2 => value2 ,}" , @lookup.inspect
end
def test_many_get
shouldda = { :one => 1 , :two => 2 , :three => 3}
shouldda.each do |k,v|
@lookup.set(k,v)
end end
@lookup.each do |k,v| def test_dict_create
assert_equal v , shouldda[k] assert_equal 0 , @lookup.length
assert @lookup.empty?
end
def test_empty_dict_doesnt_return
assert_nil @lookup.get(3)
assert_nil @lookup.get(:any)
end
def test_one_set1
assert_equal 1 , @lookup.set(1,1)
assert_equal 1 , @lookup.length
end
def test_one_double
assert_equal 1 , @lookup.set(1,1)
assert_equal 3 , @lookup.set(1,3)
assert_equal 1 , @lookup.length
end
def test_one_double2
assert_equal 1 , @lookup.set(:one,1)
assert_equal 3 , @lookup.set(:one,3)
assert_equal 1 , @lookup.length
end
def test_one_set2
assert_equal :some , @lookup.set(1,:some)
end
def test_two_sets
assert_equal 1 , @lookup.set(1,1)
assert_equal :some , @lookup.set(1,:some)
end
def test_one_get1
test_one_set1
assert_equal 1 , @lookup.get(1)
end
def test_one_get2
test_one_set2
assert_equal :some , @lookup.get(1)
end
def test_inspect1
@lookup[:key] = :value
assert_equal "Dictionary{key => value ,}" , @lookup.inspect
end
def test_inspect2
@lookup[:key1] = :value1
@lookup[:key2] = :value2
assert_equal "Dictionary{key1 => value1 ,key2 => value2 ,}" , @lookup.inspect
end
def test_many_get
shouldda = { :one => 1 , :two => 2 , :three => 3}
shouldda.each do |k,v|
@lookup.set(k,v)
end
@lookup.each do |k,v|
assert_equal v , shouldda[k]
end
end
def test_values
@lookup[2] = 2
assert @lookup.values.get_length == 1
end
def test_keys
@lookup[2] = 2
assert @lookup.keys.get_length == 1
end
def test_override_exising
@lookup[2] = 2
@lookup[2] = :two
assert @lookup[2] == :two
end end
end
def test_values
@lookup[2] = 2
assert @lookup.values.get_length == 1
end
def test_keys
@lookup[2] = 2
assert @lookup.keys.get_length == 1
end
def test_override_exising
@lookup[2] = 2
@lookup[2] = :two
assert @lookup[2] == :two
end end
end end

View File

@ -1,10 +1,10 @@
require_relative "../helper" require_relative "helper"
module Parfait module Parfait
class TestInteger < MiniTest::Test class TestInteger < ParfaitTest
def setup def setup
Risc.machine.boot super
@int = Integer.new(10) @int = Integer.new(10)
end end

View File

@ -1,198 +1,201 @@
require_relative "../helper" require_relative "helper"
class TestList < MiniTest::Test module Parfait
class TestList < ParfaitTest
def setup def setup
@list = ::Parfait::List.new super
end @list = ::Parfait::List.new
def test_isa end
assert @list.is_a? Parfait::List def test_isa
end assert @list.is_a? Parfait::List
def test_old_type end
assert_equal Parfait::Type , Parfait.object_space.classes.keys.get_type.class def test_old_type
end assert_equal Parfait::Type , Parfait.object_space.classes.keys.get_type.class
def test_old_type_push end
list = Parfait.object_space.classes.keys def test_old_type_push
assert_equal Parfait::Type , list.get_type.class list = Parfait.object_space.classes.keys
end assert_equal Parfait::Type , list.get_type.class
def test_new_type end
assert_equal Parfait::Type , @list.get_type.class def test_new_type
end assert_equal Parfait::Type , @list.get_type.class
def test_new_type_push end
@list.push(1) def test_new_type_push
assert_equal Parfait::Type , @list.get_type.class @list.push(1)
end assert_equal Parfait::Type , @list.get_type.class
def notest_type_is_first end
type = @list.get_type def notest_type_is_first
assert_equal 1 , type.variable_index(:type) type = @list.get_type
end assert_equal 1 , type.variable_index(:type)
def notest_type_is_first_old end
type = Parfait.object_space.classes.keys.get_type def notest_type_is_first_old
assert_equal 1 , type.variable_index(:type) type = Parfait.object_space.classes.keys.get_type
end assert_equal 1 , type.variable_index(:type)
end
def test_length0 def test_length0
assert_equal 0 , @list.get_length assert_equal 0 , @list.get_length
assert_equal 0, @list.indexed_length assert_equal 0, @list.indexed_length
end
def test_offset
assert_equal 2 , @list.get_offset
end
def test_indexed_index
# 1 type , 2 indexed_length
assert_equal 2 , @list.get_type.variable_index(:indexed_length)
end
def test_length1
@list.push :one
assert_equal 1 , @list.get_length
assert_equal 1 , @list.indexed_length
assert_equal 1 , @list.get_internal_word(Parfait::TYPE_INDEX + 1)
end
def test_list_inspect
@list.set(1,1)
assert_equal "1" , @list.inspect
end
def test_list_equal
@list.set(1,1)
list = ::Parfait::List.new
list.set(1,1)
assert @list.equal? list
end
def test_list_create
assert @list.empty?
end
def test_list_len
assert_equal 0 , @list.get_length
end
def test_empty_list_doesnt_return
assert_nil @list.get(3)
end
def test_one_set1
assert_equal 2 , @list.set(1,2)
assert_equal 1 , @list.get_internal_word(2)
end
def test_set1_len
@list.set(1,1)
assert_equal 1 , @list.get_length
end
def test_one_set2
assert_equal :some , @list.set(2,:some)
end
def test_set2_len
@list.set(2,:some)
assert_equal 2 , @list.get_length
end
def test_two_sets
assert_equal 1 , @list.set(1,1)
assert_equal :some , @list.set(1,:some)
end
def test_one_get1
test_one_set1
assert_equal 2 , @list.get(1)
end
def test_one_get2
test_one_set2
assert_equal :some , @list.get(2)
end
def set_shouldda
shouldda = { 1 => :one , 2 => :two , 3 => :three}
shouldda.each do |k,v|
@list.set(k,v)
end end
shouldda def test_offset
end assert_equal 2 , @list.get_offset
def test_many_get
shouldda = set_shouldda
shouldda.each do |k,v|
assert_equal v , @list.get(k)
end end
end def test_indexed_index
def test_each # 1 type , 2 indexed_length
shouldda_values = set_shouldda.values assert_equal 2 , @list.get_type.variable_index(:indexed_length)
@list.each do |val|
shouldda_values.delete val
end end
assert_equal 0 , shouldda_values.length def test_length1
end @list.push :one
def test_each_index assert_equal 1 , @list.get_length
set_shouldda assert_equal 1 , @list.indexed_length
@list.each_with_index do |val , index| assert_equal 1 , @list.get_internal_word(Parfait::TYPE_INDEX + 1)
assert_equal @list[index] , val
end end
end def test_list_inspect
def test_each_pair_length @list.set(1,1)
shouldda_values = set_shouldda.values assert_equal "1" , @list.inspect
@list.each_pair do |key,val|
shouldda_values.delete key
shouldda_values.delete val
end end
assert_equal 0 , shouldda_values.length def test_list_equal
end @list.set(1,1)
def test_each_pair_count list = ::Parfait::List.new
set_shouldda.values list.set(1,1)
counter = 0 assert @list.equal? list
@list.each_pair do |key,val| end
counter += 1 def test_list_create
assert @list.empty?
end
def test_list_len
assert_equal 0 , @list.get_length
end
def test_empty_list_doesnt_return
assert_nil @list.get(3)
end
def test_one_set1
assert_equal 2 , @list.set(1,2)
assert_equal 1 , @list.get_internal_word(2)
end
def test_set1_len
@list.set(1,1)
assert_equal 1 , @list.get_length
end
def test_one_set2
assert_equal :some , @list.set(2,:some)
end
def test_set2_len
@list.set(2,:some)
assert_equal 2 , @list.get_length
end
def test_two_sets
assert_equal 1 , @list.set(1,1)
assert_equal :some , @list.set(1,:some)
end
def test_one_get1
test_one_set1
assert_equal 2 , @list.get(1)
end
def test_one_get2
test_one_set2
assert_equal :some , @list.get(2)
end
def set_shouldda
shouldda = { 1 => :one , 2 => :two , 3 => :three}
shouldda.each do |k,v|
@list.set(k,v)
end
shouldda
end
def test_many_get
shouldda = set_shouldda
shouldda.each do |k,v|
assert_equal v , @list.get(k)
end
end
def test_each
shouldda_values = set_shouldda.values
@list.each do |val|
shouldda_values.delete val
end
assert_equal 0 , shouldda_values.length
end
def test_each_index
set_shouldda
@list.each_with_index do |val , index|
assert_equal @list[index] , val
end
end
def test_each_pair_length
shouldda_values = set_shouldda.values
@list.each_pair do |key,val|
shouldda_values.delete key
shouldda_values.delete val
end
assert_equal 0 , shouldda_values.length
end
def test_each_pair_count
set_shouldda.values
counter = 0
@list.each_pair do |key,val|
counter += 1
end
assert_equal 2 , counter
end
def test_find
@list.set(1,1)
@list.set(2,2)
assert_equal 2, @list.find{|i| i == 2}
end
def test_not_find
@list.set(1,1)
assert_nil @list.find{|i| i == 3}
end
def test_delete_at
test_many_get
assert @list.delete_at 2
assert_equal 2 , @list.get_length
assert_equal 2 , @list.index_of( :three )
end end
assert_equal 2 , counter
end
def test_find
@list.set(1,1)
@list.set(2,2)
assert_equal 2, @list.find{|i| i == 2}
end
def test_not_find
@list.set(1,1)
assert_nil @list.find{|i| i == 3}
end
def test_delete_at
test_many_get
assert @list.delete_at 2
assert_equal 2 , @list.get_length
assert_equal 2 , @list.index_of( :three )
end
def test_delete def test_delete
test_many_get test_many_get
assert @list.delete :two assert @list.delete :two
assert_equal 2 , @list.get_length assert_equal 2 , @list.get_length
assert_equal 2 , @list.index_of( :three ) assert_equal 2 , @list.index_of( :three )
end end
def test_index_of def test_index_of
test_many_get test_many_get
assert_equal 2 , @list.index_of( :two ) assert_equal 2 , @list.index_of( :two )
assert_equal 3 , @list.index_of( :three ) assert_equal 3 , @list.index_of( :three )
assert_nil @list.index_of( :four ) assert_nil @list.index_of( :four )
end end
def test_inspect def test_inspect
test_many_get test_many_get
assert @list.inspect.include?("one") , @list.inspect assert @list.inspect.include?("one") , @list.inspect
assert @list.inspect.include?("three") , @list.inspect assert @list.inspect.include?("three") , @list.inspect
end end
def test_inlcude def test_inlcude
test_many_get test_many_get
assert_equal true , @list.include?( :two ) assert_equal true , @list.include?( :two )
assert_equal false , @list.include?( :four ) assert_equal false , @list.include?( :four )
end end
def test_empty_empty def test_empty_empty
assert_equal true , @list.empty? assert_equal true , @list.empty?
end end
def test_empty_notempty def test_empty_notempty
assert_equal 1 , @list.set(1,1) assert_equal 1 , @list.set(1,1)
assert_equal false , @list.empty? assert_equal false , @list.empty?
end end
def test_first def test_first
test_many_get test_many_get
assert_equal :one , @list.first assert_equal :one , @list.first
end end
def test_first_empty def test_first_empty
assert_nil @list.first assert_nil @list.first
end end
def test_last def test_last
test_many_get test_many_get
assert_equal :three , @list.last assert_equal :three , @list.last
end end
def test_last_empty def test_last_empty
assert_nil @list.last assert_nil @list.last
end
end end
end end

View File

@ -1,11 +1,10 @@
require_relative "../helper" require_relative "helper"
module Parfait module Parfait
class TestMessage < MiniTest::Test class TestMessage < ParfaitTest
def setup def setup
Risc.machine.boot super
@space = Parfait.object_space
@mess = @space.first_message @mess = @space.first_message
end end
def test_length def test_length

View File

@ -1,11 +1,10 @@
require_relative "../helper" require_relative "helper"
module Parfait module Parfait
class TestNamedLists < MiniTest::Test class TestNamedLists < ParfaitTest
def setup def setup
Risc.machine.boot super
@space = Parfait.object_space
@named_list = @space.first_message.frame @named_list = @space.first_message.frame
@type = @named_list.get_type @type = @named_list.get_type
end end

View File

@ -1,17 +1,20 @@
require_relative "../helper" require_relative "helper"
class TestObject < MiniTest::Test module Parfait
class TestObject < ParfaitTest
def setup
super
@object = ::Parfait::Object.new
end
def test_empty_object_doesnt_return
assert_nil @object.get_internal_word(3)
end
def test_one_set1
assert_equal @object.get_type , @object.set_internal_word(1, @object.get_type)
end
def setup
@object = ::Parfait::Object.new
end end
def test_empty_object_doesnt_return
assert_nil @object.get_internal_word(3)
end
def test_one_set1
assert_equal @object.get_type , @object.set_internal_word(1, @object.get_type)
end
end end

View File

@ -1,162 +1,159 @@
require_relative "../helper" require_relative "helper"
class TestSpace < MiniTest::Test module Parfait
class TestSpace < ParfaitTest
def setup def classes
@machine = Risc.machine.boot [:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer]
@space = Parfait.object_space
end
def classes
[:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer]
end
def test_booted
assert_equal true , @machine.booted
end
def test_space_length
assert_equal 8 , @space.get_type.instance_length , @space.get_type.inspect
end
def test_singletons
assert @space.true_object , "No truth"
assert @space.false_object , "No lies"
assert @space.nil_object , "No nothing"
end
def test_methods_booted
word = @space.get_class_by_name(:Word).instance_type
assert_equal 3 , word.method_names.get_length
assert word.get_method(:putstring) , "no putstring"
end
def test_global_space
assert_equal Parfait::Space , Parfait.object_space.class
end
def test_integer
int = Parfait.object_space.get_class_by_name :Integer
assert_equal 14, int.instance_type.method_names.get_length
end
def test_classes_class
classes.each do |name|
assert_equal :Class , @space.classes[name].get_class.name
assert_equal Parfait::Class , @space.classes[name].class
end end
end
def test_types def test_booted
assert @space.instance_variable_ged("@types").is_a? Parfait::Dictionary assert_equal true , @machine.booted
end
def test_types_each
@space.each_type do |type|
assert type.is_a?(Parfait::Type)
end end
end def test_space_length
assert_equal 8 , @space.get_type.instance_length , @space.get_type.inspect
def test_types_hashes
types = @space.instance_variable_ged("@types")
types.each do |has , type|
assert has.is_a?(Fixnum) , has.inspect
end end
end def test_singletons
assert @space.true_object , "No truth"
def test_classes_types_in_space_types assert @space.false_object , "No lies"
@space.classes do |name , clazz| assert @space.nil_object , "No nothing"
assert_equal clazz.instance_type , @space.get_type_for(clazz.instance_type.hash) , clazz.name
end end
end def test_methods_booted
word = @space.get_class_by_name(:Word).instance_type
def test_word_class assert_equal 3 , word.method_names.get_length
word = @space.classes[:Word] assert word.get_method(:putstring) , "no putstring"
assert word.instance_type
t_word = @space.get_type_for(word.instance_type.hash)
assert_equal word.instance_type.hash , t_word.hash
assert_equal word.instance_type.object_id , t_word.object_id
end
def test_classes_type
classes.each do |name|
assert_equal Parfait::Type , @space.classes[name].get_type.class
end end
end
def test_classes_name def test_global_space
classes.each do |name| assert_equal Parfait::Space , Parfait.object_space.class
assert_equal name , @space.classes[name].name
end end
end
def test_method_name def test_integer
classes.each do |name| int = Parfait.object_space.get_class_by_name :Integer
cl = @space.classes[name] assert_equal 14, int.instance_type.method_names.get_length
cl.method_names.each do |mname| end
method = cl.get_instance_method(mname)
assert_equal mname , method.name def test_classes_class
assert_equal name , method.for_class.name classes.each do |name|
assert_equal :Class , @space.classes[name].get_class.name
assert_equal Parfait::Class , @space.classes[name].class
end end
end end
end
def test_messages def test_types
mess = @space.first_message assert @space.instance_variable_ged("@types").is_a? Parfait::Dictionary
all = []
while mess
all << mess
assert mess.frame
mess = mess.next_message
end end
assert_equal all.length , all.uniq.length
# there is a 5.times in space, but one Message gets created before
assert_equal 50 + 1 , all.length
end
def test_message_vars
mess = @space.first_message
all = mess.get_instance_variables
assert all
assert all.include?(:next_message)
end
def test_create_class def test_types_each
assert @space.create_class( :NewClass ) @space.each_type do |type|
end assert type.is_a?(Parfait::Type)
def test_created_class_is_stored
@space.create_class( :NewerClass )
assert @space.get_class_by_name(:NewerClass)
end
def test_class_types_are_stored
@space.classes.each do |name,clazz|
assert @space.get_type_for(clazz.instance_type.hash)
end
end
def test_class_types_are_identical
@space.classes.each do |name , clazz|
cl_type = @space.get_type_for(clazz.instance_type.hash)
assert_equal cl_type.object_id , clazz.instance_type.object_id
end
end
def test_remove_methods
@space.each_type do | type |
type.method_names.each do |method|
type.remove_method(method)
end end
end end
assert_equal 0 , @space.collect_methods.length
end
def test_no_methods_in_types
test_remove_methods
@space.each_type do |type|
assert_equal 0 , type.methods_length , "name #{type.name}"
end
end
def test_no_methods_in_classes
test_remove_methods
@space.classes.each do |name , cl|
assert_equal 0 , cl.instance_type.methods_length , "name #{cl.name}"
end
end
def test_types_hashes
types = @space.instance_variable_ged("@types")
types.each do |has , type|
assert has.is_a?(Fixnum) , has.inspect
end
end
def test_classes_types_in_space_types
@space.classes do |name , clazz|
assert_equal clazz.instance_type , @space.get_type_for(clazz.instance_type.hash) , clazz.name
end
end
def test_word_class
word = @space.classes[:Word]
assert word.instance_type
t_word = @space.get_type_for(word.instance_type.hash)
assert_equal word.instance_type.hash , t_word.hash
assert_equal word.instance_type.object_id , t_word.object_id
end
def test_classes_type
classes.each do |name|
assert_equal Parfait::Type , @space.classes[name].get_type.class
end
end
def test_classes_name
classes.each do |name|
assert_equal name , @space.classes[name].name
end
end
def test_method_name
classes.each do |name|
cl = @space.classes[name]
cl.method_names.each do |mname|
method = cl.get_instance_method(mname)
assert_equal mname , method.name
assert_equal name , method.for_class.name
end
end
end
def test_messages
mess = @space.first_message
all = []
while mess
all << mess
assert mess.frame
mess = mess.next_message
end
assert_equal all.length , all.uniq.length
# there is a 5.times in space, but one Message gets created before
assert_equal 50 + 1 , all.length
end
def test_message_vars
mess = @space.first_message
all = mess.get_instance_variables
assert all
assert all.include?(:next_message)
end
def test_create_class
assert @space.create_class( :NewClass )
end
def test_created_class_is_stored
@space.create_class( :NewerClass )
assert @space.get_class_by_name(:NewerClass)
end
def test_class_types_are_stored
@space.classes.each do |name,clazz|
assert @space.get_type_for(clazz.instance_type.hash)
end
end
def test_class_types_are_identical
@space.classes.each do |name , clazz|
cl_type = @space.get_type_for(clazz.instance_type.hash)
assert_equal cl_type.object_id , clazz.instance_type.object_id
end
end
def test_remove_methods
@space.each_type do | type |
type.method_names.each do |method|
type.remove_method(method)
end
end
assert_equal 0 , @space.collect_methods.length
end
def test_no_methods_in_types
test_remove_methods
@space.each_type do |type|
assert_equal 0 , type.methods_length , "name #{type.name}"
end
end
def test_no_methods_in_classes
test_remove_methods
@space.classes.each do |name , cl|
assert_equal 0 , cl.instance_type.methods_length , "name #{cl.name}"
end
end
end
end end

View File

@ -1,97 +1,99 @@
require_relative "../helper" require_relative "helper"
class TestMethod < MiniTest::Test module Parfait
class TestMethod < ParfaitTest
def setup def setup
Risc.machine.boot super
obj = Parfait.object_space.get_class_by_name(:Object).instance_type obj = Parfait.object_space.get_class_by_name(:Object).instance_type
args = Parfait::Type.for_hash( obj.object_class , { bar: :Integer , foo: :Type}) args = Parfait::Type.for_hash( obj.object_class , { bar: :Integer , foo: :Type})
frame = Parfait::Type.for_hash( obj.object_class , { local_bar: :Integer , local_foo: :Type}) frame = Parfait::Type.for_hash( obj.object_class , { local_bar: :Integer , local_foo: :Type})
@method = Parfait::TypedMethod.new( obj , :meth , args , frame) @method = Parfait::TypedMethod.new( obj , :meth , args , frame)
end end
def test_method_name def test_method_name
assert_equal :meth , @method.name assert_equal :meth , @method.name
end end
def test_class_for def test_class_for
assert_equal :Object , @method.for_type.object_class.name assert_equal :Object , @method.for_type.object_class.name
end end
def test_arg1 def test_arg1
assert_equal 2 , @method.arguments_length , @method.arguments_type.inspect assert_equal 2 , @method.arguments_length , @method.arguments_type.inspect
assert_equal Symbol , @method.arguments_type.names.first.class assert_equal Symbol , @method.arguments_type.names.first.class
assert_equal :bar , @method.argument_name(1) assert_equal :bar , @method.argument_name(1)
end end
def test_has_argument def test_has_argument
assert_equal 1 , @method.has_argument(:bar) assert_equal 1 , @method.has_argument(:bar)
assert_equal 2 , @method.has_argument(:foo) assert_equal 2 , @method.has_argument(:foo)
end end
def test_add_arg def test_add_arg
@method.add_argument(:foo2 , :Object) @method.add_argument(:foo2 , :Object)
assert_equal 3 , @method.arguments_length assert_equal 3 , @method.arguments_length
assert_equal :foo2 , @method.argument_name(3) assert_equal :foo2 , @method.argument_name(3)
assert_equal :Object , @method.argument_type(3) assert_equal :Object , @method.argument_type(3)
end end
def test_get_arg_name1 def test_get_arg_name1
index = @method.has_argument(:bar) index = @method.has_argument(:bar)
assert_equal 1 , index assert_equal 1 , index
assert_equal :bar , @method.argument_name(index) assert_equal :bar , @method.argument_name(index)
end end
def test_get_arg_type1 def test_get_arg_type1
index = @method.has_argument(:bar) index = @method.has_argument(:bar)
assert_equal :Integer , @method.argument_type(index) assert_equal :Integer , @method.argument_type(index)
end end
def test_get_arg_name2 def test_get_arg_name2
index = @method.has_argument(:foo) index = @method.has_argument(:foo)
assert_equal 2 , index assert_equal 2 , index
assert_equal :foo , @method.argument_name(index) assert_equal :foo , @method.argument_name(index)
end end
def test_get_arg_type2 def test_get_arg_type2
index = @method.has_argument(:foo) index = @method.has_argument(:foo)
assert_equal :Type , @method.argument_type(index) assert_equal :Type , @method.argument_type(index)
end end
def test_local1 def test_local1
assert_equal 2 , @method.frame_length , @method.frame_type.inspect assert_equal 2 , @method.frame_length , @method.frame_type.inspect
assert_equal Symbol , @method.frame_type.names.first.class assert_equal Symbol , @method.frame_type.names.first.class
assert_equal :local_bar , @method.locals_name(1) assert_equal :local_bar , @method.locals_name(1)
end end
def test_has_local def test_has_local
assert_equal 1 , @method.has_local(:local_bar) assert_equal 1 , @method.has_local(:local_bar)
assert_equal 2 , @method.has_local(:local_foo) assert_equal 2 , @method.has_local(:local_foo)
end end
def test_add_local def test_add_local
@method.add_local(:foo2 , :Object) @method.add_local(:foo2 , :Object)
assert_equal 3 , @method.frame_length assert_equal 3 , @method.frame_length
assert_equal :foo2 , @method.locals_name(3) assert_equal :foo2 , @method.locals_name(3)
assert_equal :Object , @method.locals_type(3) assert_equal :Object , @method.locals_type(3)
end end
def test_get_locals_name1 def test_get_locals_name1
index = @method.has_local(:local_bar) index = @method.has_local(:local_bar)
assert_equal 1 , index assert_equal 1 , index
assert_equal :local_bar , @method.locals_name(index) assert_equal :local_bar , @method.locals_name(index)
end end
def test_get_frame_type1 def test_get_frame_type1
index = @method.has_local(:local_bar) index = @method.has_local(:local_bar)
assert_equal :Integer , @method.locals_type(index) assert_equal :Integer , @method.locals_type(index)
end end
def test_get_locals_name2 def test_get_locals_name2
index = @method.has_local(:local_foo) index = @method.has_local(:local_foo)
assert_equal 2 , index assert_equal 2 , index
assert_equal :local_foo , @method.locals_name(index) assert_equal :local_foo , @method.locals_name(index)
end end
def test_get_frame_type2 def test_get_frame_type2
index = @method.has_local(:local_bar) index = @method.has_local(:local_bar)
assert_equal :Integer , @method.locals_type(index) assert_equal :Integer , @method.locals_type(index)
end end
def test_created_with_binary def test_created_with_binary
assert @method.binary assert @method.binary
end
end end
end end

View File

@ -1,113 +1,114 @@
require_relative "../helper" require_relative "helper"
module Parfait module Parfait
class TestEmptyWord < MiniTest::Test class TestEmptyWord < ParfaitTest
def setup def setup
Risc.machine.boot Risc.machine.boot
@word = Parfait::Word.new(0) @word = Parfait::Word.new(0)
end end
def test_word_create def test_word_create
assert @word.empty? assert @word.empty?
end end
def test_empty_is_zero def test_empty_is_zero
assert_equal 0 , @word.length assert_equal 0 , @word.length
end end
def test_empty_is_zero_internal def test_empty_is_zero_internal
assert_equal 0 , @word.char_length assert_equal 0 , @word.char_length
end end
def test_index_check_get def test_index_check_get
assert_raises RuntimeError do assert_raises RuntimeError do
@word.get_char(0) @word.get_char(0)
end
end
def test_index_check_set
assert_raises RuntimeError do
@word.set_char(1 , 32)
end
end end
end end
def test_index_check_set
assert_raises RuntimeError do class TestWord < ParfaitTest
def setup
super
@word = Parfait::Word.new(5)
end
def test_len
assert_equal 5 , @word.length
end
def test_len_internal
assert_equal 5 , @word.char_length
end
def test_first_char
assert_equal 32 , @word.get_char(1)
end
def test_equals_copy
assert_equal @word.copy , @word
end
def test_equals_copy2
@word.set_char(1 , 2)
@word.set_char(5 , 6)
assert_equal @word.copy , @word
end
def test_equals_same
assert_equal ::Parfait::Word.new(5) , @word
end
def test_index_check_get
assert_raises RuntimeError do
@word.get_char(-6)
end
end
def test_index_check_set
assert_raises RuntimeError do
@word.set_char(6 , 32)
end
end
def test_index_check_get
assert_raises RuntimeError do
@word.get_char(6)
end
end
def test_index_check_set
assert_raises RuntimeError do
@word.set_char(-6 , 32)
end
end
def test_one_char
assert_equal 32 , @word.set_char(1 , 32)
end
def test_one_char_doesnt_cause_problems
@word.set_char(1 , 32) @word.set_char(1 , 32)
assert_equal 32 , @word.get_char(1)
end
def test_one_set1
assert_equal 44 , @word.set_char(1, 44 )
end
def test_two_sets
assert_equal 1 , @word.set_char(1,1)
assert_equal 44 , @word.set_char(1,44)
end
def test_one_get1
test_one_set1
assert_equal 44 , @word.get_char(1)
end
def test_many_get
shouldda = { 1 => 11 , 2 => 22 , 3 => 33}
shouldda.each do |k,v|
@word.set_char(k,v)
end
shouldda.each do |k,v|
assert_equal v , @word.get_char(k)
end
end
def test_not_same
one = Parfait.new_word("one")
two = Parfait.new_word("two")
assert !one.compare(two)
end
def test_is_same
one = Parfait.new_word("one")
two = Parfait.new_word("one")
assert one.compare(two)
end end
end end
end end
class TestWord < MiniTest::Test
def setup
Risc.machine.boot
@word = Parfait::Word.new(5)
end
def test_len
assert_equal 5 , @word.length
end
def test_len_internal
assert_equal 5 , @word.char_length
end
def test_first_char
assert_equal 32 , @word.get_char(1)
end
def test_equals_copy
assert_equal @word.copy , @word
end
def test_equals_copy2
@word.set_char(1 , 2)
@word.set_char(5 , 6)
assert_equal @word.copy , @word
end
def test_equals_same
assert_equal ::Parfait::Word.new(5) , @word
end
def test_index_check_get
assert_raises RuntimeError do
@word.get_char(-6)
end
end
def test_index_check_set
assert_raises RuntimeError do
@word.set_char(6 , 32)
end
end
def test_index_check_get
assert_raises RuntimeError do
@word.get_char(6)
end
end
def test_index_check_set
assert_raises RuntimeError do
@word.set_char(-6 , 32)
end
end
def test_one_char
assert_equal 32 , @word.set_char(1 , 32)
end
def test_one_char_doesnt_cause_problems
@word.set_char(1 , 32)
assert_equal 32 , @word.get_char(1)
end
def test_one_set1
assert_equal 44 , @word.set_char(1, 44 )
end
def test_two_sets
assert_equal 1 , @word.set_char(1,1)
assert_equal 44 , @word.set_char(1,44)
end
def test_one_get1
test_one_set1
assert_equal 44 , @word.get_char(1)
end
def test_many_get
shouldda = { 1 => 11 , 2 => 22 , 3 => 33}
shouldda.each do |k,v|
@word.set_char(k,v)
end
shouldda.each do |k,v|
assert_equal v , @word.get_char(k)
end
end
def test_not_same
one = Parfait.new_word("one")
two = Parfait.new_word("two")
assert !one.compare(two)
end
def test_is_same
one = Parfait.new_word("one")
two = Parfait.new_word("one")
assert one.compare(two)
end
end
end

View File

@ -1,75 +1,76 @@
require_relative "../../helper" require_relative "../helper"
class BasicType < MiniTest::Test module Parfait
class BasicType < ParfaitTest
def setup def setup
Risc.machine.boot super
@space = Parfait.object_space @mess = @space.first_message
@mess = @space.first_message assert @mess
assert @mess @type = @mess.get_type()
@type = @mess.get_type() end
end
def test_type_index def test_type_index
assert_equal @mess.get_type , @mess.get_internal_word(Parfait::TYPE_INDEX) , "mess" assert_equal @mess.get_type , @mess.get_internal_word(Parfait::TYPE_INDEX) , "mess"
end end
def test_type_is_first def test_type_is_first
type = @mess.get_type type = @mess.get_type
assert_equal 1 , type.variable_index(:type) assert_equal 1 , type.variable_index(:type)
end end
def test_length def test_length
assert @mess assert @mess
assert @mess.get_type assert @mess.get_type
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
end end
def test_names def test_names
assert @type.names assert @type.names
end end
def test_types def test_types
assert @type.types assert @type.types
end end
def test_type_length def test_type_length
assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect assert_equal 9 , @mess.get_type.instance_length , @mess.get_type.inspect
end end
def test_type_length_index def test_type_length_index
type = @mess.get_type.get_type type = @mess.get_type.get_type
assert_equal 5 , type.variable_index(:methods) assert_equal 5 , type.variable_index(:methods)
assert_equal type.object_class , type.get_internal_word(4) assert_equal type.object_class , type.get_internal_word(4)
end end
def test_no_index_below_1 def test_no_index_below_1
type = @mess.get_type type = @mess.get_type
names = type.names names = type.names
assert_equal 9 , names.get_length , names.inspect assert_equal 9 , names.get_length , names.inspect
names.each do |n| names.each do |n|
assert type.variable_index(n) >= 1 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
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 end

View File

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

View File

@ -1,82 +1,83 @@
require_relative "../../helper" require_relative "../helper"
class TestMethodApi < MiniTest::Test module Parfait
class TestMethodApi < ParfaitTest
def setup def setup
Risc.machine.boot super
@space = Parfait.object_space @try_class = @space.create_class( :Try )
@try_class = @space.create_class( :Try ) @try_type = @try_class.instance_type
@try_type = @try_class.instance_type end
end
def empty_frame def empty_frame
Parfait::Type.for_hash( @try_class , { }) Parfait::Type.for_hash( @try_class , { })
end end
def foo_method( for_class = :Try) def foo_method( for_class = :Try)
args = Parfait::Type.for_hash( @try_class , { bar: :Integer}) 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) ::Parfait::TypedMethod.new( @space.get_class_by_name(for_class).instance_type , :foo , args,empty_frame)
end end
def add_foo_to( clazz = :Try ) def add_foo_to( clazz = :Try )
foo = foo_method( clazz ) foo = foo_method( clazz )
assert_equal foo , @space.get_class_by_name(clazz).instance_type.add_method(foo) assert_equal foo , @space.get_class_by_name(clazz).instance_type.add_method(foo)
foo foo
end end
def object_type def object_type
@space.get_class_by_name(:Object).instance_type @space.get_class_by_name(:Object).instance_type
end end
def test_new_methods def test_new_methods
assert_equal Parfait::List , @try_type.method_names.class assert_equal Parfait::List , @try_type.method_names.class
assert_equal @try_type.method_names.get_length , @try_type.methods_length assert_equal @try_type.method_names.get_length , @try_type.methods_length
end end
def test_add_method def test_add_method
before = @try_type.methods_length before = @try_type.methods_length
add_foo_to add_foo_to
assert_equal 1 , @try_type.methods_length - before assert_equal 1 , @try_type.methods_length - before
assert @try_type.method_names.inspect.include?(":foo") assert @try_type.method_names.inspect.include?(":foo")
end end
def test_remove_method def test_remove_method
add_foo_to add_foo_to
assert @try_type.remove_method(:foo) assert @try_type.remove_method(:foo)
end end
def test_remove_not_there def test_remove_not_there
assert_raises RuntimeError do assert_raises RuntimeError do
@try_type.remove_method(:foo) @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
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 end

View File

@ -1,93 +1,94 @@
require_relative "../../helper" require_relative "../helper"
class TypeApi < MiniTest::Test module Parfait
class TypeApi < ParfaitTest
def setup def setup
Risc.machine.boot super
@space = Parfait.object_space tc = @space.get_class_by_name( :NamedList )
tc = @space.get_class_by_name( :NamedList ) @type = tc.instance_type
@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)
end end
assert counter.empty? , counter.inspect
end
def test_each_type def test_inspect
type = test_add_name assert @type.inspect.start_with?("Type")
assert_equal 2 , type.get_length
counter = [ :Object , :Type]
type.types.each do |item|
assert_equal item , counter.delete(item)
end 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 end