fixing offset bug
found by tests that overwrite the attribute
This commit is contained in:
parent
1a236aa50e
commit
d2c670b31a
@ -140,6 +140,7 @@ module Parfait
|
|||||||
|
|
||||||
module Methods
|
module Methods
|
||||||
def offset( offset )
|
def offset( offset )
|
||||||
|
offset += 1 # for the attribute we add (indexed_length)
|
||||||
|
|
||||||
define_method :get_offset do
|
define_method :get_offset do
|
||||||
offset
|
offset
|
||||||
|
@ -25,7 +25,7 @@ module Parfait
|
|||||||
attribute :object_class
|
attribute :object_class
|
||||||
|
|
||||||
include Indexed
|
include Indexed
|
||||||
self.offset(2)
|
self.offset(1)
|
||||||
|
|
||||||
def initialize( object_class )
|
def initialize( object_class )
|
||||||
super()
|
super()
|
||||||
@ -47,7 +47,7 @@ module Parfait
|
|||||||
self.get_length
|
self.get_length
|
||||||
end
|
end
|
||||||
|
|
||||||
def object_instance_names
|
def instance_names
|
||||||
names = List.new
|
names = List.new
|
||||||
each do |item|
|
each do |item|
|
||||||
names.push item
|
names.push item
|
||||||
@ -55,20 +55,14 @@ module Parfait
|
|||||||
names
|
names
|
||||||
end
|
end
|
||||||
|
|
||||||
def object_instance_length
|
def instance_length
|
||||||
self.get_length
|
self.get_length
|
||||||
end
|
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
|
# index of the variable when using internal_object_get
|
||||||
# (internal_object_get is 1 based and 1 is always the layout)
|
# (internal_object_get is 1 based and 1 is always the layout)
|
||||||
def variable_index name
|
def variable_index name
|
||||||
has = list_index(name)
|
has = index_of(name)
|
||||||
return nil unless has
|
return nil unless has
|
||||||
raise "internal error #{name}:#{has}" if has < 1
|
raise "internal error #{name}:#{has}" if has < 1
|
||||||
has
|
has
|
||||||
|
@ -33,6 +33,15 @@ class TestList < MiniTest::Test
|
|||||||
assert_equal 1 , layout.variable_index(:layout)
|
assert_equal 1 , layout.variable_index(:layout)
|
||||||
end
|
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
|
def test_list_inspect
|
||||||
@list.set(1,1)
|
@list.set(1,1)
|
||||||
assert_equal "1" , @list.inspect
|
assert_equal "1" , @list.inspect
|
||||||
@ -54,7 +63,7 @@ class TestList < MiniTest::Test
|
|||||||
end
|
end
|
||||||
def test_one_set1
|
def test_one_set1
|
||||||
assert_equal 2 , @list.set(1,2)
|
assert_equal 2 , @list.set(1,2)
|
||||||
assert_equal 1 , @list.internal_object_get(1)
|
assert_equal 1 , @list.internal_object_get(2)
|
||||||
end
|
end
|
||||||
def test_set1_len
|
def test_set1_len
|
||||||
@list.set(1,1)
|
@list.set(1,1)
|
||||||
|
Loading…
Reference in New Issue
Block a user