2018-04-26 11:31:37 +02:00
|
|
|
require_relative "helper"
|
2015-07-02 10:09:23 +02:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
module Parfait
|
|
|
|
class TestSpace < ParfaitTest
|
2015-07-02 10:09:23 +02:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def classes
|
2019-09-21 17:50:33 +02:00
|
|
|
[:Behaviour ,:BinaryCode,:Block,:CacheEntry,:Callable,:CallableMethod,:Class,
|
2019-08-22 16:54:17 +02:00
|
|
|
:DataObject,:Data4,:Data8,:Data16,:Data32,:Dictionary,:Factory, :Integer,:FalseClass,
|
2019-09-23 19:57:33 +02:00
|
|
|
:List,:Message, :SingletonClass,:NilClass,:Object,:ReturnAddress,
|
2018-07-07 08:11:09 +02:00
|
|
|
:Space,:TrueClass,:Type,:VoolMethod,:Word]
|
2018-04-26 11:31:37 +02:00
|
|
|
end
|
2017-01-15 19:04:52 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_space_length
|
2018-09-01 10:24:16 +02:00
|
|
|
assert_equal 7 , @space.get_type.instance_length , @space.get_type.inspect
|
2018-04-26 11:31:37 +02:00
|
|
|
end
|
|
|
|
def test_singletons
|
|
|
|
assert @space.true_object , "No truth"
|
|
|
|
assert @space.false_object , "No lies"
|
|
|
|
assert @space.nil_object , "No nothing"
|
|
|
|
end
|
2019-02-17 13:37:50 +01:00
|
|
|
def space_class
|
|
|
|
Parfait.object_space.get_class_by_name(:Space)
|
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_global_space
|
|
|
|
assert_equal Parfait::Space , Parfait.object_space.class
|
|
|
|
end
|
2018-07-13 20:55:27 +02:00
|
|
|
def test_get_class_by_name
|
2019-02-17 13:37:50 +01:00
|
|
|
assert_equal Parfait::Class , space_class.class
|
|
|
|
end
|
2019-09-23 19:57:33 +02:00
|
|
|
def test_get_singleton_class
|
2019-09-24 16:25:19 +02:00
|
|
|
assert_equal Parfait::SingletonClass , space_class.single_class.class
|
2018-07-13 20:55:27 +02:00
|
|
|
end
|
|
|
|
def test_get_type_by_class_name
|
|
|
|
assert_equal Parfait::Type , Parfait.object_space.get_type_by_class_name(:Space).class
|
|
|
|
end
|
2018-07-15 11:32:02 +02:00
|
|
|
def test_get_type_by_class_name_nil
|
|
|
|
assert_nil Parfait.object_space.get_type_by_class_name(:Spac)
|
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
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
|
2015-07-28 15:19:10 +02:00
|
|
|
end
|
2018-07-01 12:43:53 +02:00
|
|
|
def test_all_classes
|
|
|
|
assert_equal classes.length , @space.classes.length , @space.classes.keys.inspect
|
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_word_class
|
|
|
|
word = @space.classes[:Word]
|
|
|
|
assert word.instance_type
|
2019-09-22 18:10:47 +02:00
|
|
|
t_word = @space.types[word.instance_type.hash]
|
2018-04-26 11:31:37 +02:00
|
|
|
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
|
2015-07-02 10:09:23 +02:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_classes_name
|
|
|
|
classes.each do |name|
|
|
|
|
assert_equal name , @space.classes[name].name
|
|
|
|
end
|
2015-07-28 15:19:10 +02:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
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
|
2015-07-28 15:19:10 +02:00
|
|
|
end
|
|
|
|
end
|
2019-09-23 19:57:33 +02:00
|
|
|
def test_all_singletons
|
2019-02-17 13:37:50 +01:00
|
|
|
@space.classes.each do |name , clazz|
|
2019-09-24 16:25:19 +02:00
|
|
|
assert clazz.single_class , clazz.name
|
2019-02-17 13:37:50 +01:00
|
|
|
end
|
|
|
|
end
|
2018-08-24 17:49:21 +02:00
|
|
|
def test_has_factory
|
|
|
|
assert_equal Dictionary , @space.factories.class
|
|
|
|
end
|
|
|
|
def test_factory_length
|
2018-09-01 10:24:16 +02:00
|
|
|
assert_equal 3 , @space.factories.length
|
2018-08-24 17:49:21 +02:00
|
|
|
end
|
|
|
|
def test_has_integer_factory
|
|
|
|
ints = @space.get_factory_for(:Integer)
|
|
|
|
assert_equal Factory , ints.class
|
|
|
|
assert_equal :Integer , ints.for_type.class_name
|
|
|
|
end
|
2018-07-01 12:43:53 +02:00
|
|
|
def test_has_integers
|
2018-08-24 17:49:21 +02:00
|
|
|
nekst = @space.get_next_for(:Integer)
|
|
|
|
assert_equal Parfait::Integer , nekst.class
|
|
|
|
assert_nil nekst.value
|
2018-07-01 12:43:53 +02:00
|
|
|
end
|
|
|
|
def test_has_next_integer
|
2018-08-24 17:49:21 +02:00
|
|
|
nekst = @space.get_next_for(:Integer)
|
|
|
|
nekst = @space.get_next_for(:Integer)
|
|
|
|
assert_equal Parfait::Integer , nekst.class
|
2018-07-01 12:43:53 +02:00
|
|
|
end
|
|
|
|
def test_has_addresses
|
2018-08-29 20:02:49 +02:00
|
|
|
ret = @space.get_next_for(:ReturnAddress)
|
|
|
|
assert_equal Parfait::ReturnAddress , ret.class
|
|
|
|
assert_nil ret.value
|
2018-07-01 12:43:53 +02:00
|
|
|
end
|
|
|
|
def test_has_next_address
|
2018-08-29 20:02:49 +02:00
|
|
|
assert_equal Parfait::ReturnAddress , @space.get_next_for(:ReturnAddress).class
|
2018-07-01 12:43:53 +02:00
|
|
|
end
|
2018-09-01 10:24:16 +02:00
|
|
|
def test_has_message_factory
|
|
|
|
ints = @space.get_factory_for(:Message)
|
|
|
|
assert_equal Factory , ints.class
|
|
|
|
assert_equal :Message , ints.for_type.class_name
|
|
|
|
end
|
|
|
|
def test_has_messages
|
|
|
|
nekst = @space.get_next_for(:Message)
|
|
|
|
assert_equal Parfait::Message , nekst.class
|
|
|
|
end
|
|
|
|
def test_has_next_message
|
|
|
|
assert_equal Parfait::Message , @space.get_next_for(:Message).class
|
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_create_class
|
|
|
|
assert @space.create_class( :NewClass )
|
|
|
|
end
|
2016-12-29 17:51:24 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_created_class_is_stored
|
2019-09-18 21:07:05 +02:00
|
|
|
clazz = @space.create_class( :NewerClass )
|
2018-04-26 11:31:37 +02:00
|
|
|
assert @space.get_class_by_name(:NewerClass)
|
|
|
|
end
|
2016-12-29 17:51:24 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
end
|
2019-02-09 11:44:35 +01:00
|
|
|
class BigTestSpace < BigParfaitTest
|
|
|
|
def test_address_count
|
|
|
|
addr = @space.get_next_for(:ReturnAddress)
|
|
|
|
count = 0
|
|
|
|
while(addr)
|
|
|
|
count += 1
|
|
|
|
addr = addr.next_integer
|
|
|
|
end
|
2019-08-24 08:46:33 +02:00
|
|
|
assert_equal 1009, count
|
2019-02-09 11:44:35 +01:00
|
|
|
end
|
|
|
|
def test_message_count
|
|
|
|
mess = @space.get_next_for(:Message)
|
|
|
|
count = 0
|
|
|
|
while(mess)
|
|
|
|
count += 1
|
2019-08-23 09:21:22 +02:00
|
|
|
assert mess.locals_used
|
2019-02-09 11:44:35 +01:00
|
|
|
mess = mess.next_message
|
|
|
|
end
|
2019-08-24 08:46:33 +02:00
|
|
|
assert_equal 285, count
|
2019-02-09 11:44:35 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-02 10:09:23 +02:00
|
|
|
end
|