Skip to content

Commit

Permalink
Added recursion support
Browse files Browse the repository at this point in the history
  • Loading branch information
assertchris committed Jan 30, 2017
1 parent 5f66415 commit e687674
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/macros.pre
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

macro {
(···parameters) => { ···body }
macro ·recursion {
(···parameters) => {···body}
} >> {
call_user_func(function($context) {
return function(···parameters) use ($context) {
Expand Down
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Fixture.php
nested.php
13 changes: 13 additions & 0 deletions tests/MacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use PHPUnit\Framework\TestCase;

use function Pre\process;

class MacroTest extends TestCase
{
public function testShortClosures()
Expand All @@ -14,4 +16,15 @@ public function testShortClosures()

$this->assertEquals("hello chris!", $cb("chris"));
}

public function testNestedClosures()
{
$base = getenv("PRE_BASE_DIR");
$pre = __DIR__ . "/nested.pre";
$php = __DIR__ . "/nested.php";

process($base, $pre, $php);

$this->assertEquals("hello world", require $php);
}
}
11 changes: 11 additions & 0 deletions tests/nested.pre
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$cb = () => {
return () => {
return () => {
return "hello world";
};
};
};

return $cb()()();

0 comments on commit e687674

Please sign in to comment.