add relationship deletion functionality
[scpubgit/stemmatology.git] / t / text_tradition_collation_relationshipstore.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 Text::Tradition;
12 use TryCatch;
13
14 use_ok( 'Text::Tradition::Collation::RelationshipStore' );
15
16 # Add some relationships, and delete them
17
18 my $cxfile = 't/data/Collatex-16.xml';
19 my $t = Text::Tradition->new( 
20     'name'  => 'inline', 
21     'input' => 'CollateX',
22     'file'  => $cxfile,
23     );
24 my $c = $t->collation;
25
26 my @v1 = $c->add_relationship( 'n21', 'n22', { 'type' => 'meaning' } );
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( 'n9', '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( 'n8', 'n13' );
36 is( scalar @v2, 2, "Deleted second global relationship" );
37 try {
38         my @v3 = $c->del_relationship( 'n1', 'n2' );
39         ok( 0, "Should have errored on non-existent relationship" );
40 } catch( Text::Tradition::Error $e ) {
41         like( $e->message, qr/No relationship defined/, "Attempt to delete non-existent relationship errored" );
42 }
43 }
44
45
46
47
48 1;