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
|
2018-07-07 14:50:43 +02:00
|
|
|
[:BinaryCode,:Block,:CacheEntry,:Callable,:CallableMethod,:Class,
|
2018-07-07 08:11:09 +02:00
|
|
|
:DataObject,:Data4,:Data8,:Data16,:Dictionary,:Integer,:FalseClass,
|
|
|
|
:List,:Message,:NamedList,:NilClass,:Object,:ReturnAddress,
|
|
|
|
: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-07-02 14:49:51 +02:00
|
|
|
assert_equal 12 , @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
|
|
|
|
def test_global_space
|
|
|
|
assert_equal Parfait::Space , Parfait.object_space.class
|
|
|
|
end
|
2016-12-30 19:47:28 +01:00
|
|
|
|
2018-07-13 20:55:27 +02:00
|
|
|
def test_get_class_by_name
|
|
|
|
assert_equal Parfait::Class , Parfait.object_space.get_class_by_name(:Space).class
|
|
|
|
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-05-29 16:03:55 +02:00
|
|
|
def test_get_integer_instance
|
|
|
|
int = @space.get_integer
|
|
|
|
assert_equal Integer , int.class
|
|
|
|
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_types
|
|
|
|
assert @space.instance_variable_ged("@types").is_a? Parfait::Dictionary
|
|
|
|
end
|
2018-05-13 12:03:04 +02:00
|
|
|
def test_types_attr
|
|
|
|
assert @space.types.is_a? Parfait::Dictionary
|
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_types_each
|
|
|
|
@space.each_type do |type|
|
|
|
|
assert type.is_a?(Parfait::Type)
|
|
|
|
end
|
2016-12-30 13:04:59 +01:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_types_hashes
|
|
|
|
types = @space.instance_variable_ged("@types")
|
|
|
|
types.each do |has , type|
|
|
|
|
assert has.is_a?(Fixnum) , has.inspect
|
|
|
|
end
|
2016-12-30 19:47:28 +01:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
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
|
2016-12-31 13:51:06 +01:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
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
|
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
|
2018-07-01 12:43:53 +02:00
|
|
|
def test_has_integers
|
|
|
|
assert_equal Parfait::Integer , @space.next_integer.class
|
|
|
|
assert_equal 0 , @space.next_integer.value
|
|
|
|
end
|
|
|
|
def test_has_next_integer
|
|
|
|
assert_equal Parfait::Integer , @space.next_integer.next_integer.class
|
|
|
|
end
|
|
|
|
def test_has_addresses
|
|
|
|
assert_equal Parfait::ReturnAddress , @space.next_address.class
|
|
|
|
assert_equal 0 , @space.next_address.value
|
|
|
|
end
|
|
|
|
def test_has_next_address
|
|
|
|
assert_equal Parfait::ReturnAddress , @space.next_address.next_integer.class
|
|
|
|
end
|
2018-07-01 13:12:42 +02:00
|
|
|
def test_address_count
|
2018-07-02 14:49:51 +02:00
|
|
|
addr = @space.addresses
|
2018-07-01 13:12:42 +02:00
|
|
|
count = 0
|
|
|
|
while(addr)
|
|
|
|
count += 1
|
|
|
|
addr = addr.next_integer
|
|
|
|
end
|
2018-08-02 16:37:27 +02:00
|
|
|
assert_equal 400, count
|
2018-07-01 13:12:42 +02:00
|
|
|
end
|
2018-07-01 12:43:53 +02:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_messages
|
2018-07-02 14:49:51 +02:00
|
|
|
mess = @space.messages
|
2018-04-26 11:31:37 +02:00
|
|
|
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
|
2018-07-02 14:49:51 +02:00
|
|
|
mess = @space.next_message
|
2018-04-26 11:31:37 +02:00
|
|
|
all = mess.get_instance_variables
|
|
|
|
assert all
|
|
|
|
assert all.include?(:next_message)
|
|
|
|
end
|
|
|
|
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
|
|
|
|
@space.create_class( :NewerClass )
|
|
|
|
assert @space.get_class_by_name(:NewerClass)
|
|
|
|
end
|
2016-12-29 17:51:24 +01:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_class_types_are_stored
|
|
|
|
@space.classes.each do |name,clazz|
|
|
|
|
assert @space.get_type_for(clazz.instance_type.hash)
|
|
|
|
end
|
2016-12-31 13:51:06 +01:00
|
|
|
end
|
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
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
|
2016-12-31 13:51:06 +01:00
|
|
|
end
|
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_remove_methods
|
|
|
|
@space.each_type do | type |
|
|
|
|
type.method_names.each do |method|
|
|
|
|
type.remove_method(method)
|
|
|
|
end
|
2016-12-31 13:51:06 +01:00
|
|
|
end
|
2018-05-01 18:19:37 +02:00
|
|
|
assert_equal 0 , @space.get_all_methods.length
|
2016-12-31 13:51:06 +01:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_no_methods_in_types
|
|
|
|
test_remove_methods
|
|
|
|
@space.each_type do |type|
|
|
|
|
assert_equal 0 , type.methods_length , "name #{type.name}"
|
|
|
|
end
|
2016-12-31 13:51:06 +01:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
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
|
2016-12-31 13:51:06 +01:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
end
|
2018-07-24 10:35:49 +02:00
|
|
|
class TestMethods < ParfaitTest
|
2018-06-29 23:39:23 +02:00
|
|
|
def setup
|
|
|
|
super
|
|
|
|
Risc::Builtin.boot_functions
|
|
|
|
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_methods_booted
|
2018-07-13 20:55:27 +02:00
|
|
|
word = @space.get_type_by_class_name(:Word)
|
2018-06-29 23:39:23 +02:00
|
|
|
assert_equal 3 , word.method_names.get_length
|
|
|
|
assert word.get_method(:putstring) , "no putstring"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-02 10:09:23 +02:00
|
|
|
end
|