# =begin testing
-{
use TryCatch;
use File::Temp;
use Text::Tradition;
my $fh = File::Temp->new();
my $file = $fh->filename;
+if ($ARGV[0] eq 'test.db') { unlink($file = 'test.db') }
$fh->close;
my $dsn = "dbi:SQLite:dbname=$file";
my $uuid;
'input' => 'Tabular',
'file' => 't/data/simple.txt',
);
+my $obj_dbh = DBI->connect($dsn);
+
+sub get_counts {
+ map @$_, @{$obj_dbh->selectall_arrayref(
+ 'SELECT class, COUNT(*) FROM entries GROUP BY class'
+ )};
+}
{
my $d = Text::Tradition::Directory->new( 'dsn' => $dsn,
"Exception has correct message" );
}
}
+
+my %first_counts = get_counts();
+
my $nt = Text::Tradition->new(
'name' => 'CX',
'input' => 'CollateX',
);
is( ref( $nt ), 'Text::Tradition', "Made new tradition" );
+my %second_counts;
+
{
my $f = Text::Tradition::Directory->new( 'dsn' => $dsn );
my $scope = $f->new_scope;
like( $e->message, qr/Cannot directly delete non-Tradition object/,
"Exception has correct message" );
}
+
+ %second_counts = get_counts;
$f->delete( $uuid );
ok( !$f->exists( $uuid ), "Object is deleted from DB" );
my @w2 = sort{ $a->sigil cmp $b->sigil } $nt->witnesses;
is_deeply( \@w1, \@w2, "Looked up remaining tradition by name" );
}
-}
-
+my %final_counts = get_counts();
+foreach my $class (sort keys %final_counts) {
+ my ($first, $second, $final) = map $_->{$class}, (
+ \%first_counts, \%second_counts, \%final_counts
+ );
+ cmp_ok(
+ $final, '==', ($second - $first),
+ "Final count for ${class} is $final ($second - $first)"
+ );
+}
1;