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

Additional check for QualificationValue #100

Merged
merged 5 commits into from
Apr 25, 2024
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
12 changes: 6 additions & 6 deletions config/regex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Year start
^(?<year>
(?<yearOpenFlag>[~?%]{0,2})
(?<yearOpenFlag>[~?%]{0,1})
Y?
(?<yearNum>
[+-]? # optional sign
Expand All @@ -14,32 +14,32 @@
(?>S # Literal S letter. It is for the significant digit indicator
(?<yearSignificantDigit>\d+)
)?
(?<yearCloseFlag>\)?[~%?]{0,2})
(?<yearCloseFlag>\)?[~%?]{0,1})
)
# Year end

(?>- # Literal - (hyphen)

# Month start
(?<month>
(?<monthOpenFlag>[~?%]{0,2})
(?<monthOpenFlag>[~?%]{0,1})
(?<monthOpenParents>\(+)?
(?<monthNum>(?>1[0-9UX]|[0UX][0-9UX]|[0-9][0-9]))
(?>\^(?<seasonQualifier>[\P{L}\P{N}\P{M}:.-]+))?
(?<monthCloseFlag>[~?%]{0,2})
(?<monthCloseFlag>[~?%]{0,1})
)
# Month end

(?>- # Begin Day Literal - (hyphen)
# Day start
(?<day>
(?<dayOpenFlag>[~?%]{0,2})
(?<dayOpenFlag>[~?%]{0,1})
(?<dayOpenParents>\(+)?
(?<dayNum>
(?>[012UX][0-9UX]|3[01UX])
)
)
(?<dayCloseFlag>[~?%]{0,2})
(?<dayCloseFlag>[~?%]{0,1})
apetushok marked this conversation as resolved.
Show resolved Hide resolved
(?<dayEnd>[)~%?]*)
# Day end

Expand Down
5 changes: 4 additions & 1 deletion src/PackagePrivate/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ private function buildQualification(): Qualification {

// TODO
private static function genQualificationValue( ?string $flag = null ): int {
assert( is_string( $flag ) );
if ( !is_string( $flag ) || !array_key_exists( $flag, self::$map ) ) {
throw new InvalidArgumentException( 'Qualifier is invalid' );
}

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

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 provideCombinedUncertainAndApproximateQualifiers
*/
public function testThrowExceptionWhenUsedCombinedUncertainAndApproximateQualifiers( string $combinedUncertainAndApproximate ): void {
$parser = new Parser();
$this->expectException( InvalidArgumentException::class );
$this->expectExceptionMessage( 'Invalid edtf format ' . $combinedUncertainAndApproximate );
$parser->createEdtf( $combinedUncertainAndApproximate );
}

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