Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 96 lines (70 sloc) 2.661 kb
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored
1 use v6;
a69b36c Test suite refactoring.
cosimo authored
2 use Test;
3
ab1c153 [t/spec/S32-array] smartlinks
moritz authored
4 # L<S32::Containers/"Array"/"=item shift">
a69b36c Test suite refactoring.
cosimo authored
5
af56f51 [t] named arg tests for shift
frew authored
6 =begin description
a69b36c Test suite refactoring.
cosimo authored
7
8 Shift tests
9
a98c723 t/spec/S29-array/*.t: converted to new POD format
moritz authored
10 =end description
a69b36c Test suite refactoring.
cosimo authored
11
87efb8a @moritz [S32-array] unfossile tests. Most of that is calling positional argum…
moritz authored
12 plan 31;
a69b36c Test suite refactoring.
cosimo authored
13
14 {
15
af56f51 [t] named arg tests for shift
frew authored
16 my @shift = (1, 2, 3, 4, 5);
a69b36c Test suite refactoring.
cosimo authored
17
af56f51 [t] named arg tests for shift
frew authored
18 is(+@shift, 5, 'we have 4 elements in our array');
a69b36c Test suite refactoring.
cosimo authored
19 my $a = shift(@shift);
20 is($a, 1, 'shift(@shift) works');
21
af56f51 [t] named arg tests for shift
frew authored
22 is(+@shift, 4, 'we have 3 elements in our array');
a69b36c Test suite refactoring.
cosimo authored
23 $a = shift @shift;
24 is($a, 2, 'shift @shift works');
25
af56f51 [t] named arg tests for shift
frew authored
26 is(+@shift, 3, 'we have 2 elements in our array');
a69b36c Test suite refactoring.
cosimo authored
27 $a = @shift.shift();
28 is($a, 3, '@shift.shift() works');
29
af56f51 [t] named arg tests for shift
frew authored
30 is(+@shift, 2, 'we have 1 element in our array');
a69b36c Test suite refactoring.
cosimo authored
31 $a = @shift.shift;
af56f51 [t] named arg tests for shift
frew authored
32 is($a, 4, '@shift.shift works');
33
2454a98 [t/spec] Refudge for ng.
colomon authored
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
36 $a = shift(@shift);
2454a98 [t/spec] Refudge for ng.
colomon authored
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
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
50 is((shift @shift), 2, 'inline shift @shift works');
a69b36c Test suite refactoring.
cosimo authored
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
59 ok(!defined(shift(@shift)), 'again, the array is exhausted and we get undefined');
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored
60 ok( shift(@shift) ~~ Failure, 'again, Failure from shifting empty array' );
a69b36c Test suite refactoring.
cosimo authored
61 }
62
63 # invocant syntax with inline arrays
64 {
65 is([1, 2, 3].shift, 1, 'this will return 1');
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
66 ok(!defined([].shift), 'this will return undefined');
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored
67 ok( [].shift ~~ Failure, 'shift of empty array is Failure' );
a69b36c Test suite refactoring.
cosimo authored
68 }
69
70 # testing some edge cases
71 {
72 my @shift;
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
73 ok(!defined(shift(@shift)), 'shift on an empty array returns undefined');
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored
74 ok( shift(@shift) ~~ Failure, 'shift on empty array is Failure');
a69b36c Test suite refactoring.
cosimo authored
75 }
76
77 # testing some error cases
78 {
79 my @shift = 1 .. 5;
af56f51 [t] named arg tests for shift
frew authored
80 dies_ok({ shift() }, 'shift() requires arguments');
81 dies_ok({ shift(@shift, 10) }, 'shift() should not allow extra arguments');
82 dies_ok({ @shift.shift(10) }, 'shift() should not allow extra arguments');
a69b36c Test suite refactoring.
cosimo authored
83 dies_ok({ 42.shift }, '.shift should not work on scalars');
84 }
85
86 # 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
87 # {
88 # my @shift = 1 .. Inf;
89 # # best not to uncomment this it just go on forever
90 # todo_throws_ok { 'shift(@shift)' }, '?? what should this error message be ??', 'cannot shift off of a Inf array';
91 # }
a69b36c Test suite refactoring.
cosimo authored
92
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
93 done;
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored
94
af56f51 [t] named arg tests for shift
frew authored
95 # vim: syn=perl6
Something went wrong with that request. Please try again.