-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
288 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
return Innmind\CodingStandard\CodingStandard::config([ | ||
'tests', | ||
'proofs', | ||
'src', | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
use Innmind\BlackBox\{ | ||
Application, | ||
Runner\Load, | ||
Runner\CodeCoverage, | ||
}; | ||
|
||
Application::new($argv) | ||
->when( | ||
\getenv('ENABLE_COVERAGE') !== false, | ||
static fn(Application $app) => $app | ||
->codeCoverage( | ||
CodeCoverage::of( | ||
__DIR__.'/src/', | ||
__DIR__.'/proofs/', | ||
) | ||
->dumpTo('coverage.clover') | ||
->enableWhen(true), | ||
) | ||
->scenariiPerProof(1), | ||
) | ||
->tryToProve(Load::everythingIn(__DIR__.'/proofs/')) | ||
->exit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
use Innmind\Mantle\{ | ||
Forerunner, | ||
Source\Predetermined, | ||
Task, | ||
}; | ||
use Innmind\OperatingSystem\Factory; | ||
use Innmind\TimeContinuum\Earth\Period\Second; | ||
use Innmind\Filesystem\Name; | ||
use Innmind\Url\Path; | ||
use Innmind\Immutable\Sequence; | ||
use Innmind\BlackBox\Set; | ||
use Innmind\BlackBox\Tag; | ||
|
||
return static function() { | ||
yield test( | ||
'Halting multiple tasks', | ||
static function($assert) { | ||
$expect = $assert->time(static function() { | ||
Forerunner::of(Factory::build())(null, Predetermined::of( | ||
static fn($os) => $os->process()->halt(Second::of(1)), | ||
static fn($os) => $os->process()->halt(Second::of(1)), | ||
static fn($os) => $os->process()->halt(Second::of(1)), | ||
)); | ||
}); | ||
$expect | ||
->inLessThan() | ||
->seconds(2); | ||
$expect | ||
->inMoreThan() | ||
->seconds(1); | ||
}, | ||
); | ||
|
||
yield proof( | ||
'Carry value via the source', | ||
given( | ||
Set\Type::any(), | ||
Set\Type::any(), | ||
), | ||
static function($assert, $initial, $modified) { | ||
$returned = Forerunner::of(Factory::build())( | ||
$initial, | ||
static fn($_, $__, $continuation) => $continuation->terminate(), | ||
); | ||
$assert->same($initial, $returned); | ||
|
||
$returned = Forerunner::of(Factory::build())( | ||
$initial, | ||
static fn($carry, $__, $continuation) => $continuation | ||
->carryWith($initial) | ||
->terminate(), | ||
); | ||
$assert->same($initial, $returned); | ||
|
||
$returned = Forerunner::of(Factory::build())( | ||
$initial, | ||
static fn($carry, $__, $continuation) => $continuation | ||
->carryWith($modified) | ||
->terminate(), | ||
); | ||
$assert->same($modified, $returned); | ||
}, | ||
); | ||
|
||
yield test( | ||
'The source is run asynchronously', | ||
static function($assert) { | ||
$expect = $assert->time(static function() { | ||
Forerunner::of(Factory::build())( | ||
false, | ||
static fn($started, $os, $continuation, $results) => match ([$started, $results->size()]) { | ||
[false, 0] => $continuation | ||
->launch(Sequence::of( | ||
Task::of(static function($os) { | ||
$os->process()->halt(Second::of(1)); | ||
$os->process()->halt(Second::of(1)); | ||
}), | ||
Task::of(static function($os) { | ||
$os->process()->halt(Second::of(1)); | ||
$os->process()->halt(Second::of(1)); | ||
}), | ||
Task::of(static function($os) { | ||
$os->process()->halt(Second::of(1)); | ||
$os->process()->halt(Second::of(1)); | ||
}), | ||
)) | ||
->carryWith(true), | ||
[true, 0] => (static function($os, $continuation) { | ||
// this halt is executed at the same time at the | ||
// second one in each task | ||
$os->process()->halt(Second::of(1)); | ||
|
||
return $continuation; | ||
})($os, $continuation), | ||
default => $continuation->terminate(), | ||
}, | ||
); | ||
}); | ||
$expect | ||
->inLessThan() | ||
->seconds(3); | ||
$expect | ||
->inMoreThan() | ||
->seconds(2); | ||
}, | ||
); | ||
|
||
yield test( | ||
'Streams are handled asynchronously', | ||
static function($assert) { | ||
$lines = []; | ||
Forerunner::of(Factory::build())(null, Predetermined::of( | ||
static function($os) use ($assert, &$lines) { | ||
$file = $os | ||
->filesystem() | ||
->mount(Path::of('./')) | ||
->get(Name::of('composer.json')) | ||
->match( | ||
static fn($file) => $file, | ||
static fn() => null, | ||
); | ||
$assert->not()->null($file); | ||
$lines[] = $file | ||
->content() | ||
->lines() | ||
->first() | ||
->match( | ||
static fn($line) => $line->toString(), | ||
static fn() => null, | ||
); | ||
$lines[] = $file | ||
->content() | ||
->lines() | ||
->filter(static fn($line) => !$line->str()->empty()) | ||
->last() | ||
->match( | ||
static fn($line) => $line->toString(), | ||
static fn() => null, | ||
); | ||
}, | ||
static function($os) use ($assert, &$lines) { | ||
$file = $os | ||
->filesystem() | ||
->mount(Path::of('./')) | ||
->get(Name::of('LICENSE')) | ||
->match( | ||
static fn($file) => $file, | ||
static fn() => null, | ||
); | ||
$assert->not()->null($file); | ||
$lines[] = $file | ||
->content() | ||
->lines() | ||
->first() | ||
->match( | ||
static fn($line) => $line->toString(), | ||
static fn() => null, | ||
); | ||
$lines[] = $file | ||
->content() | ||
->lines() | ||
->filter(static fn($line) => !$line->str()->empty()) | ||
->last() | ||
->match( | ||
static fn($line) => $line->toString(), | ||
static fn() => null, | ||
); | ||
}, | ||
)); | ||
$assert->same( | ||
['{', 'MIT License', 'SOFTWARE.', '}'], | ||
$lines, | ||
); | ||
}, | ||
)->tag(Tag::wip); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters