helly Mon Nov 7 13:38:25 2005 EDT Added files: (Branch: PHP_5_1) /php-src/ext/spl/tests iterator_025.phpt iterator_026.phpt iterator_028.phpt Log: - Add new tests
http://cvs.php.net/co.php/php-src/ext/spl/tests/iterator_025.phpt?r=1.1&p=1 Index: php-src/ext/spl/tests/iterator_025.phpt +++ php-src/ext/spl/tests/iterator_025.phpt --TEST-- SPL: RecursiveIteratorIterator and begin/endIteration() --FILE-- <?php class MyRecursiveIteratorIterator extends RecursiveIteratorIterator { function beginIteration() { echo __METHOD__ . "()\n"; } function endIteration() { echo __METHOD__ . "()\n"; } } $ar = array(1, 2, array(31, 32, array(331)), 4); $it = new MyRecursiveIteratorIterator(new ArrayObject($ar, 0, "RecursiveArrayIterator")); foreach($it as $v) echo "$v\n"; echo "===MORE===\n"; foreach($it as $v) echo "$v\n"; echo "===MORE===\n"; $it->rewind(); foreach($it as $v) echo "$v\n"; var_dump($it->valid()); echo "===MANUAL===\n"; $it->rewind(); while($it->valid()) { echo $it->current() . "\n"; $it->next(); break; } $it->rewind(); while($it->valid()) { echo $it->current() . "\n"; $it->next(); } ?> ===DONE=== <?php exit(0); ?> --EXPECT-- MyRecursiveIteratorIterator::beginIteration() 1 2 31 32 331 4 MyRecursiveIteratorIterator::endIteration() ===MORE=== MyRecursiveIteratorIterator::beginIteration() 1 2 31 32 331 4 MyRecursiveIteratorIterator::endIteration() ===MORE=== MyRecursiveIteratorIterator::beginIteration() 1 2 31 32 331 4 MyRecursiveIteratorIterator::endIteration() bool(false) ===MANUAL=== MyRecursiveIteratorIterator::beginIteration() 1 1 2 31 32 331 4 MyRecursiveIteratorIterator::endIteration() ===DONE=== http://cvs.php.net/co.php/php-src/ext/spl/tests/iterator_026.phpt?r=1.1&p=1 Index: php-src/ext/spl/tests/iterator_026.phpt +++ php-src/ext/spl/tests/iterator_026.phpt --TEST-- SPL: CachingIterator::hasNext() --FILE-- <?php $ar = array(1, 2, array(31, 32, array(331)), 4); $it = new RecursiveArrayIterator($ar); $it = new CachingRecursiveIterator($it); $it = new RecursiveIteratorIterator($it); foreach($it as $k=>$v) { echo "$k=>$v\n"; echo "hasNext: " . ($it->getInnerIterator()->hasNext() ? "yes" : "no") . "\n"; } ?> ===DONE=== <?php exit(0); ?> --EXPECT-- 0=>1 hasNext: yes 1=>2 hasNext: yes 0=>31 hasNext: yes 1=>32 hasNext: yes 0=>331 hasNext: no 3=>4 hasNext: no ===DONE=== http://cvs.php.net/co.php/php-src/ext/spl/tests/iterator_028.phpt?r=1.1&p=1 Index: php-src/ext/spl/tests/iterator_028.phpt +++ php-src/ext/spl/tests/iterator_028.phpt --TEST-- SPL: RecursiveIteratorIterator and setMaxDepth() --FILE-- <?php $ar = array(1, 2, array(31, 32, array(331, array(3321, array(33221)))), 4); $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($ar)); echo "===?===\n"; var_dump($it->getMaxDepth()); foreach($it as $v) echo $it->getDepth() . ": $v\n"; echo "===2===\n"; $it->setMaxDepth(2); var_dump($it->getMaxDepth()); foreach($it as $v) echo $it->getDepth() . ": $v\n"; echo "===X===\n"; $it->setMaxDepth(); var_dump($it->getMaxDepth()); foreach($it as $v) echo $it->getDepth() . ": $v\n"; echo "===3===\n"; $it->setMaxDepth(3); var_dump($it->getMaxDepth()); foreach($it as $v) echo $it->getDepth() . ": $v\n"; echo "===5===\n"; $it->setMaxDepth(5); var_dump($it->getMaxDepth()); foreach($it as $v) echo $it->getDepth() . ": $v\n"; echo "===0===\n"; $it->setMaxDepth(0); var_dump($it->getMaxDepth()); foreach($it as $v) echo $it->getDepth() . ": $v\n"; echo "===-1===\n"; $it->setMaxDepth(-1); var_dump($it->getMaxDepth()); try { $it->setMaxDepth(4); $it->setMaxDepth(-2); } catch(Exception $e) { var_dump($e->getMessage()); } var_dump($it->getMaxDepth()); ?> ===DONE=== <?php exit(0); ?> --EXPECT-- ===?=== bool(false) 0: 1 0: 2 1: 31 1: 32 2: 331 3: 3321 4: 33221 0: 4 ===2=== int(2) 0: 1 0: 2 1: 31 1: 32 2: 331 0: 4 ===X=== bool(false) 0: 1 0: 2 1: 31 1: 32 2: 331 3: 3321 4: 33221 0: 4 ===3=== int(3) 0: 1 0: 2 1: 31 1: 32 2: 331 3: 3321 0: 4 ===5=== int(5) 0: 1 0: 2 1: 31 1: 32 2: 331 3: 3321 4: 33221 0: 4 ===0=== int(0) 0: 1 0: 2 0: 4 ===-1=== bool(false) string(33) "Parameter max_depth must be >= -1" int(4) ===DONE=== -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php