~rgrjr/Spreadsheet-Table-Extract

c9af2974e04ca80c4312c689985cbbac81472878 — Bob Rogers 11 months ago 46ed3ff
Make explain_overlap smarter

* lib/Spreadsheet/Table/Extract.pm:
   + (explain_overlap):  Check whether tables are actually disjoint
     before trying to report on overlap.
* t/01-basic.t:
   + Add a test for same.
2 files changed, 7 insertions(+), 2 deletions(-)

M lib/Spreadsheet/Table/Extract.pm
M t/01-basic.t
M lib/Spreadsheet/Table/Extract.pm => lib/Spreadsheet/Table/Extract.pm +4 -1
@@ 176,7 176,10 @@ sub explain_overlap {

    my ($self_name, $other_name)
	= ($self->name || $self, $other->name || $other);
    if ($self->first_row > $other->first_row) {
    if (! ($self->overlaps($other))) {
	return 'Tables are disjoint.';
    }
    elsif ($self->first_row > $other->first_row) {
	return $other->explain_overlap($self);
    }
    elsif ($self->first_row == $other->first_row) {

M t/01-basic.t => t/01-basic.t +3 -1
@@ 3,7 3,7 @@
use strict;
use warnings;

use Test::More tests => 28;
use Test::More tests => 29;

use Spreadsheet::Table::Extract;
use Spreadsheet::Read;


@@ 124,6 124,8 @@ is($all_tables->[0]->explain_overlap($all_tables->[1]),
$check_table->make_disjoint($all_tables);
is_deeply([ map { $_->last_row; } @$all_tables ], [ 29, 40, 40],
	  "disjoint tables have correct final rows");
is($all_tables->[0]->explain_overlap($all_tables->[1]), 'Tables are disjoint.',
   'explain_overlap reports they are disjoint');
# Once again, we get the right number of entries.
@entries = $all_tables->[0]->extract
    ($book->[1], 'Spreadsheet::Table::Test::CheckbookEntry');