Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apetushok committed Apr 24, 2024
1 parent 345207e commit 9dac057
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/PackagePrivate/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,11 @@ private function buildQualification(): Qualification {

// TODO
private static function genQualificationValue( ?string $flag = null ): int {
assert( is_string( $flag ) );
return (int)( self::$map[$flag] ?? 0 );
if ( !is_string( $flag ) || !isset(self::$map[$flag]) ) {
throw new InvalidArgumentException( 'Qualifier is incorrect' );
}

return (int)self::$map[$flag];
}

private function buildSet( string $input ): Set {
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/PackagePrivate/Parser/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,27 @@ public function setOpenMiddleNonExtDateValues(): array {
[ "{2000%..2000-02}", "Dates in set ranges cannot be uncertain" ],
];
}

/**
* @dataProvider setCombinedUncertainAndApproximateQualifiers
*/
public function testThrowExceptionWhenUsedCombinedUncertainAndApproximateQualifiers( string $combinedUncertainAndApproximate ): void {
$parser = new Parser();
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessage( 'Invalid edtf format ' . $combinedUncertainAndApproximate );
$parser->createEdtf( $combinedUncertainAndApproximate );
}

public function setCombinedUncertainAndApproximateQualifiers(): array {
return [
[ '1990?~' ],
[ '1990~?' ],
[ '?~1990}' ],
[ '~?1990' ],
[ '1990-02~?' ],
[ '1990-?~02' ],
[ '1990-?~02~?-03' ],
[ '1990-02-~?03' ],
];
}
}

0 comments on commit 9dac057

Please sign in to comment.