xref: /PHP-8.0/ext/spl/tests/dllist_013.phpt (revision f7fbc633)
1--TEST--
2SPL: DoublyLinkedList: insert operations
3--FILE--
4<?php
5$dll = new SplDoublyLinkedList();
6// errors
7try {
8    $dll->add(2,5);
9} catch (OutOfRangeException $e) {
10    echo "Exception: ".$e->getMessage()."\n";
11}
12
13$dll->add(0,6);						//	6
14$dll->add(0,3);						//	3 6
15// Insert in the middle of the DLL
16$dll->add(1,4);						//	3 4 6
17$dll->add(2,5);						//	3 4 5 6
18$dll->unshift(2);					//	2 3 5 4 6
19// Insert at the beginning and end of the DLL
20$dll->add(0,1);						//	1 2 3 4 5 6
21$dll->add(6,7);						//	1 2 3 4 5 6 7
22
23echo count($dll)."\n";
24
25echo $dll->pop()."\n";
26echo $dll->pop()."\n";
27echo $dll->pop()."\n";
28echo $dll->pop()."\n";
29echo $dll->pop()."\n";
30echo $dll->pop()."\n";
31echo $dll->pop()."\n";
32?>
33--EXPECT--
34Exception: SplDoublyLinkedList::add(): Argument #1 ($index) is out of range
357
367
376
385
394
403
412
421
43