]> granicus.if.org Git - php/commitdiff
- Add tests for the examples
authorMarcus Boerger <helly@php.net>
Wed, 28 Apr 2004 20:10:21 +0000 (20:10 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 28 Apr 2004 20:10:21 +0000 (20:10 +0000)
ext/spl/examples/tests/examples.inc [new file with mode: 0755]
ext/spl/examples/tests/iterators_001.phpt [new file with mode: 0755]
ext/spl/examples/tests/iterators_002.phpt [new file with mode: 0755]

diff --git a/ext/spl/examples/tests/examples.inc b/ext/spl/examples/tests/examples.inc
new file mode 100755 (executable)
index 0000000..da7016e
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+class IncludeFiles extends ArrayIterator
+{
+       function __construct($path, $classes)
+       {
+               parent::__construct();
+               foreach($classes as $c)
+               {
+                       $this->append($path . '/' . strtolower($c) . '.inc');
+               }
+       }
+}
+
+$classes = array(
+       'EmptyIterator',
+       'InfiniteIterator',
+);
+
+foreach (new IncludeFiles(dirname(__FILE__). '/..', $classes) as $file)
+{
+       require_once($file);
+}
+
+?>
\ No newline at end of file
diff --git a/ext/spl/examples/tests/iterators_001.phpt b/ext/spl/examples/tests/iterators_001.phpt
new file mode 100755 (executable)
index 0000000..5b4a6ff
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+SPL: EmptyIterator
+--FILE--
+<?php
+
+require_once('examples.inc');
+
+echo "===EmptyIterator===\n";
+
+foreach(new LimitIterator(new EmptyIterator(), 0, 3) as $key => $val)
+{
+       echo "$key=>$val\n";
+}
+
+?>
+===DONE===
+<?php exit(0);
+--EXPECTF--
+===EmptyIterator===
+===DONE===
diff --git a/ext/spl/examples/tests/iterators_002.phpt b/ext/spl/examples/tests/iterators_002.phpt
new file mode 100755 (executable)
index 0000000..dcbaa9c
--- /dev/null
@@ -0,0 +1,53 @@
+--TEST--
+SPL: InfiniteIterator
+--FILE--
+<?php
+
+require_once('examples.inc');
+
+echo "===EmptyIterator===\n";
+
+foreach(new LimitIterator(new InfiniteIterator(new EmptyIterator()), 0, 3) as $key=>$val)
+{
+       echo "$key=>$val\n";
+}
+
+echo "===InfiniteIterator===\n";
+
+$it = new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D'));
+$it = new InfiniteIterator($it);
+$it = new LimitIterator($it, 2, 5);
+foreach($it as $val=>$key)
+{
+       echo "$val=>$key\n";
+}
+
+echo "===Infinite/LimitIterator===\n";
+
+$it = new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D'));
+$it = new LimitIterator($it, 1, 2);
+$it = new InfiniteIterator($it);
+$it = new LimitIterator($it, 2, 5);
+foreach($it as $val=>$key)
+{
+       echo "$val=>$key\n";
+}
+
+?>
+===DONE===
+<?php exit(0);
+--EXPECTF--
+===EmptyIterator===
+===InfiniteIterator===
+2=>C
+3=>D
+0=>A
+1=>B
+2=>C
+===Infinite/LimitIterator===
+1=>B
+2=>C
+1=>B
+2=>C
+1=>B
+===DONE===