com php-src: Add first real generator test: Zend/tests/generators/xrange.phpt
| From: | Gustavo André dos Santos Lopes | Date: | Sat, 26 May 2012 22:50:27 +0000 |
| Subject: | com php-src: Add first real generator test: Zend/tests/generators/xrange.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-70070@lists.php.net to get a copy of this message | ||
Commit: 39d3d5ec138119acf614fb285e92c3bcda7a2555
Author: Nikita Popov <nikic@php.net> Sun, 27 May 2012 00:50:27 +0200
Parents: cbfa96cad59d679502eca002a1e920065f11f871
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=39d3d5ec138119acf614fb285e92c3bcda7a2555
Log:
Add first real generator test
The test implements an xrange() function (the generator version of range()).
Changed paths:
A Zend/tests/generators/xrange.phpt
Diff:
diff --git a/Zend/tests/generators/xrange.phpt b/Zend/tests/generators/xrange.phpt
new file mode 100644
index 0000000..685c6b3
--- /dev/null
+++ b/Zend/tests/generators/xrange.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Simple generator xrange() test
+--FILE--
+<?php
+
+function *xrange($start, $end, $step = 1) {
+ for ($i = $start; $i <= $end; $i += $step) {
+ yield $i;
+ }
+}
+
+foreach (xrange(10, 20, 2) as $i) {
+ var_dump($i);
+}
+
+?>
+--EXPECT--
+int(10)
+int(12)
+int(14)
+int(16)
+int(18)
+int(20)