Skip to content

Commit d819056

Browse files
committed
Refactored new tests, made semim optional
1 parent c3aeae4 commit d819056

File tree

8 files changed

+60
-45
lines changed

8 files changed

+60
-45
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"license": "MIT",
44
"require": {
55
"php": "^7.0",
6-
"pre/plugin": "^0.4.0"
6+
"pre/plugin": "^0.5"
77
},
88
"autoload": {
99
"files": [
@@ -14,7 +14,7 @@
1414
}
1515
},
1616
"require-dev": {
17-
"phpunit/phpunit": "^5.7"
17+
"phpunit/phpunit": "^5.0"
1818
},
1919
"autoload-dev": {
2020
"psr-4": {

src/macros.pre

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ macro ·recursion {
55
defer,
66
·between(
77
·token("{"), ·layer()·body, ·token("}")
8-
)
8+
),
9+
·optional(·token(";"))
910
)
1011
} >> {
1112
$deferred = new \Pre\Deferred\Deferred(call_user_func(function($context) {
1213
return function() use ($context) {
1314
extract($context);
1415
·body
1516
};
16-
}, get_defined_vars()))
17+
}, get_defined_vars()));
1718
}
1819

1920
macro ·recursion {
@@ -22,7 +23,8 @@ macro ·recursion {
2223
·ns()·function,
2324
·between(
2425
·token("("), ·layer()·parameters, ·token(")")
25-
)
26+
),
27+
·token(";")
2628
)
2729
} >> {
2830
$deferred = new \Pre\Deferred\Deferred(call_user_func(function() {
@@ -31,5 +33,5 @@ macro ·recursion {
3133
return function() use ($context) {
3234
call_user_func_array(→(·function), $context);
3335
};
34-
}, ·parameters))
36+
}, ·parameters));
3537
}

tests/Fixture/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/Fixture/Fixture.pre

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/MacroTest.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/SpecTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Pre\Deferred;
4+
5+
use Pre\Testing\Runner;
6+
7+
class SpecTest extends Runner
8+
{
9+
protected function path(): string
10+
{
11+
return __DIR__ . "/specs";
12+
}
13+
}

tests/bootstrap.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
namespace Yay;
4+
5+
// let's use a namespace trick, to make non-colliding variables predictable.
6+
7+
function md5($value)
8+
{
9+
return $value;
10+
}
11+
312
putenv("PRE_BASE_DIR=" . __DIR__ . "/..");
413

514
require __DIR__ . "/../vendor/autoload.php";

tests/specs/deferred.spec

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--DESCRIPTION--
2+
3+
Test deferred
4+
5+
--GIVEN--
6+
7+
defer unlink("path/to/file");
8+
9+
defer {
10+
fclose($handle);
11+
print "all done";
12+
}
13+
14+
--EXPECT--
15+
16+
$deferred·0 = new \Pre\Deferred\Deferred(call_user_func(function () {
17+
$context·0 = func_get_args();
18+
19+
return function () use ($context·0) {
20+
call_user_func_array('unlink', $context·0);
21+
};
22+
}, "path/to/file"));
23+
24+
$deferred·2 = new \Pre\Deferred\Deferred(call_user_func(function ($context·2) {
25+
return function () use ($context·2) {
26+
extract($context·2);
27+
fclose($handle);
28+
print "all done";
29+
};
30+
}, get_defined_vars()));

0 commit comments

Comments
 (0)