overhaul of colocated-relationship validation, still segfaulting
[scpubgit/stemmatology.git] / t / text_tradition_collation_relationshipstore.t
index 6b9db2b..48b6423 100644 (file)
@@ -23,7 +23,7 @@ my $t = Text::Tradition->new(
     );
 my $c = $t->collation;
 
-my @v1 = $c->add_relationship( 'n21', 'n22', { 'type' => 'meaning' } );
+my @v1 = $c->add_relationship( 'n21', 'n22', { 'type' => 'lexical' } );
 is( scalar @v1, 1, "Added a single relationship" );
 is( $v1[0]->[0], 'n21', "Got correct node 1" );
 is( $v1[0]->[1], 'n22', "Got correct node 2" );
@@ -40,5 +40,67 @@ is( scalar @v3, 0, "Nothing deleted on non-existent relationship" );
 
 
 
+# =begin testing
+{
+use Text::Tradition;
+use TryCatch;
+
+my $t1 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' );
+# Test 1: try to equate nodes that are prevented with an intermediate collation
+ok( $t1, "Parsed test fragment file" );
+my $c1 = $t1->collation;
+## HACK
+$c1->calculate_ranks();
+my $trel = $c1->get_relationship( '9,2', '9,3' );
+is( ref( $trel ), 'Text::Tradition::Collation::Relationship',
+       "Troublesome relationship exists" );
+is( $trel->type, 'collated', "Troublesome relationship is a collation" );
+
+# Try to make the link we want
+try {
+       $c1->add_relationship( '8,6', '10,3', { 'type' => 'orthographic' } );
+       ok( 1, "Added cross-collation relationship as expected" );
+} catch {
+       ok( 0, "Existing collation blocked equivalence relationship" );
+}
+
+try {
+       $c1->calculate_ranks();
+       ok( 1, "Successfully calculated ranks" );
+} catch {
+       ok( 0, "Collation now has a cycle" );
+}
+
+# Test 2: try to equate nodes that are prevented with a real intermediate
+# equivalence
+
+my $t2 = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/legendfrag.xml' );
+# Test 1: try to equate nodes that are prevented with an intermediate collation
+my $c2 = $t2->collation;
+## HACK
+$c2->calculate_ranks();
+$c2->add_relationship( '9,2', '9,3', { 'type' => 'lexical' } );
+my $trel2 = $c2->get_relationship( '9,2', '9,3' );
+is( ref( $trel2 ), 'Text::Tradition::Collation::Relationship',
+       "Created blocking relationship" );
+is( $trel2->type, 'lexical', "Blocking relationship is not a collation" );
+# This time the link ought to fail
+try {
+       $c2->add_relationship( '8,6', '10,3', { 'type' => 'orthographic' } );
+       ok( 0, "Existing equivalence blocked crossing relationship" );
+} catch {
+       ok( 1, "Added cross-equivalent bad relationship" );
+}
+
+try {
+       $c2->calculate_ranks();
+       ok( 1, "Successfully calculated ranks" );
+} catch {
+       ok( 0, "Collation now has a cycle" );
+}
+}
+
+
+
 
 1;