From: tla Date: Sat, 6 Dec 2014 22:19:21 +0000 (+0100) Subject: Add test for compress_readings so that we can close #27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c67190dd432a3b2742b11e4944827168ad77e3bf;p=scpubgit%2Fstemmatology.git Add test for compress_readings so that we can close #27 --- diff --git a/base/lib/Text/Tradition/Collation.pm b/base/lib/Text/Tradition/Collation.pm index 84ed439..f3f2322 100644 --- a/base/lib/Text/Tradition/Collation.pm +++ b/base/lib/Text/Tradition/Collation.pm @@ -538,6 +538,35 @@ readings must also not be marked as nonsense or bad grammar. WARNING: This operation cannot be undone. +=begin testing + +use Text::Tradition; + +my $t = Text::Tradition->new( input => 'CollateX', file => 't/data/CollateX-16.xml' ); +my $c = $t->collation; +my $n = scalar $c->readings; +$c->compress_readings(); +is( scalar $c->readings, $n - 6, "Compressing readings seems to work" ); + +# Now put in a join-word and make sure the thing still works. +my $t2 = Text::Tradition->new( input => 'CollateX', file => 't/data/CollateX-16.xml' ); +my $c2 = $t2->collation; +# Split n21 ('unto') for testing purposes +my $new_r = $c2->add_reading( { 'id' => 'n21p0', 'text' => 'un', 'join_next' => 1 } ); +my $old_r = $c2->reading( 'n21' ); +$old_r->alter_text( 'to' ); +$c2->del_path( 'n20', 'n21', 'A' ); +$c2->add_path( 'n20', 'n21p0', 'A' ); +$c2->add_path( 'n21p0', 'n21', 'A' ); +$c2->calculate_ranks(); +is( scalar $c2->readings, $n + 1, "We have our extra test reading" ); +$c2->compress_readings(); +is( scalar $c2->readings, $n - 6, "Compressing readings also works with join_next" ); +is( $c2->reading( 'n21p0' )->text, 'unto', "The joined word has no space" ); + + +=end testing + =cut sub compress_readings { diff --git a/base/t/text_tradition_collation.t b/base/t/text_tradition_collation.t index edced1b..bdd329e 100644 --- a/base/t/text_tradition_collation.t +++ b/base/t/text_tradition_collation.t @@ -119,6 +119,35 @@ try { # =begin testing { +use Text::Tradition; + +my $t = Text::Tradition->new( input => 'CollateX', file => 't/data/CollateX-16.xml' ); +my $c = $t->collation; +my $n = scalar $c->readings; +$c->compress_readings(); +is( scalar $c->readings, $n - 6, "Compressing readings seems to work" ); + +# Now put in a join-word and make sure the thing still works. +my $t2 = Text::Tradition->new( input => 'CollateX', file => 't/data/CollateX-16.xml' ); +my $c2 = $t2->collation; +# Split n21 ('unto') for testing purposes +my $new_r = $c2->add_reading( { 'id' => 'n21p0', 'text' => 'un', 'join_next' => 1 } ); +my $old_r = $c2->reading( 'n21' ); +$old_r->alter_text( 'to' ); +$c2->del_path( 'n20', 'n21', 'A' ); +$c2->add_path( 'n20', 'n21p0', 'A' ); +$c2->add_path( 'n21p0', 'n21', 'A' ); +$c2->calculate_ranks(); +is( scalar $c2->readings, $n + 1, "We have our extra test reading" ); +$c2->compress_readings(); +is( scalar $c2->readings, $n - 6, "Compressing readings also works with join_next" ); +is( $c2->reading( 'n21p0' )->text, 'unto', "The joined word has no space" ); +} + + + +# =begin testing +{ use Test::More::UTF8; use Text::Tradition; use TryCatch;