Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/variadic intersection type #185

Merged
merged 17 commits into from
Apr 28, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 31 additions & 9 deletions tests/unit/Type/IntersectionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class IntersectionTypeTest extends TypeTest
{
public function testIntersectionLeft(): void
{
$intersection = Type\intersection(Type\array_key(), Type\int());
$intersection = Type\intersection(Type\array_key(), Type\int(), Type\positive_int());

static::assertSame(1, $intersection->coerce('1'));
}
Expand Down Expand Up @@ -53,14 +53,36 @@ public function getToStringExamples(): iterable
'Psl\Collection\IndexAccessInterface&Psl\Collection\CollectionInterface'
];

yield [Type\intersection(
Type\object(IndexAccessInterface::class),
Type\union(Type\object(CollectionInterface::class), Type\object(Iterator::class))
), 'Psl\Collection\IndexAccessInterface&(Psl\Collection\CollectionInterface|Iterator)'];
yield [
Type\intersection(
Type\object(IndexAccessInterface::class),
Type\union(
Type\object(CollectionInterface::class),
Type\object(Iterator::class)
)
),
'Psl\Collection\IndexAccessInterface&(Psl\Collection\CollectionInterface|Iterator)'
];

yield [Type\intersection(
Type\union(Type\object(CollectionInterface::class), Type\object(Iterator::class)),
Type\object(IndexAccessInterface::class)
), '(Psl\Collection\CollectionInterface|Iterator)&Psl\Collection\IndexAccessInterface'];
yield [
Type\intersection(
Type\union(
Type\object(CollectionInterface::class),
Type\object(Iterator::class)
),
Type\object(IndexAccessInterface::class)
),
'(Psl\Collection\CollectionInterface|Iterator)&Psl\Collection\IndexAccessInterface'
];

yield [
Type\intersection(
Type\object(IndexAccessInterface::class),
Type\object(CollectionInterface::class),
Type\object(Iterator::class),
Type\shape(['id' => Type\string()]),
),
Comment on lines +79 to +84
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically an impossible type, but okay :p

'Psl\Collection\IndexAccessInterface&Psl\Collection\CollectionInterface&Iterator&array{\'id\': string}'
];
}
}