Commit | Line | Data |
e867486f |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test::More 'no_plan'; |
5 | $| = 1; |
6 | |
7 | |
8 | |
9 | # =begin testing |
10 | { |
951ddfe8 |
11 | use Safe::Isa; |
9fef629b |
12 | use Test::Warn; |
e867486f |
13 | use Text::Tradition; |
951ddfe8 |
14 | use TryCatch; |
e867486f |
15 | binmode STDOUT, ":utf8"; |
16 | binmode STDERR, ":utf8"; |
17 | eval { no warnings; binmode $DB::OUT, ":utf8"; }; |
18 | |
19 | my $tradition = 't/data/florilegium_graphml.xml'; |
20 | my $t = Text::Tradition->new( |
21 | 'name' => 'inline', |
22 | 'input' => 'Self', |
23 | 'file' => $tradition, |
24 | ); |
25 | |
951ddfe8 |
26 | ok( $t->$_isa('Text::Tradition'), "Parsed GraphML version 2" ); |
e867486f |
27 | if( $t ) { |
28 | is( scalar $t->collation->readings, 319, "Collation has all readings" ); |
255875b8 |
29 | is( scalar $t->collation->paths, 376, "Collation has all paths" ); |
e867486f |
30 | is( scalar $t->witnesses, 13, "Collation has all witnesses" ); |
31 | } |
bbd064a9 |
32 | |
2a812726 |
33 | # TODO add a relationship, add a stemma, write graphml, reparse it, check that |
34 | # the new data is there |
e92d4229 |
35 | my $language_enabled = $t->can('language'); |
36 | if( $language_enabled ) { |
37 | $t->language('Greek'); |
38 | } |
37bf09f4 |
39 | my $stemma_enabled = $t->can('add_stemma'); |
951ddfe8 |
40 | if( $stemma_enabled ) { |
41 | $t->add_stemma( 'dotfile' => 't/data/florilegium.dot' ); |
42 | } |
bbd064a9 |
43 | $t->collation->add_relationship( 'w12', 'w13', |
44 | { 'type' => 'grammatical', 'scope' => 'global', |
45 | 'annotation' => 'This is some note' } ); |
46 | ok( $t->collation->get_relationship( 'w12', 'w13' ), "Relationship set" ); |
47 | my $graphml_str = $t->collation->as_graphml; |
48 | |
49 | my $newt = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str ); |
951ddfe8 |
50 | ok( $newt->$_isa('Text::Tradition'), "Parsed current GraphML version" ); |
bbd064a9 |
51 | if( $newt ) { |
52 | is( scalar $newt->collation->readings, 319, "Collation has all readings" ); |
53 | is( scalar $newt->collation->paths, 376, "Collation has all paths" ); |
54 | is( scalar $newt->witnesses, 13, "Collation has all witnesses" ); |
55 | is( scalar $newt->collation->relationships, 1, "Collation has added relationship" ); |
e92d4229 |
56 | if( $language_enabled ) { |
57 | is( $newt->language, 'Greek', "Tradition has correct language setting" ); |
58 | } |
bbd064a9 |
59 | my $rel = $newt->collation->get_relationship( 'w12', 'w13' ); |
60 | ok( $rel, "Found set relationship" ); |
61 | is( $rel->annotation, 'This is some note', "Relationship has its properties" ); |
951ddfe8 |
62 | if( $stemma_enabled ) { |
63 | is( scalar $newt->stemmata, 1, "Tradition has its stemma" ); |
64 | is( $newt->stemma(0)->witnesses, $t->stemma(0)->witnesses, "Stemma has correct length witness list" ); |
65 | } |
bbd064a9 |
66 | } |
9fef629b |
67 | |
951ddfe8 |
68 | # Test warning if we can |
69 | unless( $stemma_enabled ) { |
70 | my $nst; |
71 | warnings_exist { |
72 | $nst = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/lexformat.xml' ); |
73 | } [qr/DROPPING stemmata/], |
74 | "Got expected stemma drop warning on parse"; |
75 | } |
e867486f |
76 | } |
77 | |
78 | |
79 | |
80 | |
81 | 1; |