4 use Test::More 'no_plan';
11 use Test::More::UTF8 qw/ -utf8 /;
13 my $trad = Text::Tradition->new( 'name' => 'test tradition' );
14 my $c = $trad->collation;
16 # Test a plaintext witness via string
17 my $str = 'This is a line of text';
18 my $ptwit = $trad->add_witness(
20 'sourcetype' => 'plaintext',
23 is( ref( $ptwit ), 'Text::Tradition::Witness', 'Created a witness' );
25 is( $ptwit->sigil, 'A', "Witness has correct sigil" );
26 $c->make_witness_path( $ptwit );
27 is( $c->path_text( $ptwit->sigil ), $str, "Witness has correct text" );
30 # Test some JSON witnesses via object
31 open( JSIN, 't/data/witnesses/testwit.json' ) or die "Could not open JSON test input";
32 binmode( JSIN, ':encoding(UTF-8)' );
35 $trad->add_json_witnesses( join( '', @lines ) );
36 is( ref( $trad->witness( 'MsAJ' ) ), 'Text::Tradition::Witness',
37 "Found first JSON witness" );
38 is( ref( $trad->witness( 'MsBJ' ) ), 'Text::Tradition::Witness',
39 "Found second JSON witness" );
41 # Test an XML witness via file
42 my $xmlwit = $trad->add_witness( 'sourcetype' => 'xmldesc',
43 'file' => 't/data/witnesses/teiwit.xml' );
44 is( ref( $xmlwit ), 'Text::Tradition::Witness', "Created witness from XML file" );
46 is( $xmlwit->sigil, 'V887', "XML witness has correct sigil" );
47 ok( $xmlwit->is_layered, "Picked up correction layer" );
48 is( @{$xmlwit->text}, 182, "Got correct text length" );
49 is( @{$xmlwit->layertext}, 182, "Got correct a.c. text length" );
51 my @allwitwords = grep { $_->id =~ /^V887/ } $c->readings;
52 is( @allwitwords, 184, "Reused appropriate readings" );
55 my $xpwit = $trad->add_witness( 'sourcetype' => 'xmldesc',
56 'file' => 't/data/witnesses/group.xml',
57 'use_text' => '//tei:group/tei:text[2]' );
58 is( ref( $xpwit ), 'Text::Tradition::Witness', "Created witness from XML group" );
60 is( $xpwit->sigil, 'G', "XML part witness has correct sigil" );
61 ok( !$xpwit->is_layered, "Picked up no correction layer" );
62 is( @{$xpwit->text}, 157, "Got correct text length" );
65 # Test non-ASCII sigla
66 my $at = Text::Tradition->new(
70 file => 't/data/armexample.xlsx' );
71 foreach my $wit ( $at->witnesses ) {
72 my $sig = $wit->sigil;
73 if( $sig =~ /^\p{ASCII}+$/ ) {
74 is( $wit->ascii_sigil, '_A_' . $sig,
75 "Correct ASCII sigil for ASCII witness $sig" );
77 # This is our non-ASCII example
78 is( $wit->ascii_sigil, '_A_5315622',
79 "Correct ASCII sigil for non-ASCII witness $sig" );
89 my $trad = Text::Tradition->new();
91 my @text = qw/ Thhis is a line of text /;
92 my $wit = $trad->add_witness(
94 'string' => join( ' ', @text ),
95 'sourcetype' => 'plaintext',
96 'identifier' => 'test witness',
98 my $jsonstruct = $wit->export_as_json;
99 is( $jsonstruct->{'id'}, 'A', "got the right witness sigil" );
100 is( $jsonstruct->{'name'}, 'test witness', "got the right identifier" );
101 is( scalar @{$jsonstruct->{'tokens'}}, 6, "got six text tokens" );
102 foreach my $idx ( 0 .. $#text ) {
103 is( $jsonstruct->{'tokens'}->[$idx]->{'t'}, $text[$idx], "tokens look OK" );
106 my @ctext = qw( when april with his showers sweet with fruit the drought of march
107 has pierced unto the root );
108 $trad = Text::Tradition->new(
109 'input' => 'CollateX',
110 'file' => 't/data/Collatex-16.xml' );
112 $jsonstruct = $trad->witness('A')->export_as_json;
113 is( $jsonstruct->{'id'}, 'A', "got the right witness sigil" );
114 is( $jsonstruct->{'name'}, undef, "got undef for missing identifier" );
115 is( scalar @{$jsonstruct->{'tokens'}}, 17, "got all text tokens" );
116 foreach my $idx ( 0 .. $#ctext ) {
117 is( $jsonstruct->{'tokens'}->[$idx]->{'t'}, $ctext[$idx], "tokens look OK" );
120 ## TODO test layertext export