small rename and new test for layout

This commit is contained in:
Torsten Ruger 2015-08-08 18:08:47 +03:00
parent 0a54d030b5
commit 5d838056fa
4 changed files with 44 additions and 12 deletions

View File

@ -60,12 +60,18 @@ module Parfait
names
end
alias :list_index :index_of
# private inheritance is something to think off, we don't really want the list api exported
def index_of name
raise "should not rely on layout internal structure, use variable_index"
end
# index of a variable name into the layout.
# layout is a list, so lowest index is 1
# :layout is a variable for every object, so 1 is taken for :layout
# still, the index is the same.
def variable_index name
index_of(name)
list_index(name)
end
def sof_reference_name

View File

@ -98,7 +98,7 @@ module Register
real_name = clazz_name.to_s.split('_').last.capitalize.to_sym
clazz = Parfait::Space.object_space.get_class_by_name(real_name)
raise "Class name not given #{real_name}" unless clazz
index = clazz.object_layout.index_of( instance_name )
index = clazz.object_layout.variable_index( instance_name )
raise "Instance name=#{instance_name} not found on #{real_name}" unless index.is_a?(Numeric)
return index # the type word is at index 0, but layout is a list and starts at 1 == layout
end

View File

@ -0,0 +1,36 @@
require_relative "../helper"
class TestLayout < MiniTest::Test
def setup
@mess = Virtual.machine.boot.space.first_message
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
assert_equal 2 , index
assert_equal @mess.next_message , @mess.internal_object_get(index)
end
def test_layout_index
assert_equal @mess.get_layout , @mess.internal_object_get(1) , "mess"
end
def test_no_index_below_2
layout = @mess.get_layout
names = layout.object_instance_names
assert_equal 7 , names.get_length
names.each do |n|
assert layout.variable_index(n) > 1
end
end
end

View File

@ -76,14 +76,4 @@ class TestSpace < MiniTest::Test
assert all.include?(:next_message)
end
def test_message_layout
mess = @machine.space.first_message
one_way = mess.get_layout
assert one_way
assert mess.instance_variable_defined :next_message
# other_way = mess.get_instance_variable :layout
# assert other_way
# assert_equal one_way , other_way , "not same "
end
end