2015-07-02 10:09:23 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
class TestSpace < MiniTest::Test
|
|
|
|
|
|
|
|
def setup
|
2017-01-19 08:02:29 +01:00
|
|
|
@machine = Risc.machine.boot
|
2016-12-30 13:10:49 +01:00
|
|
|
@space = Parfait.object_space
|
2015-07-02 10:09:23 +02:00
|
|
|
end
|
2016-12-30 19:47:28 +01:00
|
|
|
|
2015-07-28 15:19:10 +02:00
|
|
|
def classes
|
2018-04-02 16:06:31 +02:00
|
|
|
[:Word,:List,:Message,:NamedList,:Type,:Object,:Class,:Dictionary,:TypedMethod , :Integer]
|
2015-07-28 15:19:10 +02:00
|
|
|
end
|
2017-01-15 19:04:52 +01:00
|
|
|
|
2015-07-02 10:09:23 +02:00
|
|
|
def test_booted
|
|
|
|
assert_equal true , @machine.booted
|
|
|
|
end
|
2018-03-31 12:47:02 +02:00
|
|
|
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
|
2017-01-15 19:04:52 +01:00
|
|
|
def test_methods_booted
|
|
|
|
word = @space.get_class_by_name(:Word).instance_type
|
2018-04-08 17:55:17 +02:00
|
|
|
assert_equal 3 , word.method_names.get_length
|
2017-01-15 19:04:52 +01:00
|
|
|
assert word.get_method(:putstring) , "no putstring"
|
|
|
|
end
|
|
|
|
|
2015-07-02 12:49:33 +02:00
|
|
|
def test_global_space
|
2016-12-30 13:10:49 +01:00
|
|
|
assert_equal Parfait::Space , Parfait.object_space.class
|
2015-07-02 10:09:23 +02:00
|
|
|
end
|
2016-12-30 19:47:28 +01:00
|
|
|
|
2015-10-13 13:46:07 +02:00
|
|
|
def test_integer
|
2016-12-30 13:10:49 +01:00
|
|
|
int = Parfait.object_space.get_class_by_name :Integer
|
2018-04-19 21:57:31 +02:00
|
|
|
assert_equal 12, int.instance_type.method_names.get_length
|
2015-08-06 17:26:59 +02:00
|
|
|
end
|
2015-10-13 13:46:07 +02:00
|
|
|
|
2015-07-28 15:19:10 +02:00
|
|
|
def test_classes_class
|
|
|
|
classes.each do |name|
|
2016-12-30 13:04:59 +01:00
|
|
|
assert_equal :Class , @space.classes[name].get_class.name
|
|
|
|
assert_equal Parfait::Class , @space.classes[name].class
|
2015-07-28 15:19:10 +02:00
|
|
|
end
|
|
|
|
end
|
2015-10-13 13:46:07 +02:00
|
|
|
|
2016-12-07 22:34:45 +01:00
|
|
|
def test_types
|
2018-04-03 18:33:36 +02:00
|
|
|
assert @space.instance_variable_ged("@types").is_a? Parfait::Dictionary
|
2016-12-30 13:04:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_types_each
|
|
|
|
@space.each_type do |type|
|
|
|
|
assert type.is_a?(Parfait::Type)
|
|
|
|
end
|
2016-12-07 22:34:45 +01:00
|
|
|
end
|
2016-12-14 12:25:06 +01:00
|
|
|
|
2016-12-30 19:47:28 +01:00
|
|
|
def test_types_hashes
|
2018-04-03 18:33:36 +02:00
|
|
|
types = @space.instance_variable_ged("@types")
|
2016-12-30 19:47:28 +01:00
|
|
|
types.each do |has , type|
|
|
|
|
assert has.is_a?(Fixnum) , has.inspect
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-31 13:51:06 +01: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
|
|
|
|
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
|
|
|
|
|
2016-02-25 20:50:10 +01:00
|
|
|
def test_classes_type
|
2015-07-28 15:19:10 +02:00
|
|
|
classes.each do |name|
|
2016-12-30 13:04:59 +01:00
|
|
|
assert_equal Parfait::Type , @space.classes[name].get_type.class
|
2015-07-02 10:09:23 +02:00
|
|
|
end
|
|
|
|
end
|
2015-10-13 13:46:07 +02:00
|
|
|
|
2015-07-28 15:19:10 +02:00
|
|
|
def test_classes_name
|
|
|
|
classes.each do |name|
|
2016-12-30 13:04:59 +01:00
|
|
|
assert_equal name , @space.classes[name].name
|
2015-07-28 15:19:10 +02:00
|
|
|
end
|
|
|
|
end
|
2015-10-13 13:46:07 +02:00
|
|
|
|
2015-07-28 15:19:10 +02:00
|
|
|
def test_method_name
|
|
|
|
classes.each do |name|
|
2016-12-30 13:04:59 +01:00
|
|
|
cl = @space.classes[name]
|
2015-07-28 15:19:10 +02:00
|
|
|
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
|
2015-07-02 10:09:23 +02:00
|
|
|
def test_messages
|
2016-12-30 13:04:59 +01:00
|
|
|
mess = @space.first_message
|
2015-07-02 10:09:23 +02:00
|
|
|
all = []
|
|
|
|
while mess
|
|
|
|
all << mess
|
2018-03-14 13:09:04 +01:00
|
|
|
assert mess.frame
|
2015-07-02 10:09:23 +02:00
|
|
|
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
|
2015-11-05 11:23:11 +01:00
|
|
|
assert_equal 50 + 1 , all.length
|
2015-07-02 10:09:23 +02:00
|
|
|
end
|
2015-07-20 12:20:43 +02:00
|
|
|
def test_message_vars
|
2016-12-30 13:04:59 +01:00
|
|
|
mess = @space.first_message
|
2015-07-20 12:20:43 +02:00
|
|
|
all = mess.get_instance_variables
|
|
|
|
assert all
|
|
|
|
assert all.include?(:next_message)
|
|
|
|
end
|
|
|
|
|
2016-12-29 17:51:24 +01:00
|
|
|
def test_create_class
|
2016-12-30 13:04:59 +01:00
|
|
|
assert @space.create_class( :NewClass )
|
2016-12-29 17:51:24 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_created_class_is_stored
|
2016-12-30 13:04:59 +01:00
|
|
|
@space.create_class( :NewerClass )
|
|
|
|
assert @space.get_class_by_name(:NewerClass)
|
2016-12-29 17:51:24 +01:00
|
|
|
end
|
|
|
|
|
2016-12-31 13:51:06 +01:00
|
|
|
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|
|
2018-04-02 15:36:43 +02:00
|
|
|
assert_equal 0 , type.methods_length , "name #{type.name}"
|
2016-12-31 13:51:06 +01:00
|
|
|
end
|
|
|
|
end
|
2018-03-31 12:47:02 +02:00
|
|
|
def test_no_methods_in_classes
|
2016-12-31 13:51:06 +01:00
|
|
|
test_remove_methods
|
|
|
|
@space.classes.each do |name , cl|
|
2018-04-02 15:36:43 +02:00
|
|
|
assert_equal 0 , cl.instance_type.methods_length , "name #{cl.name}"
|
2016-12-31 13:51:06 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-02 10:09:23 +02:00
|
|
|
end
|