From 5d838056fafe93b844f2c63d28221b73847d5601 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 8 Aug 2015 18:08:47 +0300 Subject: [PATCH] small rename and new test for layout --- lib/parfait/layout.rb | 8 ++++++- lib/register/register_reference.rb | 2 +- test/parfait/test_layout.rb | 36 ++++++++++++++++++++++++++++++ test/parfait/test_space.rb | 10 --------- 4 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 test/parfait/test_layout.rb diff --git a/lib/parfait/layout.rb b/lib/parfait/layout.rb index 5f488e6e..ced0a9aa 100644 --- a/lib/parfait/layout.rb +++ b/lib/parfait/layout.rb @@ -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 diff --git a/lib/register/register_reference.rb b/lib/register/register_reference.rb index d59fc871..4f2048dc 100644 --- a/lib/register/register_reference.rb +++ b/lib/register/register_reference.rb @@ -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 diff --git a/test/parfait/test_layout.rb b/test/parfait/test_layout.rb new file mode 100644 index 00000000..d65d84ad --- /dev/null +++ b/test/parfait/test_layout.rb @@ -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 diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index 5dcac7a1..911b044e 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -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