split off stemma analysis modules from base Tradition layer
[scpubgit/stemmatology.git] / base / t / lexeme_serialize.t
CommitLineData
70745e70 1use lib 'lib';
2use strict;
3use warnings;
951ddfe8 4use Safe::Isa;
70745e70 5use Test::More;
6use Text::Tradition;
7
8eval "use Flemm";
9plan skip_all => "Flemm 3.1 required" if $@;
10
11binmode( STDOUT, ':utf8' );
12binmode( STDERR, ':utf8' );
13
14my $tf = Text::Tradition->new(
15 'input' => 'Self',
16 'file' => 't/data/besoin.xml',
17 'language' => 'French' );
18
19$tf->lemmatize();
20my $graphmlstr = $tf->collation->as_graphml;
21like( $graphmlstr, qr/graphml xmlns/,
22 "Serialized tradition after lemmatization" );
23
24my $tf2 = Text::Tradition->new(
25 input => 'Self',
26 string => $graphmlstr,
27 language => 'French' );
28
951ddfe8 29ok( $tf2->$_isa('Text::Tradition'), "Re-parsed tradition with lemmatization" );
70745e70 30is( $tf->name, $tf2->name, "Traditions have same name" );
31foreach my $r ( $tf->collation->readings ) {
32 my $r2 = $tf2->collation->reading( $r->id );
951ddfe8 33 ok( $r2->$_isa('Text::Tradition::Collation::Reading'),
70745e70 34 "Reading $r exists in new tradition" );
35 if( $r2 ) {
36 is( scalar $r->lexemes, scalar $r2->lexemes,
37 "Same number of lexemes in new tradition for $r" );
38 }
39}
40
6ba69acd 41# Test a snippet of tradition with possibly-problematic saved lexemes
42my $tf3 = Text::Tradition->new(
43 'input' => 'Self',
44 'file' => 't/data/lexformat.xml' );
951ddfe8 45ok( $tf3->$_isa('Text::Tradition'),
6ba69acd 46 "Successfully parsed tradition with incomplete lexemes" );
47
70745e70 48done_testing();