]> granicus.if.org Git - php/commitdiff
- Fix iterators part and add tests
authorMarcus Boerger <helly@php.net>
Wed, 10 May 2006 00:29:42 +0000 (00:29 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 10 May 2006 00:29:42 +0000 (00:29 +0000)
ext/spl/spl_iterators.c
ext/spl/tests/iterator_027.phpt [new file with mode: 0755]
ext/spl/tests/iterator_029.phpt [new file with mode: 0755]

index d99bcaeff076d789a4a6644cc840d89ccc1b3e04..22e087ff25f6b0e31dd0b9d000c5e14961ac83a3 100755 (executable)
@@ -1812,7 +1812,6 @@ SPL_METHOD(CachingIterator, offsetSet)
        spl_dual_it_object   *intern;
        char *arKey;
        uint nKeyLength;
-       zend_uchar type;
        zval *value;
 
        intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
@@ -1821,7 +1820,7 @@ SPL_METHOD(CachingIterator, offsetSet)
                zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%v does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name);
        }
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Tz", &arKey, &nKeyLength, &type, &value) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &arKey, &nKeyLength, &value) == FAILURE) {
                return;
        }
 
diff --git a/ext/spl/tests/iterator_027.phpt b/ext/spl/tests/iterator_027.phpt
new file mode 100755 (executable)
index 0000000..633c8fb
--- /dev/null
@@ -0,0 +1,113 @@
+--TEST--
+SPL: CachingIterator::FULL_CACHE
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+$ar = array(1, 2, array(31, 32, array(331)), 4);
+
+$it = new RecursiveArrayIterator($ar);
+$it = new RecursiveIteratorIterator($it);
+$it = new CachingIterator($it, CachingIterator::FULL_CACHE);
+
+foreach($it as $k=>$v)
+{
+       echo "$k=>$v\n";
+}
+
+echo "===CHECK===\n";
+
+for ($i = 0; $i < 4; $i++)
+{
+       if (isset($it[$i]))
+       {
+               var_dump($i, $it[$i]);
+       }
+}
+
+$it[2] = 'foo';
+$it[3] = 'bar';
+$it['baz'] = '25';
+
+var_dump($it[2]);
+var_dump($it[3]);
+var_dump($it['baz']);
+
+unset($it[0]);
+unset($it[2]);
+unset($it['baz']);
+
+var_dump(isset($it[0])); // unset
+var_dump(isset($it[1])); // still present
+var_dump(isset($it[2])); // unset
+var_dump(isset($it[3])); // still present
+var_dump(isset($it['baz']));
+
+echo "===REWIND===\n";
+
+$it->rewind(); // cleans and reads first element
+var_dump(isset($it[0])); // pre-fetched
+var_dump(isset($it[1])); // deleted
+var_dump(isset($it[2])); // unset
+var_dump(isset($it[3])); // deleted
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECT--
+0=>1
+1=>2
+0=>31
+1=>32
+0=>331
+3=>4
+===CHECK===
+int(0)
+int(331)
+int(1)
+int(32)
+int(3)
+int(4)
+string(3) "foo"
+string(3) "bar"
+string(2) "25"
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+===REWIND===
+bool(true)
+bool(false)
+bool(false)
+bool(false)
+===DONE===
+--UEXPECT--
+0=>1
+1=>2
+0=>31
+1=>32
+0=>331
+3=>4
+===CHECK===
+int(0)
+int(331)
+int(1)
+int(32)
+int(3)
+int(4)
+unicode(3) "foo"
+unicode(3) "bar"
+unicode(2) "25"
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+===REWIND===
+bool(true)
+bool(false)
+bool(false)
+bool(false)
+===DONE===
diff --git a/ext/spl/tests/iterator_029.phpt b/ext/spl/tests/iterator_029.phpt
new file mode 100755 (executable)
index 0000000..6ca53ef
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+SPL: RegExIterator
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+
+$ar = array(0, "123", 123, 22 => "abc", "a2b", 22, "a2d" => 7, 42);
+
+foreach(new RegExIterator(new ArrayIterator($ar), "/2/") as $k => $v)
+{
+       echo "$k=>$v\n";
+}
+
+?>
+===KEY===
+<?php
+
+foreach(new RegExIterator(new ArrayIterator($ar), "/2/", RegExIterator::USE_KEY) as $k => $v)
+{
+       echo "$k=>$v\n";
+}
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECT--
+1=>123
+2=>123
+23=>a2b
+24=>22
+25=>42
+===KEY===
+2=>123
+22=>abc
+23=>a2b
+24=>22
+a2d=>7
+25=>42
+===DONE===