return the new reading generated on duplication
[scpubgit/stemmatology.git] / base / t / text_tradition_parser_self.t
CommitLineData
e867486f 1#!/usr/bin/perl -w
2
3use strict;
4use Test::More 'no_plan';
5$| = 1;
6
7
8
9# =begin testing
10{
951ddfe8 11use Safe::Isa;
9fef629b 12use Test::Warn;
e867486f 13use Text::Tradition;
951ddfe8 14use TryCatch;
e867486f 15binmode STDOUT, ":utf8";
16binmode STDERR, ":utf8";
17eval { no warnings; binmode $DB::OUT, ":utf8"; };
18
19my $tradition = 't/data/florilegium_graphml.xml';
20my $t = Text::Tradition->new(
21 'name' => 'inline',
22 'input' => 'Self',
23 'file' => $tradition,
24 );
25
951ddfe8 26ok( $t->$_isa('Text::Tradition'), "Parsed GraphML version 2" );
e867486f 27if( $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 35my $language_enabled = $t->can('language');
36if( $language_enabled ) {
37 $t->language('Greek');
38}
37bf09f4 39my $stemma_enabled = $t->can('add_stemma');
951ddfe8 40if( $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' } );
46ok( $t->collation->get_relationship( 'w12', 'w13' ), "Relationship set" );
47my $graphml_str = $t->collation->as_graphml;
48
49my $newt = Text::Tradition->new( 'input' => 'Self', 'string' => $graphml_str );
951ddfe8 50ok( $newt->$_isa('Text::Tradition'), "Parsed current GraphML version" );
bbd064a9 51if( $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
69unless( $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
811;