only use applicable a.c. witnesses in stemma for analysis
[scpubgit/stemmatology.git] / t / text_tradition_witness.t
CommitLineData
7158714d 1#!/usr/bin/perl -w
2
3use strict;
4use Test::More 'no_plan';
5$| = 1;
6
7
8
9# =begin testing
10{
11use_ok( 'Text::Tradition::Witness', "can use module" );
12
13my @text = qw( This is a line of text );
14my $wit = Text::Tradition::Witness->new(
15 'sigil' => 'A',
16 'text' => \@text,
17 );
18is( ref( $wit ), 'Text::Tradition::Witness', 'Created a witness' );
19if( $wit ) {
20 is( $wit->sigil, 'A', "Witness has correct sigil" );
21 is( join( ' ', @{$wit->text} ), join( ' ', @text ), "Witness has correct text" );
22}
23}
24
25
26
f025e303 27# =begin testing
28{
29use Text::Tradition;
30
31my @text = qw( This is a line of text );
32my $wit = Text::Tradition::Witness->new(
33 'sigil' => 'A',
34 'text' => \@text,
35 'identifier' => 'test witness',
36 );
37my $jsonstruct = $wit->export_as_json;
38is( $jsonstruct->{'id'}, 'A', "got the right witness sigil" );
39is( $jsonstruct->{'name'}, 'test witness', "got the right identifier" );
40is( scalar @{$jsonstruct->{'tokens'}}, 6, "got six text tokens" );
41foreach my $idx ( 0 .. $#text ) {
42 is( $jsonstruct->{'tokens'}->[$idx]->{'t'}, $text[$idx], "tokens look OK" );
43}
44
45my @ctext = qw( when april with his showers sweet with fruit the drought of march
46 has pierced unto the root );
47my $trad = Text::Tradition->new(
48 'input' => 'CollateX',
49 'file' => 't/data/Collatex-16.xml' );
50
51$jsonstruct = $trad->witness('A')->export_as_json;
52is( $jsonstruct->{'id'}, 'A', "got the right witness sigil" );
53is( $jsonstruct->{'name'}, undef, "got undef for missing identifier" );
54is( scalar @{$jsonstruct->{'tokens'}}, 17, "got all text tokens" );
55foreach my $idx ( 0 .. $#ctext ) {
56 is( $jsonstruct->{'tokens'}->[$idx]->{'t'}, $ctext[$idx], "tokens look OK" );
57}
58}
59
60
61
7158714d 62
631;