Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 101 lines (76 sloc) 2.938 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 pop">
a69b36c Test suite refactoring.
cosimo authored
5
91b701a S29-array/shift.t, S29-array/pop.t:
pmichaud authored
6 =begin description
a69b36c Test suite refactoring.
cosimo authored
7
8 Pop tests
9
91b701a S29-array/shift.t, S29-array/pop.t:
pmichaud authored
10 =end description
a69b36c Test suite refactoring.
cosimo authored
11
6bfa6b1 @lizmat Add some more tests related to pop()/.pop error conditions
lizmat authored
12 plan 36;
a69b36c Test suite refactoring.
cosimo authored
13
14 { # pop() elements into variables
8b9f0b2 [t] named argument test for pop
frew authored
15 my @pop = (-1, 1, 2, 3, 4);
16 is(+@pop, 5, 'we have 4 elements in the array');
6bfa6b1 @lizmat Add some more tests related to pop()/.pop error conditions
lizmat authored
17
a69b36c Test suite refactoring.
cosimo authored
18 my $a = pop(@pop);
19 is($a, 4, 'pop(@pop) works');
20
8b9f0b2 [t] named argument test for pop
frew authored
21 is(+@pop, 4, 'we have 3 elements in the array');
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
22 $a = pop @pop;
a69b36c Test suite refactoring.
cosimo authored
23 is($a, 3, 'pop @pop works');
24
8b9f0b2 [t] named argument test for pop
frew authored
25 is(+@pop, 3, 'we have 2 elements in the array');
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
26 $a = @pop.pop();
a69b36c Test suite refactoring.
cosimo authored
27 is($a, 2, '@pop.pop() works');
28
8b9f0b2 [t] named argument test for pop
frew authored
29 is(+@pop, 2, 'we have 1 element in the array');
1e0f570 [t/spec]: Eliminate some "Redeclared variable" warnings in tests
pmichaud authored
30 $a = @pop.pop;
a69b36c Test suite refactoring.
cosimo authored
31 is($a, 1, '@pop.pop works');
32
8b9f0b2 [t] named argument test for pop
frew authored
33 is(+@pop, 1, 'we have 1 element in the array');
d8279ea [t/spec] Refudged for ng.
colomon authored
34
35 {
87efb8a @moritz [S32-array] unfossile tests. Most of that is calling positional argument...
moritz authored
36 $a = pop(@pop);
d8279ea [t/spec] Refudged for ng.
colomon authored
37 is($a, -1, '@pop.pop works');
38
39 is(+@pop, 0, 'we have no more element in the array');
40 ok(!defined(pop(@pop)), 'after the array is exhausted pop() returns undefined');
004612d @coke niecza fudge
coke authored
41 #?niecza skip 'undeclared name Failure'
d8279ea [t/spec] Refudged for ng.
colomon authored
42 ok(pop(@pop) ~~ Failure, 'after the array is exhausted pop() returns Failure');
43 }
6bfa6b1 @lizmat Add some more tests related to pop()/.pop error conditions
lizmat authored
44 } #13
a69b36c Test suite refactoring.
cosimo authored
45
46 { # pop() elements inline
47 my @pop = (1, 2, 3, 4);
48
49 is(+@pop, 4, 'we have 4 elements in the array');
50 is(pop(@pop), 4, 'inline pop(@pop) works');
51
52 is(+@pop, 3, 'we have 3 elements in the array');
d8279ea [t/spec] Refudged for ng.
colomon authored
53 is((pop @pop), 3, 'inline pop @pop works');
a69b36c Test suite refactoring.
cosimo authored
54
55 is(+@pop, 2, 'we have 2 elements in the array');
56 is(@pop.pop(), 2, 'inline @pop.pop() works');
57
58 is(+@pop, 1, 'we have 1 element in the array');
59 is(@pop.pop, 1, 'inline @pop.pop works');
60
61 is(+@pop, 0, 'we have no more element in the array');
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
62 ok(!defined(pop(@pop)), 'after the array is exhausted pop() returns undefined');
004612d @coke niecza fudge
coke authored
63 #?niecza skip 'undeclared name Failure'
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored
64 ok(pop(@pop) ~~ Failure, 'after the array is exhausted pop() returns Failure');
6bfa6b1 @lizmat Add some more tests related to pop()/.pop error conditions
lizmat authored
65 } #11
a69b36c Test suite refactoring.
cosimo authored
66
67 # invocant syntax with inline arrays
68 {
69 is([1, 2, 3].pop, 3, 'this will return 3');
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
70 ok(!defined([].pop), 'this will return undefined');
004612d @coke niecza fudge
coke authored
71 #?niecza skip 'undeclared name Failure'
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored
72 ok( [].pop ~~ Failure, '[].pop is a Failure' );
6bfa6b1 @lizmat Add some more tests related to pop()/.pop error conditions
lizmat authored
73 } #3
a69b36c Test suite refactoring.
cosimo authored
74
75 # some edge cases
76 {
77 my @pop;
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
78 ok(!defined(@pop.pop()), 'pop on an un-initialized array returns undefined');
004612d @coke niecza fudge
coke authored
79 #?niecza skip 'undeclared name Failure'
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored
80 ok( @pop.pop() ~~ Failure, 'pop off uninitialized array is a Failure' );
a69b36c Test suite refactoring.
cosimo authored
81 }
82
83 # testing some error cases
84 {
85 my @pop = 1 .. 5;
6bfa6b1 @lizmat Add some more tests related to pop()/.pop error conditions
lizmat authored
86 eval_dies_ok('pop', 'pop() requires arguments');
87 eval_dies_ok('42.pop', '.pop should not work on scalars');
88 eval_dies_ok('pop(@pop,10)'), 'pop() should not allow extra arguments';
89 eval_dies_ok('@pop.pop(10)'), '.pop() should not allow extra arguments';
90 eval_dies_ok('@pop.pop = 3'), 'Cannot assign to a readonly variable or a value';
91 eval_dies_ok('pop(@pop) = 3'), 'Cannot assign to a readonly variable or a value';
92 } #6
93
94 #?niecza skip "may run forever"
95 {
96 my @push = 1 .. Inf;
97 eval_dies_ok( 'pop @push', 'cannot pop from an Inf array' );
98 } #1
ffcfab2 [t/spec] [].shift and [].pop return Failure, per spec r28723
kyle authored
99
f0c51f9 [t] fixed pod locations for S32-array
frew authored
100 # vim: ft=perl6
Something went wrong with that request. Please try again.