From: Daniel Frederick Crisman Date: Fri, 13 Nov 2009 08:49:41 +0000 (-0500) Subject: Refactor and expand unshift.t X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ad2250c8dddabeba39a143c3eff5a0f641ee9402;p=p5sagit%2Fp5-mst-13.2.git Refactor and expand unshift.t --- diff --git a/t/op/unshift.t b/t/op/unshift.t index 30291fb..9659ee4 100644 --- a/t/op/unshift.t +++ b/t/op/unshift.t @@ -1,12 +1,67 @@ #!./perl -print "1..2\n"; +BEGIN { + require "test.pl"; +} -@a = (1,2,3); -$cnt1 = unshift(@a,0); +plan(18); -if (join(' ',@a) eq '0 1 2 3') {print "ok 1\n";} else {print "not ok 1\n";} -$cnt2 = unshift(@a,3,2,1); -if (join(' ',@a) eq '3 2 1 0 1 2 3') {print "ok 2\n";} else {print "not ok 2\n";} +@array = (1, 2, 3); +{ + no warnings 'syntax'; + $count3 = unshift (@array); +} +is(join(' ',@array), '1 2 3', 'unshift null'); +cmp_ok($count3, '==', 3, 'unshift count == 3'); + +$count3_2 = unshift (@array, ()); +is(join(' ',@array), '1 2 3', 'unshift null empty'); +cmp_ok($count3_2, '==', 3, 'unshift count == 3 again'); + +$count4 = unshift (@array, 0); +is(join(' ',@array), '0 1 2 3', 'unshift singleton list'); +cmp_ok($count4, '==', 4, 'unshift count == 4'); + +$count7 = unshift (@array, 3, 2, 1); +is(join(' ',@array), '3 2 1 0 1 2 3', 'unshift list'); +cmp_ok($count7, '==', 7, 'unshift count == 7'); + +@list = (5, 4); +$count9 = unshift (@array, @list); +is(join(' ',@array), '5 4 3 2 1 0 1 2 3', 'unshift array'); +cmp_ok($count9, '==', 9, 'unshift count == 9'); + +@list = (7); +@list2 = (6); +$count11 = unshift (@array, @list, @list2); +is(join(' ',@array), '7 6 5 4 3 2 1 0 1 2 3', 'unshift arrays'); +cmp_ok($count11, '==', 11, 'unshift count == 11'); + +# ignoring counts +@alpha = ('y', 'z'); + +{ + no warnings 'syntax'; + unshift (@alpha); +} +is(join(' ',@alpha), 'y z', 'void unshift null'); + +unshift (@alpha, ()); +is(join(' ',@alpha), 'y z', 'void unshift null empty'); + +unshift (@alpha, 'x'); +is(join(' ',@alpha), 'x y z', 'void unshift singleton list'); + +unshift (@alpha, 'u', 'v', 'w'); +is(join(' ',@alpha), 'u v w x y z', 'void unshift list'); + +@bet = ('s', 't'); +unshift (@alpha, @bet); +is(join(' ',@alpha), 's t u v w x y z', 'void unshift array'); + +@bet = ('q'); +@gimel = ('r'); +unshift (@alpha, @bet, @gimel); +is(join(' ',@alpha), 'q r s t u v w x y z', 'void unshift arrays');