From 4ce4775902ab88e673c5b4ad93277eaed1b8442e Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 17 Oct 2015 10:03:39 +0300 Subject: [PATCH] fix layout amazing at this stage, but yet another index error the strange (and wonderful) thing is that changing the return of the one function just shifts the variables and everything else stays intact. Thus are the wonders of object orientation --- lib/parfait/layout.rb | 11 ++++++----- test/parfait/test_layout.rb | 26 ++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/parfait/layout.rb b/lib/parfait/layout.rb index e8a0bef3..01ceb8a3 100644 --- a/lib/parfait/layout.rb +++ b/lib/parfait/layout.rb @@ -62,12 +62,13 @@ module Parfait 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. + # index of the variable when using internal_object_get + # (internal_object_get is 1 based and 1 is always the layout) def variable_index name - list_index(name) + has = list_index(name) + return nil unless has + raise "internal error #{name}:#{has}" if has < 2 + has - 1 end def inspect diff --git a/test/parfait/test_layout.rb b/test/parfait/test_layout.rb index ab3e5049..8f54df21 100644 --- a/test/parfait/test_layout.rb +++ b/test/parfait/test_layout.rb @@ -16,7 +16,7 @@ class TestLayout < MiniTest::Test 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 3 , index + assert_equal 2 , index assert_equal @mess.next_message , @mess.internal_object_get(index) end @@ -33,7 +33,7 @@ class TestLayout < MiniTest::Test end def test_layout_is_first layout = @mess.get_layout - assert_equal nil , layout.variable_index(:layout) + assert_equal 1 , layout.variable_index(:layout) end def test_no_index_below_1 @@ -53,4 +53,26 @@ class TestLayout < MiniTest::Test assert_equal layout.object_instance_names.get_length , 0 #assert_equal layout.first , :layout end + + def test_attribute_set + @mess.receiver = 55 + assert_equal 55 , @mess.receiver + end + + # 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 + assert_equal 55 , @mess.internal_object_get(message_ind) + end + + def test_object_layout + assert_equal 2 , @mess.get_layout.variable_index(:next_message) + end + + def test_remove_me + layout = @mess.get_layout + assert_equal layout , @mess.internal_object_get(1) + end end