Skip to content

Commit

Permalink
#82 posix instead
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Mar 17, 2024
1 parent 7524606 commit 85c9433
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 39 deletions.
4 changes: 2 additions & 2 deletions bibcop.pl
Expand Up @@ -26,8 +26,8 @@ package bibcop;

use warnings;
use strict;
use POSIX;
use File::Basename;
use Time::Piece;

# Hash of incoming command line arguments.
my %args = map { $_ => 1 } @ARGV;
Expand Down Expand Up @@ -543,7 +543,7 @@ sub entry_fix {
}
my $value = clean_tex($entry{$tag});
if ($tag eq 'url') {
my $today = localtime->strftime('%d-%m-%Y');
my $today = strftime('%d-%m-%Y', localtime(time));
push(@lines, " howpublished = {\\url{$value}},");
push(@lines, " note = {[Online; accessed $today]},");
next;
Expand Down
5 changes: 3 additions & 2 deletions perl-tests/entry_fixing.pl
Expand Up @@ -25,14 +25,15 @@ package bibcop;

use strict;
use warnings;
use Time::Piece;

use POSIX;

require './bibcop.pl';

fixes_entry({':name' => 'knuth78', ':type' => 'book', 'title' => 'The TeX Book'}, "\@book{knuth78,\n title = {{The TeX Book}},\n}\n\n");
fixes_entry({':name' => 'k', ':type' => 'article', 'title' => 'Book', 'pages' => ''}, "\@article{k,\n title = {{Book}},\n}\n\n");

my $today = localtime->strftime('%d-%m-%Y');
my $today = strftime('%d-%m-%Y', localtime(time));
fixes_entry({':name' => 'f', ':type' => 'misc', 'url' => 'http://google.com'}, "\@misc{f,\n howpublished = {\\url{http://google.com}},\n note = {[Online; accessed $today]},\n}\n\n");

fixes_entry({':name' => 'f', ':type' => 'article', 'booktitle' => 'ONE'}, "\@article{f,\n journal = {{ONE}},\n}\n\n");
Expand Down
14 changes: 7 additions & 7 deletions perl-tests/functions.pl
Expand Up @@ -26,12 +26,12 @@ package bibcop;
use strict;
use warnings;

assert(clean_tex('Hello, \LaTeX{}!'), 'Hello, \LaTeX{}!');
assert(clean_tex("Hello,\n\\TeX{}!"), 'Hello, \TeX{}!');
assert(clean_tex(" Gamma!"), 'Gamma!');
assert(clean_tex("Hello! "), 'Hello!');
assert(clean_tex('{Alpha}'), 'Alpha');
assert(clean_tex('{{Beta}}'), 'Beta');
assert(clean_tex('Hello, {world!}'), 'Hello, {world!}');
assert_eq(clean_tex('Hello, \LaTeX{}!'), 'Hello, \LaTeX{}!');
assert_eq(clean_tex("Hello,\n\\TeX{}!"), 'Hello, \TeX{}!');
assert_eq(clean_tex(" Gamma!"), 'Gamma!');
assert_eq(clean_tex("Hello! "), 'Hello!');
assert_eq(clean_tex('{Alpha}'), 'Alpha');
assert_eq(clean_tex('{{Beta}}'), 'Beta');
assert_eq(clean_tex('Hello, {world!}'), 'Hello, {world!}');

1;
54 changes: 27 additions & 27 deletions perl-tests/parsing.pl
Expand Up @@ -28,56 +28,56 @@ package bibcop;

my @i1 = entries('@Misc{knuth-1984:x, author ={Donald Knuth}, Title="The TeX Book "}');
# show(@i1);
assert(@i1+0, 1);
assert($i1[0]{':name'}, 'knuth-1984:x');
assert($i1[0]{':type'}, 'Misc');
assert($i1[0]{'author'}, 'Donald Knuth');
assert($i1[0]{'title'}, 'The TeX Book ');
assert_eq(@i1+0, 1);
assert_eq($i1[0]{':name'}, 'knuth-1984:x');
assert_eq($i1[0]{':type'}, 'Misc');
assert_eq($i1[0]{'author'}, 'Donald Knuth');
assert_eq($i1[0]{'title'}, 'The TeX Book ');

my @i2 = entries('@misc{patrick, author={{Patrick S\:{u}skind}},}');
# show(@i2);
assert(@i2+0, 1);
assert($i2[0]{'author'}, '{Patrick S\:{u}skind}');
assert_eq(@i2+0, 1);
assert_eq($i2[0]{'author'}, '{Patrick S\:{u}skind}');

my @i3 = entries('@misc{p1} @article{p2,author="Jeff"} ');
# show(@i3);
assert(@i3+0, 2);
assert($i3[0]{':name'}, 'p1');
assert($i3[1]{':name'}, 'p2');
assert($i3[1]{'author'}, 'Jeff');
assert_eq(@i3+0, 2);
assert_eq($i3[0]{':name'}, 'p1');
assert_eq($i3[1]{':name'}, 'p2');
assert_eq($i3[1]{'author'}, 'Jeff');

my @i4 = entries('@misc{x1, year = 1989 }');
# show(@i4);
assert(@i4+0, 1);
assert($i4[0]{'year'}, '1989');
assert_eq(@i4+0, 1);
assert_eq($i4[0]{'year'}, '1989');

my @i5 = entries('@misc{x2,year=2021,}');
# show(@i5);
assert(@i5+0, 1);
assert($i5[0]{'year'}, '2021');
assert_eq(@i5+0, 1);
assert_eq($i5[0]{'year'}, '2021');

my @i6 = entries('@misc{x2,year=2021,year=1989}');
# show(@i6);
assert(@i6+0, 1);
assert($i6[0]{'year'}, '2021');
assert_eq(@i6+0, 1);
assert_eq($i6[0]{'year'}, '2021');

my @i7 = entries("\% a comment\n \@misc{7}\n");
# show(@i7);
assert(@i7+0, 1);
assert_eq(@i7+0, 1);

my @i8 = entries("\@misc{foo33, title={It's 100\\% true!}}\n");
# show(@i8);
assert(@i8+0, 1);
assert_eq(@i8+0, 1);

# These are all parsing errors
assert(entries('no bibs')+0, 0);
assert(entries('@misc{---}')+0, 0);
assert(entries('@misc{hello, ??}')+0, 0);
assert_eq(entries('no bibs')+0, 0);
assert_eq(entries('@misc{---}')+0, 0);
assert_eq(entries('@misc{hello, ??}')+0, 0);

assert(entries('')+0, 0);
assert(entries('@misc{k1,a={{x}{y}{}},b="{f}{x}",}')+0, 1);
assert(entries('@article{k1_34} @misc{do43ss,Title=,Year=1998}')+0, 2);
assert(entries("\@article{t1}\n\n\n\@misc{ff,year=1998}")+0, 2);
assert(entries('@misc{42i-88/7.7,a=hello}')+0, 1);
assert_eq(entries('')+0, 0);
assert_eq(entries('@misc{k1,a={{x}{y}{}},b="{f}{x}",}')+0, 1);
assert_eq(entries('@article{k1_34} @misc{do43ss,Title=,Year=1998}')+0, 2);
assert_eq(entries("\@article{t1}\n\n\n\@misc{ff,year=1998}")+0, 2);
assert_eq(entries('@misc{42i-88/7.7,a=hello}')+0, 1);

1;
2 changes: 1 addition & 1 deletion tests.pl
Expand Up @@ -27,7 +27,7 @@ package bibcop;
use strict;

# Assert on the value and exit if error.
sub assert {
sub assert_eq {
my ($l, $r) = @_;
if ($l ne $r) {
print "'$l' ne '$r'\n";
Expand Down

0 comments on commit 85c9433

Please sign in to comment.