Skip to content

Commit

Permalink
#30 check year better
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed May 18, 2023
1 parent 544cedc commit 22e51e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions bibcop.pl
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,14 @@ sub check_year {
my (%entry) = @_;
if (exists $entry{'year'}) {
my $year = $entry{'year'};
if (not $year =~ /^[0-9]{3,4}$/) {
return "The format of the 'year' is wrong"
if ($year =~ /^\{.+\}$/) {
return;
}
if (not $year =~ /^[0-9]+$/) {
return "The format of the 'year' is wrong, may only contain numbers or must be wrapped in curly braces"
}
if (not $year =~ /^[0-9]{4}$/) {
return "Exactly four digits must be present in the 'year', or it must be wrapped in curly braces"
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions perl-tests/checks.pl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ package bibcop;
check_passes($f, ('title' => 'Data Flow Languages and Architecture'));
check_passes($f, ('title' => 'A Preliminary Architecture for a Basic Data-Flow Processor'));

$f = 'check_year';
check_fails($f, ('year' => 'hello'));
check_fails($f, ('year' => '20019'));
check_fails($f, ('year' => '2009-2011'));
check_passes($f, ('year' => '{400 BC}'));
check_passes($f, ('year' => '2022'));
check_passes($f, ('year' => '1612'));

$f = 'check_pages';
check_fails($f, ('pages' => '1a'));
check_fails($f, ('pages' => '40A'));
Expand Down

0 comments on commit 22e51e0

Please sign in to comment.