Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Commit

Permalink
Remove usused code and add more unit tests for Entry
Browse files Browse the repository at this point in the history
  • Loading branch information
vikin91 committed May 2, 2019
1 parent 1aacc2c commit edf2cf7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
40 changes: 15 additions & 25 deletions lib/BibSpace/Model/Entry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -322,27 +322,24 @@ sub populate_from_bib {

return if !$self->has_valid_bibtex;

if (defined $self->bib and $self->bib ne '') {
my $bibtex_entry = new Text::BibTeX::Entry();
my $s = $bibtex_entry->parse_s($self->bib);
my $bibtex_entry = new Text::BibTeX::Entry();
my $s = $bibtex_entry->parse_s($self->bib);

$self->bibtex_key($bibtex_entry->key);
my $year_str = $bibtex_entry->get('year');
if (Scalar::Util::looks_like_number($year_str)) {
$self->year($year_str);
}
$self->bibtex_key($bibtex_entry->key);
my $year_str = $bibtex_entry->get('year');
if (Scalar::Util::looks_like_number($year_str)) {
$self->year($year_str);
}

if ($bibtex_entry->exists('booktitle')) {
$self->title($bibtex_entry->get('booktitle'));
}
if ($bibtex_entry->exists('title')) {
$self->title($bibtex_entry->get('title'));
}
$self->abstract($bibtex_entry->get('abstract') || undef);
$self->_bibtex_type($bibtex_entry->type);
return 1;
if ($bibtex_entry->exists('booktitle')) {
$self->title($bibtex_entry->get('booktitle'));
}
return;
if ($bibtex_entry->exists('title')) {
$self->title($bibtex_entry->get('title'));
}
$self->abstract($bibtex_entry->get('abstract') || undef);
$self->_bibtex_type($bibtex_entry->type);
return 1;
}

sub add_bibtex_field {
Expand Down Expand Up @@ -586,13 +583,6 @@ sub has_author {
return defined $authorship;
}

sub has_master_author {
my $self = shift;
my $author = shift;

return $self->has_author($author->get_master);
}

sub author_names_from_bibtex {
my $self = shift;

Expand Down
30 changes: 26 additions & 4 deletions t/100-unit/Entry.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ my $repo = $self->app->repo;

my @all_entries = $repo->entries_all;

my $limit_test_entries = 20;
my $limit_test_entries = 10;

note "============ Testing " . scalar(@all_entries) . " Entries ============";

foreach my $entry (@all_entries) {
last if $limit_test_entries < 0;
note ">> Testing Entry ID " . $entry->id . ".";

ok($entry->equals($entry), "Entry is equal to itself");
dies_ok(sub { $entry->equals(undef) }, 'equals undef expecting to die');

ok($entry->equals_bibtex($entry), "Entry is equal_bibtex to itself");
dies_ok(
sub { $entry->equals_bibtex(undef) },
'equal_bibtex undef expecting to die'
);

$entry->make_paper;
ok($entry->is_paper);
$entry->make_talk;
Expand Down Expand Up @@ -54,8 +63,7 @@ foreach my $entry (@all_entries) {
ok($entry->fix_month, "month fixed");
is($entry->month, 4, "month fixed correctly");

if ($entry->has_bibtex_field('author') or $entry->has_bibtex_field('editor'))
{
if ($entry->has_bibtex_field('author')) {
my @author_names = $entry->author_names_from_bibtex;
ok(scalar @author_names > 0, "Entry has authors in bibtex");
}
Expand All @@ -65,6 +73,21 @@ foreach my $entry (@all_entries) {
is(scalar @author_names, 1, "Entry has 1 author in bibtex");
}

note "Testing case where there are no authors but there are editors";
$entry->remove_bibtex_fields(['author']);
if ($entry->has_bibtex_field('editor')) {
my @author_names = $entry->author_names_from_bibtex;
ok(scalar @author_names > 0, "Entry has editors in bibtex");
}
else {
$entry->add_bibtex_field("editor", "James Bond");
my @author_names = $entry->author_names_from_bibtex;
is(scalar @author_names, 1, "Entry has 1 editor in bibtex");
}

# readd removed field
$entry->add_bibtex_field("author", "James Bond");

if ($entry->has_bibtex_field('tags')) {
is($entry->remove_bibtex_fields(['tags']), 1, "remove tags bibtex field");
my @no_tag_names = $entry->tag_names_from_bibtex;
Expand All @@ -89,5 +112,4 @@ foreach my $entry (@all_entries) {
my $broken_entry = $self->app->entityFactory->new_Entry(bib => ' ');
$broken_entry->regenerate_html(1, $self->app->bst, $self->app->bibtexConverter);

ok(1);
done_testing();

0 comments on commit edf2cf7

Please sign in to comment.