Add check for duplicate_reading that at least one witness remains for each reading...
[scpubgit/stemmatology.git] / base / t / text_tradition_collation.t
index 32f65b7..e374002 100644 (file)
@@ -53,7 +53,9 @@ is( $c->reading('n21p0')->text, 'unto', "Reading n21p0 merged correctly" );
 
 # =begin testing
 {
+use Test::More::UTF8;
 use Text::Tradition;
+use TryCatch;
 
 my $st = Text::Tradition->new( 'input' => 'Self', 'file' => 't/data/collatecorr.xml' );
 is( ref( $st ), 'Text::Tradition', "Got a tradition from test file" );
@@ -88,6 +90,27 @@ is( scalar @pairs, 3, "Found three more identical readings" );
 is( $sc->end->rank, 11, "The ranks shifted appropriately" );
 $sc->flatten_ranks();
 is( scalar( $sc->readings ), $numr - 3, "Now we are collated correctly" );
+
+# Check that we can't "duplicate" a reading with no wits or with all wits
+try {
+       my( $badr, @del_rdgs ) = $sc->duplicate_reading( 'n124' );
+       ok( 0, "Reading duplication without witnesses throws an error" );
+} catch( Text::Tradition::Error $e ) {
+       like( $e->message, qr/Must specify one or more witnesses/, 
+               "Reading duplication without witnesses throws the expected error" );
+} catch {
+       ok( 0, "Reading duplication without witnesses threw the wrong error" );
+}
+
+try {
+       my( $badr, @del_rdgs ) = $sc->duplicate_reading( 'n124', 'Ba96', 'Mü11475' );
+       ok( 0, "Reading duplication with all witnesses throws an error" );
+} catch( Text::Tradition::Error $e ) {
+       like( $e->message, qr/Cannot join all witnesses/, 
+               "Reading duplication with all witnesses throws the expected error" );
+} catch {
+       ok( 0, "Reading duplication with all witnesses threw the wrong error" );
+}
 }