Skip to content
Newer
Older
100644 99 lines (73 sloc) 2.73 KB
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored May 8, 2008
1 use v6;
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
2 use Test;
3
ab1c153 [t/spec/S32-array] smartlinks
moritz authored Apr 26, 2009
4 # L<S32::Containers/"Array"/"=item shift">
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
5
af56f51 [t] named arg tests for shift
frew authored Jan 28, 2009
6 =begin description
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
7
8 Shift tests
9
a98c723 t/spec/S29-array/*.t: converted to new POD format
moritz authored Jan 20, 2008
10 =end description
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
11
87efb8a @moritz [S32-array] unfossile tests. Most of that is calling positional argum…
moritz authored May 23, 2011
12 plan 31;
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
13
14 {
15
af56f51 [t] named arg tests for shift
frew authored Jan 28, 2009
16 my @shift = (1, 2, 3, 4, 5);
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
17
af56f51 [t] named arg tests for shift
frew authored Jan 28, 2009
18 is(+@shift, 5, 'we have 4 elements in our array');
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
19 my $a = shift(@shift);
20 is($a, 1, 'shift(@shift) works');
21
af56f51 [t] named arg tests for shift
frew authored Jan 28, 2009
22 is(+@shift, 4, 'we have 3 elements in our array');
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
23 $a = shift @shift;
24 is($a, 2, 'shift @shift works');
25
af56f51 [t] named arg tests for shift
frew authored Jan 28, 2009
26 is(+@shift, 3, 'we have 2 elements in our array');
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
27 $a = @shift.shift();
28 is($a, 3, '@shift.shift() works');
29
af56f51 [t] named arg tests for shift
frew authored Jan 28, 2009
30 is(+@shift, 2, 'we have 1 element in our array');
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
31 $a = @shift.shift;
af56f51 [t] named arg tests for shift
frew authored Jan 28, 2009
32 is($a, 4, '@shift.shift works');
33
2454a98 [t/spec] Refudge for ng.
colomon authored Dec 17, 2009
34 {
35 is(+@shift, 1, 'we have 1 element in our array');
87efb8a @moritz [S32-array] unfossile tests. Most of that is calling positional argum…
moritz authored May 23, 2011
36 $a = shift(@shift);
2454a98 [t/spec] Refudge for ng.
colomon authored Dec 17, 2009
37
38 is(+@shift, 0, 'we have no elements in our array');
39 ok(!defined(shift(@shift)), 'after the array is exhausted it gives undefined');
40 }
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
41 }
42
43 {
44 my @shift = (1, 2, 3, 4);
45
46 is(+@shift, 4, 'we have 4 elements in our array');
47 is(shift(@shift), 1, 'inline shift(@shift) works');
48
49 is(+@shift, 3, 'we have 3 elements in our array');
2454a98 [t/spec] Refudge for ng.
colomon authored Dec 17, 2009
50 is((shift @shift), 2, 'inline shift @shift works');
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
51
52 is(+@shift, 2, 'we have 2 elements in our array');
53 is(@shift.shift(), 3, 'inline @shift.shift() works');
54
55 is(+@shift, 1, 'we have 1 elements in our array');
56 is(@shift.shift, 4, 'inline @shift.shift works');
57
58 is(+@shift, 0, 'we have no elements in our array');
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored Nov 25, 2009
59 ok(!defined(shift(@shift)), 'again, the array is exhausted and we get undefined');
c03f823 @coke niecza fudge
coke authored Dec 24, 2011
60 #?niecza skip 'undeclared name Failure'
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored Oct 10, 2009
61 ok( shift(@shift) ~~ Failure, 'again, Failure from shifting empty array' );
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
62 }
63
64 # invocant syntax with inline arrays
65 {
66 is([1, 2, 3].shift, 1, 'this will return 1');
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored Nov 25, 2009
67 ok(!defined([].shift), 'this will return undefined');
c03f823 @coke niecza fudge
coke authored Dec 24, 2011
68 #?niecza skip 'undeclared name Failure'
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored Oct 10, 2009
69 ok( [].shift ~~ Failure, 'shift of empty array is Failure' );
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
70 }
71
72 # testing some edge cases
73 {
74 my @shift;
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored Nov 25, 2009
75 ok(!defined(shift(@shift)), 'shift on an empty array returns undefined');
c03f823 @coke niecza fudge
coke authored Dec 24, 2011
76 #?niecza skip 'undeclared name Failure'
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored Oct 10, 2009
77 ok( shift(@shift) ~~ Failure, 'shift on empty array is Failure');
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
78 }
79
80 # testing some error cases
81 {
82 my @shift = 1 .. 5;
27d699f @moritz move some errors into eval()
moritz authored Sep 26, 2011
83 eval_dies_ok('shift() ', 'shift() requires arguments');
84 eval_dies_ok('42.shift', '.shift should not work on scalars');
0eba93a @felher rewrite tests that rely on Exception to return False on .Bool
felher authored Apr 14, 2012
85 dies_ok { eval('shift(@shift, 10)') }, 'shift() should not allow extra arguments';
86 dies_ok { eval(' @shift.shift(10)') }, 'shift() should not allow extra arguments';
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
87 }
88
89 # Push with Inf arrays (waiting on answers to perl6-compiler email)
f9002e6 [STD] now does reduce tokens correctly; we now use a variable length
lwall authored Jul 22, 2008
90 # {
91 # my @shift = 1 .. Inf;
92 # # best not to uncomment this it just go on forever
93 # todo_throws_ok { 'shift(@shift)' }, '?? what should this error message be ??', 'cannot shift off of a Inf array';
94 # }
a69b36c Test suite refactoring.
cosimo authored Jan 15, 2008
95
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored Dec 31, 2010
96 done;
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored Oct 10, 2009
97
af56f51 [t] named arg tests for shift
frew authored Jan 28, 2009
98 # vim: syn=perl6
Something went wrong with that request. Please try again.