4 use Test::More 'no_plan';
14 use_ok( 'Text::Tradition::Collation::RelationshipStore' );
16 # Add some relationships, and delete them
18 my $cxfile = 't/data/Collatex-16.xml';
19 my $t = Text::Tradition->new(
21 'input' => 'CollateX',
24 my $c = $t->collation;
26 my @v1 = $c->add_relationship( 'n21', 'n22', { 'type' => 'lexical' } );
27 is( scalar @v1, 1, "Added a single relationship" );
28 is( $v1[0]->[0], 'n21', "Got correct node 1" );
29 is( $v1[0]->[1], 'n22', "Got correct node 2" );
30 my @v2 = $c->add_relationship( 'n24', 'n23',
31 { 'type' => 'spelling', 'scope' => 'global' } );
32 is( scalar @v2, 2, "Added a global relationship with two instances" );
33 @v1 = $c->del_relationship( 'n22', 'n21' );
34 is( scalar @v1, 1, "Deleted first relationship" );
35 @v2 = $c->del_relationship( 'n12', 'n13' );
36 is( scalar @v2, 2, "Deleted second global relationship" );
37 my @v3 = $c->del_relationship( 'n1', 'n2' );
38 is( scalar @v3, 0, "Nothing deleted on non-existent relationship" );
51 $t1 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' );
52 } 'DROPPING r14.2 -> r8.1: Cannot set relationship on a meta reading',
53 "Got expected relationship drop warning on parse";
55 # Test 1.1: try to equate nodes that are prevented with an intermediate collation
56 ok( $t1, "Parsed test fragment file" );
57 my $c1 = $t1->collation;
58 my $trel = $c1->get_relationship( 'r9.2', 'r9.3' );
59 is( ref( $trel ), 'Text::Tradition::Collation::Relationship',
60 "Troublesome relationship exists" );
61 is( $trel->type, 'collated', "Troublesome relationship is a collation" );
63 # Try to make the link we want
65 $c1->add_relationship( 'r8.6', 'r10.3', { 'type' => 'orthographic' } );
66 ok( 1, "Added cross-collation relationship as expected" );
67 } catch( Text::Tradition::Error $e ) {
68 ok( 0, "Existing collation blocked equivalence relationship: " . $e->message );
72 $c1->calculate_ranks();
73 ok( 1, "Successfully calculated ranks" );
74 } catch ( Text::Tradition::Error $e ) {
75 ok( 0, "Collation now has a cycle: " . $e->message );
78 # Test 1.2: attempt merge of an identical reading
80 $c1->merge_readings( 'r9.3', 'r11.5' );
81 ok( 1, "Successfully merged reading 'pontifex'" );
82 } catch ( Text::Tradition::Error $e ) {
83 ok( 0, "Merge of mergeable readings failed: $e->message" );
87 # Test 1.3: attempt relationship with a meta reading (should fail)
89 $c1->add_relationship( 'r8.1', 'r9.2', { 'type' => 'collated' } );
90 ok( 0, "Allowed a meta-reading to be used in a relationship" );
91 } catch ( Text::Tradition::Error $e ) {
92 is( $e->message, 'Cannot set relationship on a meta reading',
93 "Relationship link prevented for a meta reading" );
96 # Test 2.1: try to equate nodes that are prevented with a real intermediate
100 $t2 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' );
101 } 'DROPPING r14.2 -> r8.1: Cannot set relationship on a meta reading',
102 "Got expected relationship drop warning on parse";
103 my $c2 = $t2->collation;
104 $c2->add_relationship( 'r9.2', 'r9.3', { 'type' => 'lexical' } );
105 my $trel2 = $c2->get_relationship( 'r9.2', 'r9.3' );
106 is( ref( $trel2 ), 'Text::Tradition::Collation::Relationship',
107 "Created blocking relationship" );
108 is( $trel2->type, 'lexical', "Blocking relationship is not a collation" );
109 # This time the link ought to fail
111 $c2->add_relationship( 'r8.6', 'r10.3', { 'type' => 'orthographic' } );
112 ok( 0, "Added cross-equivalent bad relationship" );
113 } catch ( Text::Tradition::Error $e ) {
114 like( $e->message, qr/witness loop/,
115 "Existing equivalence blocked crossing relationship" );
119 $c2->calculate_ranks();
120 ok( 1, "Successfully calculated ranks" );
121 } catch ( Text::Tradition::Error $e ) {
122 ok( 0, "Collation now has a cycle: " . $e->message );
125 # Test 3.1: make a straightforward pair of transpositions.
126 my $t3 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/lf2.xml' );
127 # Test 1: try to equate nodes that are prevented with an intermediate collation
128 my $c3 = $t3->collation;
130 $c3->add_relationship( 'r36.4', 'r38.3', { 'type' => 'transposition' } );
131 ok( 1, "Added straightforward transposition" );
132 } catch ( Text::Tradition::Error $e ) {
133 ok( 0, "Failed to add normal transposition: " . $e->message );
136 $c3->add_relationship( 'r36.3', 'r38.2', { 'type' => 'transposition' } );
137 ok( 1, "Added straightforward transposition complement" );
138 } catch ( Text::Tradition::Error $e ) {
139 ok( 0, "Failed to add normal transposition complement: " . $e->message );
142 # Test 3.2: try to make a transposition that could be a parallel.
144 $c3->add_relationship( 'r28.2', 'r29.2', { 'type' => 'transposition' } );
145 ok( 0, "Added bad colocated transposition" );
146 } catch ( Text::Tradition::Error $e ) {
147 like( $e->message, qr/Readings appear to be colocated/,
148 "Prevented bad colocated transposition" );
151 # Test 3.3: make the parallel, and then make the transposition again.
153 $c3->add_relationship( 'r28.3', 'r29.3', { 'type' => 'orthographic' } );
154 ok( 1, "Equated identical readings for transposition" );
155 } catch ( Text::Tradition::Error $e ) {
156 ok( 0, "Failed to equate identical readings: " . $e->message );
159 $c3->add_relationship( 'r28.2', 'r29.2', { 'type' => 'transposition' } );
160 ok( 1, "Added straightforward transposition complement" );
161 } catch ( Text::Tradition::Error $e ) {
162 ok( 0, "Failed to add normal transposition complement: " . $e->message );