Skip to content

Commit

Permalink
Add test for compress_readings so that we can close #27
Browse files Browse the repository at this point in the history
  • Loading branch information
tla committed Dec 6, 2014
1 parent 6e6d1e2 commit c67190d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions base/lib/Text/Tradition/Collation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 29 additions & 0 deletions base/t/text_tradition_collation.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c67190d

Please sign in to comment.