Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion fixtures/Authority.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public static function any(): Set
Authority\Port::any(),
Set::of(Model\Port::none()),
),
);
)
->exclude(
static fn($authority) => !$authority->userInformation()->equals(Model\UserInformation::none()) &&
$authority->host()->equals(Model\Host::none()),
);
}
}
40 changes: 37 additions & 3 deletions fixtures/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

namespace Fixtures\Innmind\Url;

use Innmind\Url\Path as Model;
use Innmind\Url\{
Path as Model,
Url,
};
use Innmind\BlackBox\Set;

final class Path
Expand All @@ -13,7 +16,32 @@ final class Path
*/
public static function any(): Set
{
return self::strings()->map(Model::of(...));
return Set::either(
self::relative(),
self::absolute(),
);
}

/**
* @return Set<Model>
*/
public static function relative(): Set
{
return self::strings()
->map(static fn($value) => \ltrim($value, '/'))
->exclude(static fn($value) => \str_ends_with($value, '\\'))
->map(Model::of(...));
}

/**
* @return Set<Model>
*/
public static function absolute(): Set
{
return self::strings()
->map(static fn($value) => '/'.\ltrim($value, '/'))
->exclude(static fn($value) => \str_ends_with($value, '\\'))
->map(Model::of(...));
}

/**
Expand Down Expand Up @@ -46,7 +74,13 @@ private static function strings(): Set
)
->filter(static fn($value) => (bool) \preg_match('~\S+~', $value))
->exclude(static fn($value) => \str_contains($value, '//'))
->exclude(static fn($value) => \str_contains($value, '\\@'))
->exclude(static fn($value) => \str_starts_with($value, '\\'))
->map(static fn($value) => \trim($value, ' '));
->map(static fn($value) => \trim($value, ' '))
->exclude(static fn($value) => $value === '')
->filter(static fn($value) => Url::attempt($value)->match(
static fn() => true,
static fn() => false,
));
}
}
61 changes: 58 additions & 3 deletions fixtures/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Innmind\Url\{
Url as Model,
Scheme as SchemeModel,
Authority as AuthorityModel,
Path as PathModel,
Query as QueryModel,
Expand All @@ -19,15 +20,21 @@ final class Url
*/
public static function any(): Set
{
return Set::compose(
$url = Set::compose(
Model::from(...),
Scheme::any(),
Set::either(
Scheme::any(),
Set::of(
SchemeModel::none(),
SchemeModel::less(),
),
),
Set::either(
Authority::any(),
Set::of(AuthorityModel::none()),
),
Set::either(
Path::any(),
Path::absolute(),
Set::of(PathModel::none()),
),
Set::either(
Expand All @@ -38,6 +45,54 @@ public static function any(): Set
Fragment::any(),
Set::of(FragmentModel::none()),
),
)
->exclude(
static fn($url) => !$url->authority()->port()->equals(AuthorityModel\Port::none()) && (
$url->authority()->host()->equals(AuthorityModel\Host::none()) ||
$url->scheme()->equals(SchemeModel::none())
),
)
->exclude(
static fn($url) => !$url->query()->equals(QueryModel::none()) &&
$url->path()->equals(PathModel::none()),
)
->exclude(
static fn($url) => !$url->fragment()->equals(FragmentModel::none()) &&
$url->path()->equals(PathModel::none()),
)
->exclude(
static fn($url) => $url->scheme()->equals(SchemeModel::less()) &&
$url->authority()->equals(AuthorityModel::none()),
)
->exclude(
static fn($url) => $url->authority()->equals(AuthorityModel::none()) && !(
$url->scheme()->equals(SchemeModel::none()) ||
$url->scheme()->equals(SchemeModel::less())
),
)
->exclude(
static fn($url) => !$url->scheme()->equals(SchemeModel::none()) &&
$url->authority()->port()->value() > 65535,
);
$path = Path::relative()->map(
static fn($path) => Model::from(
SchemeModel::none(),
AuthorityModel::none(),
$path,
QueryModel::none(),
FragmentModel::none(),
),
);
$file = Path::absolute()->map(
static fn($path) => Model::from(
SchemeModel::of('file'),
AuthorityModel::none(),
$path,
QueryModel::none(),
FragmentModel::none(),
),
);

return Set::either($url, $path, $file);
}
}
22 changes: 22 additions & 0 deletions tests/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,28 @@ public function testParsingIdempotencyOfPartiallyEncodedUrls()
);
}

public function testAnyUrlFixtureCanBeParsed(): BlackBox\Proof
{
return $this
->forAll(Fixture::any())
->prove(function($url) {
$this->assert()->not()->throws(
static fn() => Url::of($url->toString()),
);
});
}

public function testAnyUrlsCanBeResolved(): BlackBox\Proof
{
return $this
->forAll(Fixture::any(), Fixture::any())
->prove(function($a, $b) {
$this->assert()->not()->throws(
static fn() => $a->resolve($b)->unwrap(),
);
});
}

public static function cases(): array
{
return [
Expand Down
Loading