2015-08-08 17:08:47 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
class TestLayout < MiniTest::Test
|
|
|
|
|
|
|
|
def setup
|
2015-10-22 17:16:29 +02:00
|
|
|
@mess = Register.machine.boot.space.first_message
|
2015-08-08 17:08:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_message_layout
|
|
|
|
layout = @mess.get_layout
|
|
|
|
assert layout
|
|
|
|
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_layout.variable_index :next_message
|
2015-10-17 09:03:39 +02:00
|
|
|
assert_equal 2 , index
|
2015-11-07 16:40:59 +01:00
|
|
|
assert_equal @mess.next_message , @mess.get_internal(index)
|
2015-08-08 17:08:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_layout_index
|
2015-11-07 16:40:59 +01:00
|
|
|
assert_equal @mess.get_layout , @mess.get_internal(Parfait::LAYOUT_INDEX) , "mess"
|
2015-08-08 17:08:47 +02:00
|
|
|
end
|
|
|
|
|
2015-10-16 17:34:54 +02:00
|
|
|
def test_inspect
|
|
|
|
assert @mess.get_layout.inspect.start_with?("Layout")
|
|
|
|
end
|
2015-10-13 13:46:07 +02:00
|
|
|
def test_layout_is_first
|
|
|
|
layout = @mess.get_layout
|
2015-10-17 09:03:39 +02:00
|
|
|
assert_equal 1 , layout.variable_index(:layout)
|
2015-10-13 13:46:07 +02:00
|
|
|
end
|
|
|
|
|
2015-10-26 11:22:32 +01:00
|
|
|
def test_length
|
2015-10-27 15:05:50 +01:00
|
|
|
assert_equal 9 , @mess.get_layout.instance_length , @mess.get_layout.inspect
|
2015-10-26 11:22:32 +01:00
|
|
|
end
|
|
|
|
|
2015-10-26 14:07:59 +01:00
|
|
|
def test_layout_length
|
2015-10-29 11:45:29 +01:00
|
|
|
assert_equal 9 , @mess.get_layout.instance_length , @mess.get_layout.inspect
|
2015-11-07 16:40:59 +01:00
|
|
|
assert_equal 18 , @mess.get_layout.get_internal(4)
|
2015-10-26 14:07:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_layout_length_index
|
|
|
|
assert_equal 4 , @mess.get_layout.get_layout.variable_index(:indexed_length)
|
|
|
|
assert_equal 4 , @mess.get_layout.get_layout.get_offset
|
|
|
|
assert_equal 4 , @mess.get_layout.get_offset
|
2015-10-29 11:45:29 +01:00
|
|
|
assert_equal 8 , @mess.get_layout.get_layout.indexed_length
|
2015-11-07 16:40:59 +01:00
|
|
|
assert_equal 8 , @mess.get_layout.get_layout.get_internal(4)
|
2015-10-26 14:07:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_layout_methods
|
|
|
|
assert_equal 3 , @mess.get_layout.get_layout.variable_index(:instance_methods)
|
|
|
|
end
|
|
|
|
|
2015-10-13 13:46:07 +02:00
|
|
|
def test_no_index_below_1
|
2015-08-08 17:08:47 +02:00
|
|
|
layout = @mess.get_layout
|
2015-10-26 11:58:38 +01:00
|
|
|
names = layout.instance_names
|
2015-10-27 15:05:50 +01:00
|
|
|
assert_equal 9 , names.get_length , names.inspect
|
2015-08-08 17:08:47 +02:00
|
|
|
names.each do |n|
|
2015-10-13 13:46:07 +02:00
|
|
|
assert layout.variable_index(n) >= 1
|
2015-08-08 17:08:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-13 13:46:07 +02:00
|
|
|
def test_class_layout
|
2015-10-22 17:16:29 +02:00
|
|
|
oc = Register.machine.boot.space.get_class_by_name( :Object )
|
2015-10-13 13:46:07 +02:00
|
|
|
assert_equal Parfait::Class , oc.class
|
|
|
|
layout = oc.object_layout
|
|
|
|
assert_equal Parfait::Layout , layout.class
|
2015-10-26 11:58:38 +01:00
|
|
|
assert_equal 1 , layout.instance_names.get_length
|
2015-10-26 11:22:32 +01:00
|
|
|
assert_equal layout.first , :layout
|
2015-10-13 13:46:07 +02:00
|
|
|
end
|
2015-10-17 09:03:39 +02:00
|
|
|
|
2015-11-07 19:10:55 +01:00
|
|
|
|
|
|
|
def test_class_space
|
|
|
|
space = Register.machine.space
|
|
|
|
assert_equal Parfait::Space , space.class
|
|
|
|
layout = space.get_layout
|
|
|
|
assert_equal Parfait::Layout , layout.class
|
|
|
|
assert_equal 3 , layout.instance_names.get_length
|
|
|
|
assert_equal layout.object_class.class , Parfait::Class
|
|
|
|
assert_equal layout.object_class.name , :Space
|
|
|
|
end
|
2015-10-17 09:03:39 +02:00
|
|
|
def test_attribute_set
|
|
|
|
@mess.receiver = 55
|
|
|
|
assert_equal 55 , @mess.receiver
|
|
|
|
end
|
|
|
|
|
2015-10-26 14:07:59 +01:00
|
|
|
def test_add_name
|
|
|
|
layout = Parfait::Layout.new Register.machine.space.get_class_by_name(:Layout)
|
2015-10-29 11:45:29 +01:00
|
|
|
layout.add_instance_variable :boo , :Object
|
2015-10-26 14:07:59 +01:00
|
|
|
assert_equal 2 , layout.variable_index(:boo)
|
2015-10-29 11:45:29 +01:00
|
|
|
assert_equal 4 , layout.get_length
|
2015-10-26 14:07:59 +01:00
|
|
|
assert_equal :layout , layout.get(1)
|
2015-10-29 11:45:29 +01:00
|
|
|
assert_equal :boo , layout.get(3)
|
2015-10-26 14:07:59 +01:00
|
|
|
layout
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_inspect
|
|
|
|
layout = test_add_name
|
|
|
|
assert layout.inspect.include?("boo") , layout.inspect
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_each
|
|
|
|
layout = test_add_name
|
2015-10-29 11:45:29 +01:00
|
|
|
assert_equal 4 , layout.get_length
|
|
|
|
counter = [:boo , :Object, :layout , :Layout]
|
2015-10-26 14:07:59 +01:00
|
|
|
layout.each do |item|
|
|
|
|
assert_equal item , counter.delete(item)
|
|
|
|
end
|
|
|
|
assert counter.empty?
|
|
|
|
end
|
|
|
|
|
2015-10-17 09:03:39 +02:00
|
|
|
# not really parfait test, but related and no other place currently
|
|
|
|
def test_reg_index
|
|
|
|
message_ind = Register.resolve_index( :message , :receiver )
|
|
|
|
assert_equal 3 , message_ind
|
|
|
|
@mess.receiver = 55
|
2015-11-07 16:40:59 +01:00
|
|
|
assert_equal 55 , @mess.get_internal(message_ind)
|
2015-10-17 09:03:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_object_layout
|
|
|
|
assert_equal 2 , @mess.get_layout.variable_index(:next_message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_me
|
|
|
|
layout = @mess.get_layout
|
2015-11-07 16:40:59 +01:00
|
|
|
assert_equal layout , @mess.get_internal(1)
|
2015-10-17 09:03:39 +02:00
|
|
|
end
|
2015-08-08 17:08:47 +02:00
|
|
|
end
|