xref: /PHP-7.3/ext/spl/tests/dllist_013.phpt (revision ded3d984)
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===DONE===
34<?php exit(0); ?>
35--EXPECT--
36Exception: Offset invalid or out of range
377
387
396
405
414
423
432
441
45===DONE===
46