Commit | Line | Data |
64a36834 |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test::More 'no_plan'; |
5 | $| = 1; |
6 | |
7 | |
8 | |
9 | # =begin testing |
10 | { |
64a36834 |
11 | use TryCatch; |
12 | |
13 | use_ok( 'Text::Tradition::Stemma' ); |
14 | |
64a36834 |
15 | # Try to create a bad graph |
02b6340e |
16 | my $baddotfh; |
17 | open( $baddotfh, 't/data/besoin_bad.dot' ) or die "Could not open test dotfile"; |
18 | try { |
19 | my $stemma = Text::Tradition::Stemma->new( dot => $baddotfh ); |
20 | ok( 0, "Created broken stemma from dotfile with syntax error" ); |
21 | } catch( Text::Tradition::Error $e ) { |
22 | like( $e->message, qr/^Error trying to parse/, "Syntax error in dot threw exception" ); |
64a36834 |
23 | } |
24 | |
25 | # Create a good graph |
26 | my $dotfh; |
27 | open( $dotfh, 't/data/florilegium.dot' ) or die "Could not open test dotfile"; |
28 | binmode( $dotfh, ':utf8' ); |
ace5fce5 |
29 | my $stemma = Text::Tradition::Stemma->new( dot => $dotfh ); |
64a36834 |
30 | is( ref( $stemma ), 'Text::Tradition::Stemma', "Created stemma from good dotfile" ); |
31 | is( scalar $stemma->witnesses, 13, "Found correct number of extant witnesses" ); |
32 | is( scalar $stemma->hypotheticals, 8, "Found correct number of extant hypotheticals" ); |
f96630e3 |
33 | ok( $stemma->has_identifier, "Stemma identifier was found in dot" ); |
34 | is( $stemma->identifier, 'Coislinianum lineage', "Correct stemma identifier was found in dot" ); |
64a36834 |
35 | my $found_unicode_sigil; |
36 | foreach my $h ( $stemma->hypotheticals ) { |
37 | $found_unicode_sigil = 1 if $h eq "\x{3b1}"; |
38 | } |
39 | ok( $found_unicode_sigil, "Found a correctly encoded Unicode sigil" ); |
ea45d2a6 |
40 | |
cb741417 |
41 | # Create an undirected graph |
42 | my $undirdotfh; |
43 | open( $undirdotfh, 't/data/besoin_undirected.dot' ) or die "Could not open test dotfile"; |
44 | binmode( $undirdotfh, ':utf8' ); |
45 | my $udstemma = Text::Tradition::Stemma->new( dot => $undirdotfh ); |
46 | is( ref( $udstemma ), 'Text::Tradition::Stemma', "Created stemma from undirected dotfile" ); |
47 | is( scalar $udstemma->witnesses, 13, "Found correct number of extant witnesses" ); |
48 | is( scalar $udstemma->hypotheticals, 12, "Found correct number of hypotheticals" ); |
49 | ok( $udstemma->is_undirected, "Stemma was recorded as undirected" ); |
64a36834 |
50 | } |
51 | |
52 | |
53 | |
54 | |
55 | 1; |