From c67190dd432a3b2742b11e4944827168ad77e3bf Mon Sep 17 00:00:00 2001 From: tla Date: Sat, 6 Dec 2014 23:19:21 +0100 Subject: [PATCH] Add test for compress_readings so that we can close #27 --- base/lib/Text/Tradition/Collation.pm | 29 ++++++++++++++++++++++++++++ base/t/text_tradition_collation.t | 29 ++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/base/lib/Text/Tradition/Collation.pm b/base/lib/Text/Tradition/Collation.pm index 84ed4397..f3f2322f 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 edced1b8..bdd329e3 100644 --- a/base/t/text_tradition_collation.t +++ b/base/t/text_tradition_collation.t @@ -117,6 +117,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;