| 1 | #!./perl |
| 2 | |
| 3 | BEGIN { |
| 4 | require "test.pl"; |
| 5 | } |
| 6 | |
| 7 | plan(36); |
| 8 | |
| 9 | @array = (1, 2, 3); |
| 10 | $aref = [1, 2, 3]; |
| 11 | |
| 12 | no warnings 'experimental::autoderef'; |
| 13 | { |
| 14 | no warnings 'syntax'; |
| 15 | $count3 = unshift (@array); |
| 16 | $count3r = unshift ($aref); |
| 17 | } |
| 18 | is(join(' ',@array), '1 2 3', 'unshift null'); |
| 19 | cmp_ok($count3, '==', 3, 'unshift count == 3'); |
| 20 | is(join(' ',@$aref), '1 2 3', 'unshift null (ref)'); |
| 21 | cmp_ok($count3r, '==', 3, 'unshift count == 3 (ref)'); |
| 22 | |
| 23 | |
| 24 | $count3_2 = unshift (@array, ()); |
| 25 | is(join(' ',@array), '1 2 3', 'unshift null empty'); |
| 26 | cmp_ok($count3_2, '==', 3, 'unshift count == 3 again'); |
| 27 | $count3_2r = unshift ($aref, ()); |
| 28 | is(join(' ',@$aref), '1 2 3', 'unshift null empty (ref)'); |
| 29 | cmp_ok($count3_2r, '==', 3, 'unshift count == 3 again (ref)'); |
| 30 | |
| 31 | $count4 = unshift (@array, 0); |
| 32 | is(join(' ',@array), '0 1 2 3', 'unshift singleton list'); |
| 33 | cmp_ok($count4, '==', 4, 'unshift count == 4'); |
| 34 | $count4r = unshift ($aref, 0); |
| 35 | is(join(' ',@$aref), '0 1 2 3', 'unshift singleton list (ref)'); |
| 36 | cmp_ok($count4r, '==', 4, 'unshift count == 4 (ref)'); |
| 37 | |
| 38 | $count7 = unshift (@array, 3, 2, 1); |
| 39 | is(join(' ',@array), '3 2 1 0 1 2 3', 'unshift list'); |
| 40 | cmp_ok($count7, '==', 7, 'unshift count == 7'); |
| 41 | $count7r = unshift ($aref, 3, 2, 1); |
| 42 | is(join(' ',@$aref), '3 2 1 0 1 2 3', 'unshift list (ref)'); |
| 43 | cmp_ok($count7r, '==', 7, 'unshift count == 7 (ref)'); |
| 44 | |
| 45 | @list = (5, 4); |
| 46 | $count9 = unshift (@array, @list); |
| 47 | is(join(' ',@array), '5 4 3 2 1 0 1 2 3', 'unshift array'); |
| 48 | cmp_ok($count9, '==', 9, 'unshift count == 9'); |
| 49 | $count9r = unshift ($aref, @list); |
| 50 | is(join(' ',@$aref), '5 4 3 2 1 0 1 2 3', 'unshift array (ref)'); |
| 51 | cmp_ok($count9r, '==', 9, 'unshift count == 9 (ref)'); |
| 52 | |
| 53 | |
| 54 | @list = (7); |
| 55 | @list2 = (6); |
| 56 | $count11 = unshift (@array, @list, @list2); |
| 57 | is(join(' ',@array), '7 6 5 4 3 2 1 0 1 2 3', 'unshift arrays'); |
| 58 | cmp_ok($count11, '==', 11, 'unshift count == 11'); |
| 59 | $count11r = unshift ($aref, @list, @list2); |
| 60 | is(join(' ',@$aref), '7 6 5 4 3 2 1 0 1 2 3', 'unshift arrays (ref)'); |
| 61 | cmp_ok($count11r, '==', 11, 'unshift count == 11 (ref)'); |
| 62 | |
| 63 | # ignoring counts |
| 64 | @alpha = ('y', 'z'); |
| 65 | $alpharef = ['y', 'z']; |
| 66 | |
| 67 | { |
| 68 | no warnings 'syntax'; |
| 69 | unshift (@alpha); |
| 70 | unshift ($alpharef); |
| 71 | } |
| 72 | is(join(' ',@alpha), 'y z', 'void unshift null'); |
| 73 | is(join(' ',@$alpharef), 'y z', 'void unshift null (ref)'); |
| 74 | |
| 75 | unshift (@alpha, ()); |
| 76 | is(join(' ',@alpha), 'y z', 'void unshift null empty'); |
| 77 | unshift ($alpharef, ()); |
| 78 | is(join(' ',@$alpharef), 'y z', 'void unshift null empty (ref)'); |
| 79 | |
| 80 | unshift (@alpha, 'x'); |
| 81 | is(join(' ',@alpha), 'x y z', 'void unshift singleton list'); |
| 82 | unshift ($alpharef, 'x'); |
| 83 | is(join(' ',@$alpharef), 'x y z', 'void unshift singleton list (ref)'); |
| 84 | |
| 85 | unshift (@alpha, 'u', 'v', 'w'); |
| 86 | is(join(' ',@alpha), 'u v w x y z', 'void unshift list'); |
| 87 | unshift ($alpharef, 'u', 'v', 'w'); |
| 88 | is(join(' ',@$alpharef), 'u v w x y z', 'void unshift list (ref)'); |
| 89 | |
| 90 | @bet = ('s', 't'); |
| 91 | unshift (@alpha, @bet); |
| 92 | is(join(' ',@alpha), 's t u v w x y z', 'void unshift array'); |
| 93 | unshift ($alpharef, @bet); |
| 94 | is(join(' ',@$alpharef), 's t u v w x y z', 'void unshift array (ref)'); |
| 95 | |
| 96 | @bet = ('q'); |
| 97 | @gimel = ('r'); |
| 98 | unshift (@alpha, @bet, @gimel); |
| 99 | is(join(' ',@alpha), 'q r s t u v w x y z', 'void unshift arrays'); |
| 100 | unshift ($alpharef, @bet, @gimel); |
| 101 | is(join(' ',@$alpharef), 'q r s t u v w x y z', 'void unshift arrays (ref)'); |
| 102 | |