split off stemma analysis modules from base Tradition layer
[scpubgit/stemmatology.git] / analysis / t / text_tradition_stemma.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Test::More 'no_plan';
5 $| = 1;
6
7
8
9 # =begin testing
10 {
11 use TryCatch;
12
13 use_ok( 'Text::Tradition::Stemma' );
14
15 # Try to create a bad graph
16 TODO: {
17         local $TODO = "cannot use stdout redirection trick with FastCGI";
18         my $baddotfh;
19         open( $baddotfh, 't/data/besoin_bad.dot' ) or die "Could not open test dotfile";
20         try {
21                 my $stemma = Text::Tradition::Stemma->new( dot => $baddotfh );
22                 ok( 0, "Created broken stemma from dotfile with syntax error" );
23         } catch( Text::Tradition::Error $e ) {
24                 like( $e->message, qr/^Error trying to parse/, "Syntax error in dot threw exception" );
25         }
26 }
27
28 # Create a good graph
29 my $dotfh;
30 open( $dotfh, 't/data/florilegium.dot' ) or die "Could not open test dotfile";
31 binmode( $dotfh, ':utf8' );
32 my $stemma = Text::Tradition::Stemma->new( dot => $dotfh );
33 is( ref( $stemma ), 'Text::Tradition::Stemma', "Created stemma from good dotfile" );
34 is( scalar $stemma->witnesses, 13, "Found correct number of extant witnesses" );
35 is( scalar $stemma->hypotheticals, 8, "Found correct number of extant hypotheticals" );
36 my $found_unicode_sigil;
37 foreach my $h ( $stemma->hypotheticals ) {
38         $found_unicode_sigil = 1 if $h eq "\x{3b1}";
39 }
40 ok( $found_unicode_sigil, "Found a correctly encoded Unicode sigil" );
41
42 # TODO Create stemma from graph, create stemma from undirected graph,
43 # create stemma from incompletely-specified graph
44 }
45
46
47
48
49 1;