From 332a734288244b92d2492c218b0f32ff0e4565a3 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 11 Apr 2011 15:20:18 -0500 Subject: [PATCH] do not remove an element while splicing --- lib/WebGUI/FormBuilder/Role/HasObjects.pm | 2 +- t/FormBuilder.t | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/FormBuilder/Role/HasObjects.pm b/lib/WebGUI/FormBuilder/Role/HasObjects.pm index 2098f2f94..f3641cd04 100644 --- a/lib/WebGUI/FormBuilder/Role/HasObjects.pm +++ b/lib/WebGUI/FormBuilder/Role/HasObjects.pm @@ -76,7 +76,7 @@ The numeric index. 0 is the first object. sub addObjectAt { my ( $self, $object, $position ) = @_; - splice @{$self->objects}, $position, 1, $object; + splice @{$self->objects}, $position, 0, $object; return $object; } diff --git a/t/FormBuilder.t b/t/FormBuilder.t index 768f2c061..1cbfa3616 100644 --- a/t/FormBuilder.t +++ b/t/FormBuilder.t @@ -249,8 +249,16 @@ $tab = $fb->addTab( tabset => 'one', name => 'one' ); $fset = $fb->addFieldset( name => 'three', label => 'Three' ); $field2 = $fb->addFieldAt( WebGUI::Form::Text->new( $session, name => "two" ), 2 ); -is( $fb->objects->[2], $field2, 'objects array is correct' ); -is( $fb->fields->[1], $field2, 'fields array is correct' ); +cmp_deeply( + $fb->objects, + [ $field, $fb->getTabset('one'), $field2, $fset ], + 'objects array is correct', +); +cmp_deeply( + $fb->fields, + [ $field, $field2 ], + 'fields array is correct', +); #---------------------------------------------------------------------------- # Serialize and deserialize