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