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" );
48 my $t1 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' );
49 # Test 1.1: try to equate nodes that are prevented with an intermediate collation
50 ok( $t1, "Parsed test fragment file" );
51 my $c1 = $t1->collation;
52 my $trel = $c1->get_relationship( '9,2', '9,3' );
53 is( ref( $trel ), 'Text::Tradition::Collation::Relationship',
54 "Troublesome relationship exists" );
55 is( $trel->type, 'collated', "Troublesome relationship is a collation" );
57 # Try to make the link we want
59 $c1->add_relationship( '8,6', '10,3', { 'type' => 'orthographic' } );
60 ok( 1, "Added cross-collation relationship as expected" );
61 } catch( Text::Tradition::Error $e ) {
62 ok( 0, "Existing collation blocked equivalence relationship: " . $e->message );
66 $c1->calculate_ranks();
67 ok( 1, "Successfully calculated ranks" );
68 } catch ( Text::Tradition::Error $e ) {
69 ok( 0, "Collation now has a cycle: " . $e->message );
72 # Test 1.2: attempt merge of an identical reading
74 $c1->merge_readings( '9,3', '11,5' );
75 ok( 1, "Successfully merged reading 'pontifex'" );
76 } catch ( Text::Tradition::Error $e ) {
77 ok( 0, "Merge of mergeable readings failed: $e->message" );
81 # Test 1.3: attempt relationship with a meta reading (should fail)
83 $c1->add_relationship( '8,1', '9,2', { 'type' => 'collated' } );
84 ok( 0, "Allowed a meta-reading to be used in a relationship" );
85 } catch ( Text::Tradition::Error $e ) {
86 is( $e->message, 'Cannot set relationship on a meta reading',
87 "Relationship link prevented for a meta reading" );
90 # Test 2.1: try to equate nodes that are prevented with a real intermediate
92 my $t2 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' );
93 my $c2 = $t2->collation;
94 $c2->add_relationship( '9,2', '9,3', { 'type' => 'lexical' } );
95 my $trel2 = $c2->get_relationship( '9,2', '9,3' );
96 is( ref( $trel2 ), 'Text::Tradition::Collation::Relationship',
97 "Created blocking relationship" );
98 is( $trel2->type, 'lexical', "Blocking relationship is not a collation" );
99 # This time the link ought to fail
101 $c2->add_relationship( '8,6', '10,3', { 'type' => 'orthographic' } );
102 ok( 0, "Added cross-equivalent bad relationship" );
103 } catch ( Text::Tradition::Error $e ) {
104 like( $e->message, qr/witness loop/,
105 "Existing equivalence blocked crossing relationship" );
109 $c2->calculate_ranks();
110 ok( 1, "Successfully calculated ranks" );
111 } catch ( Text::Tradition::Error $e ) {
112 ok( 0, "Collation now has a cycle: " . $e->message );
115 # Test 3.1: make a straightforward pair of transpositions.
116 my $t3 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/lf2.xml' );
117 # Test 1: try to equate nodes that are prevented with an intermediate collation
118 my $c3 = $t3->collation;
120 $c3->add_relationship( '36,4', '38,3', { 'type' => 'transposition' } );
121 ok( 1, "Added straightforward transposition" );
122 } catch ( Text::Tradition::Error $e ) {
123 ok( 0, "Failed to add normal transposition: " . $e->message );
126 $c3->add_relationship( '36,3', '38,2', { 'type' => 'transposition' } );
127 ok( 1, "Added straightforward transposition complement" );
128 } catch ( Text::Tradition::Error $e ) {
129 ok( 0, "Failed to add normal transposition complement: " . $e->message );
132 # Test 3.2: try to make a transposition that could be a parallel.
134 $c3->add_relationship( '28,2', '29,2', { 'type' => 'transposition' } );
135 ok( 0, "Added bad colocated transposition" );
136 } catch ( Text::Tradition::Error $e ) {
137 like( $e->message, qr/Readings appear to be colocated/,
138 "Prevented bad colocated transposition" );
141 # Test 3.3: make the parallel, and then make the transposition again.
143 $c3->add_relationship( '28,3', '29,3', { 'type' => 'orthographic' } );
144 ok( 1, "Equated identical readings for transposition" );
145 } catch ( Text::Tradition::Error $e ) {
146 ok( 0, "Failed to equate identical readings: " . $e->message );
149 $c3->add_relationship( '28,2', '29,2', { 'type' => 'transposition' } );
150 ok( 1, "Added straightforward transposition complement" );
151 } catch ( Text::Tradition::Error $e ) {
152 ok( 0, "Failed to add normal transposition complement: " . $e->message );