Skip to content

Commit

Permalink
test: add test for value-of parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed Jun 6, 2024
1 parent cb60378 commit 90c2383
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/Functional/Type/Parser/LexingParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
use CuyZ\Valinor\Type\Parser\Exception\Iterable\ShapedArrayUnexpectedTokenAfterSealedType;
use CuyZ\Valinor\Type\Parser\Exception\Iterable\ShapedArrayWithoutElementsWithSealedType;
use CuyZ\Valinor\Type\Parser\Exception\Iterable\SimpleArrayClosingBracketMissing;
use CuyZ\Valinor\Type\Parser\Exception\Magic\ValueOfClosingBracketMissing;
use CuyZ\Valinor\Type\Parser\Exception\Magic\ValueOfIncorrectSubType;
use CuyZ\Valinor\Type\Parser\Exception\Magic\ValueOfOpeningBracketMissing;
use CuyZ\Valinor\Type\Parser\Exception\MissingClosingQuoteChar;
use CuyZ\Valinor\Type\Parser\Exception\RightIntersectionTypeMissing;
use CuyZ\Valinor\Type\Parser\Exception\RightUnionTypeMissing;
Expand Down Expand Up @@ -1613,6 +1616,46 @@ public function test_duplicated_template_name_throws_exception(): void

$this->parser->parse("$className<int, string>");
}

public function test_value_of_enum_missing_opening_bracket_throws_exception(): void
{
$this->expectException(ValueOfOpeningBracketMissing::class);
$this->expectExceptionCode(1717702268);
$this->expectExceptionMessage('The opening bracket is missing for `value-of<...>`.');

$this->parser->parse('value-of');
}

public function test_value_of_enum_missing_closing_bracket_throws_exception(): void
{
$enumName = BackedStringEnum::class;

$this->expectException(ValueOfClosingBracketMissing::class);
$this->expectExceptionCode(1717702289);
$this->expectExceptionMessage("The closing bracket is missing for `value-of<$enumName>`.");

$this->parser->parse("value-of<$enumName");
}

public function test_value_of_incorrect_type_throws_exception(): void
{
$this->expectException(ValueOfIncorrectSubType::class);
$this->expectExceptionCode(1717702683);
$this->expectExceptionMessage('Invalid subtype `value-of<string>`, it should be a `BackedEnum`.');

$this->parser->parse('value-of<string>');
}

public function test_value_of_unit_enum_type_throws_exception(): void
{
$enumName = PureEnum::class;

$this->expectException(ValueOfIncorrectSubType::class);
$this->expectExceptionCode(1717702683);
$this->expectExceptionMessage("Invalid subtype `value-of<$enumName>`, it should be a `BackedEnum`.");

$this->parser->parse("value-of<$enumName>");
}
}

/**
Expand Down

0 comments on commit 90c2383

Please sign in to comment.