Skip to content

Commit b7507b8

Browse files
committed
Add tests for int @a.append|prepend
1 parent d4463f9 commit b7507b8

File tree

1 file changed

+49
-15
lines changed

1 file changed

+49
-15
lines changed

S09-typed-arrays/native-int.t

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if $*KERNEL.bits == 64 {
88
@uint.push: uint64;
99
}
1010

11-
plan (@int + @uint) * 136 + @uint * 2;
11+
plan (@int + @uint) * 157 + @uint * 2;
1212

1313
# Basic native int array tests.
1414
for flat @int,@uint -> $T {
@@ -140,41 +140,75 @@ for flat @int,@uint -> $T {
140140
"Cannot push non-int/Int to $t array";
141141
throws-like { @arr[0] := my $a }, Exception,
142142
message => 'Cannot bind to a natively typed array',
143-
"Cannot push non-int/Int to $t array";
143+
"Cannot bind to $t array";
144144
throws-like { @arr[0]:delete }, Exception,
145145
message => 'Cannot delete from a natively typed array',
146-
"Cannot push non-int/Int to $t array";
146+
"Cannot delete from $t array";
147147

148-
is (@arr.push(101, 105)), (42,101,105), "can push multiple to $t array";
148+
is (@arr.push(101, 105)), (42,101,105),
149+
"can push multiple to $t array";
149150
is @arr.elems, 3, "push multiple to $t array works (1)";
150151
is @arr[1], 101, "push multiple to $t array works (2)";
151152
is @arr[2], 105, "push multiple to $t array works (3)";
152153
throws-like { @arr.push('omg', 'wtf') }, Exception,
153154
"Cannot push non-int/Int to $t array (multiple push)";
154155

155-
is @arr.pop, 105, "pop from $t array works (1)";
156-
is @arr.elems, 2, "pop from $t array works (2)";
157-
158-
is (@arr.unshift(1)), (1,42,101), "can unshift to $t array";
159-
is @arr.elems, 3, "unshift to $t array works (1)";
156+
is @arr.append(66), (42,101,105,66), "can append to $t array";
157+
is @arr.elems, 4, "append to $t array works (1)";
158+
is @arr[3], 66, "append to $t array works (2)";
159+
throws-like { @arr.append('it real good') }, Exception,
160+
"Cannot append non-int/Int to $t array";
161+
162+
is (@arr.append(21,25)), (42,101,105,66,21,25),
163+
"can append multiple to $t array";
164+
is @arr.elems, 6, "append multiple to $t array works (1)";
165+
is @arr[4], 21, "append multiple to $t array works (2)";
166+
is @arr[5], 25, "append multiple to $t array works (3)";
167+
throws-like { @arr.append('omg', 'wtf') }, Exception,
168+
"Cannot append non-int/Int to $t array (multiple append)";
169+
170+
is @arr.pop, 25, "pop from $t array works (1)";
171+
is @arr.elems, 5, "pop from $t array works (2)";
172+
173+
is (@arr.unshift(1)), (1,42,101,105,66,21),
174+
"can unshift to $t array";
175+
is @arr.elems, 6, "unshift to $t array works (1)";
160176
is @arr[0], 1, "unshift to $t array works (2)";
161177
is @arr[1], 42, "unshift to $t array works (3)";
162178
# RT #125123
163-
throws-like { @arr.unshift('part of the day not working') }, X::TypeCheck,
164-
got => Str,
179+
throws-like { @arr.unshift('part of the day not working') }, Exception,
165180
"Cannot unshift non-int/Int to $t array";
166181

167-
is (@arr.unshift(3,2)), (3,2,1,42,101),"can unshift multiple to $t array";
168-
is @arr.elems, 5, "unshift multiple to $t array works (1)";
182+
is (@arr.unshift(3,2)), (3,2,1,42,101,105,66,21),
183+
"can unshift multiple to $t array";
184+
is @arr.elems, 8, "unshift multiple to $t array works (1)";
169185
is @arr[0], 3, "unshift multiple to $t array works (2)";
170186
is @arr[1], 2, "unshift multiple to $t array works (3)";
171187
is @arr[2], 1, "unshift multiple to $t array works (4)";
172188
is @arr[3], 42, "unshift multiple to $t array works (5)";
173189
throws-like { @arr.unshift('wtf', 'bbq') }, Exception,
174190
"Cannot unshift non-int/Int to $t array (multiple unshift)";
175191

176-
is @arr.shift, 3, "shift from $t array works (1)";
177-
is @arr.elems, 4, "shift from $t array works (2)";
192+
is (@arr.prepend(4)), (4,3,2,1,42,101,105,66,21),
193+
"can prepend to $t array";
194+
is @arr.elems, 9, "prepend to $t array works (1)";
195+
is @arr[0], 4, "prepend to $t array works (2)";
196+
is @arr[1], 3, "prepend to $t array works (3)";
197+
throws-like { @arr.prepend('part of the day not working') }, Exception,
198+
"Cannot prepend non-int/Int to $t array";
199+
200+
is (@arr.prepend(6,5)), (6,5,4,3,2,1,42,101,105,66,21),
201+
"can prepend multiple to $t array";
202+
is @arr.elems, 11, "unshift multiple to $t array works (1)";
203+
is @arr[0], 6, "prepend multiple to $t array works (2)";
204+
is @arr[1], 5, "prepend multiple to $t array works (3)";
205+
is @arr[2], 4, "prepend multiple to $t array works (4)";
206+
is @arr[3], 3, "prepend multiple to $t array works (5)";
207+
throws-like { @arr.prepend('wtf', 'bbq') }, Exception,
208+
"Cannot prepend non-int/Int to $t array (multiple unshift)";
209+
210+
is @arr.shift, 6, "shift from $t array works (1)";
211+
is @arr.elems, 10, "shift from $t array works (2)";
178212

179213
is (@arr = 1..10), (1..10).List, "can initialize $t from Range";
180214
my @replaced = @arr.splice(3, 2, 98, 99, 100);

0 commit comments

Comments
 (0)