fixing offset bug

found by tests that overwrite the attribute
This commit is contained in:
Torsten Ruger 2015-10-26 12:57:54 +02:00
parent 1a236aa50e
commit d2c670b31a
3 changed files with 15 additions and 11 deletions

View File

@ -140,6 +140,7 @@ module Parfait
module Methods
def offset( offset )
offset += 1 # for the attribute we add (indexed_length)
define_method :get_offset do
offset

View File

@ -25,7 +25,7 @@ module Parfait
attribute :object_class
include Indexed
self.offset(2)
self.offset(1)
def initialize( object_class )
super()
@ -47,7 +47,7 @@ module Parfait
self.get_length
end
def object_instance_names
def instance_names
names = List.new
each do |item|
names.push item
@ -55,20 +55,14 @@ module Parfait
names
end
def object_instance_length
def instance_length
self.get_length
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 the variable when using internal_object_get
# (internal_object_get is 1 based and 1 is always the layout)
def variable_index name
has = list_index(name)
has = index_of(name)
return nil unless has
raise "internal error #{name}:#{has}" if has < 1
has

View File

@ -33,6 +33,15 @@ class TestList < MiniTest::Test
assert_equal 1 , layout.variable_index(:layout)
end
def test_length0
assert_equal 0 , @list.get_length
assert_equal nil , @list.indexed_length
end
def test_length1
@list.push :one
assert_equal 1 , @list.get_length
assert_equal 1 , @list.indexed_length
end
def test_list_inspect
@list.set(1,1)
assert_equal "1" , @list.inspect
@ -54,7 +63,7 @@ class TestList < MiniTest::Test
end
def test_one_set1
assert_equal 2 , @list.set(1,2)
assert_equal 1 , @list.internal_object_get(1)
assert_equal 1 , @list.internal_object_get(2)
end
def test_set1_len
@list.set(1,1)