Commit | Line | Data |
331c2dbf |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test::More 'no_plan'; |
5 | $| = 1; |
6 | |
7 | |
8 | |
9 | # =begin testing |
10 | { |
4889be4f |
11 | use TryCatch; |
331c2dbf |
12 | use_ok( 'Text::Tradition', "can use module" ); |
13 | |
14 | my $t = Text::Tradition->new( 'name' => 'empty' ); |
15 | is( ref( $t ), 'Text::Tradition', "initialized an empty Tradition object" ); |
16 | is( $t->name, 'empty', "object has the right name" ); |
17 | is( scalar $t->witnesses, 0, "object has no witnesses" ); |
18 | |
19 | my $simple = 't/data/simple.txt'; |
20 | my $s = Text::Tradition->new( |
21 | 'name' => 'inline', |
22 | 'input' => 'Tabular', |
23 | 'file' => $simple, |
24 | ); |
25 | is( ref( $s ), 'Text::Tradition', "initialized a Tradition object" ); |
26 | is( $s->name, 'inline', "object has the right name" ); |
27 | is( scalar $s->witnesses, 3, "object has three witnesses" ); |
28 | |
331c2dbf |
29 | my $wit_a = $s->witness('A'); |
30 | is( ref( $wit_a ), 'Text::Tradition::Witness', "Found a witness A" ); |
31 | if( $wit_a ) { |
32 | is( $wit_a->sigil, 'A', "Witness A has the right sigil" ); |
33 | } |
34 | is( $s->witness('X'), undef, "There is no witness X" ); |
044d1e45 |
35 | ok( !exists $s->{'witnesses'}->{'X'}, "Witness key X not created" ); |
36 | |
4889be4f |
37 | my $wit_d = $s->add_witness( 'sigil' => 'D', 'sourcetype' => 'plaintext', |
38 | 'string' => 'je suis depourvu de foi' ); |
044d1e45 |
39 | is( ref( $wit_d ), 'Text::Tradition::Witness', "new witness created" ); |
40 | is( $wit_d->sigil, 'D', "witness has correct sigil" ); |
41 | is( scalar $s->witnesses, 4, "object now has four witnesses" ); |
42 | |
4889be4f |
43 | try { |
44 | $s->rename_witness( 'D', 'Invalid Sigil' ); |
45 | ok( 0, "Renamed witness with bad sigil" ); |
46 | } catch ( Text::Tradition::Error $e ) { |
47 | print STDERR $e->message . "\n"; |
48 | is( $s->witness('D'), $wit_d, "Held onto witness during bad rename" ); |
49 | } |
50 | |
51 | try { |
52 | $s->rename_witness( 'D', 'Q' ); |
53 | ok( 1, "Rename of witness succeeded" ); |
54 | is( $s->witness('Q'), $wit_d, "Witness available under new sigil" ); |
55 | ok( !$s->has_witness('D'), "Witness no longer available under old sigil" ); |
56 | } catch ( Text::Tradition::Error $e ) { |
57 | ok( 0, "Failed to rename witness: " . $e->message ); |
58 | } |
59 | |
60 | my $del = $s->del_witness( 'Q' ); |
044d1e45 |
61 | is( $del, $wit_d, "Deleted correct witness" ); |
62 | is( scalar $s->witnesses, 3, "object has three witnesses again" ); |
63 | |
4889be4f |
64 | try { |
65 | $s->rename_witness( 'A', 'WitA' ); |
66 | ok( 0, "Successfully renamed an already collated witness" ); |
67 | } catch ( Text::Tradition::Error $e ) { |
68 | is( $e->message, 'Cannot rename witness that has already been collated', |
69 | "Refused to rename an already-collated witness" ); |
70 | } |
331c2dbf |
71 | } |
72 | |
73 | |
74 | |
75 | |
76 | 1; |