blob: eb6d20ec193fec2715a626ed0f7a46e747caf173 [file] [log] [blame]
Nils Diewald7364d1f2013-11-05 19:26:35 +00001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use Mojo::ByteStream 'b';
6use utf8;
7use lib 'lib', '../lib';
8
Akron00dbba52016-02-14 01:42:20 +01009use_ok('KorAP::XML::Document::Primary');
Nils Diewald7364d1f2013-11-05 19:26:35 +000010
11my $t = "Der März ging vorüber und demnächst würde es Herbstblätter regnen.";
12
Akron00dbba52016-02-14 01:42:20 +010013ok(my $p = KorAP::XML::Document::Primary->new($t), 'Constructor');
Nils Diewald7364d1f2013-11-05 19:26:35 +000014
15is($p->data_length, 66, 'Text has correct length');
16
17is($p->data, $t, 'Text is identical');
18is($p->data(0,3), 'Der', 'Text is identical');
19is($p->data(4,8), 'März', 'Text is identical');
20is($p->data(26,35), 'demnächst', 'Text is identical');
21
22is($p->data_bytes(0,3), 'Der', 'Text is identical');
23is($p->data_bytes(4,9), 'März', 'Text is identical');
24is($p->data_bytes(28,38), 'demnächst', 'Text is identical');
25
26is($p->bytes2chars(4), 4, 'Byte offset matches');
27is($p->bytes2chars(9), 8, 'Byte offset matches');
28is($p->bytes2chars(28), 26, 'Byte offset matches');
29is($p->bytes2chars(38), 35, 'Byte offset matches');
30
31is(
32 $p->data(
33 $p->bytes2chars(17),
34 $p->bytes2chars(45)
35 ),
36 $p->data_bytes(17,45),
37 'Text is identical'
38);
39
40$t = 'Er dächte, daß dies „für alle Elemente gilt“.';
41
Akron00dbba52016-02-14 01:42:20 +010042ok($p = KorAP::XML::Document::Primary->new($t), 'Constructor');
Nils Diewald7364d1f2013-11-05 19:26:35 +000043
44is($p->data_length, 45, 'Text has correct length');
45
46is($p->data, $t, 'Text is identical');
47is($p->data(0,2), 'Er', 'Text is identical');
48is($p->data(3,9), 'dächte', 'Text is identical');
49is($p->data(21,24), 'für', 'Text is identical');
50is($p->data(20,21), '„', 'Text is identical');
51is($p->data(43,44), '“', 'Text is identical');
52is($p->data(44,45), '.', 'Text is identical');
53
54is($p->data_bytes(0,2), 'Er', 'Text is identical');
55is($p->bytes2chars(0),0, 'b2c correct');
56is($p->bytes2chars(2),2, 'b2c correct');
57is($p->data_bytes(3,10), 'dächte', 'Text is identical');
58is($p->bytes2chars(3),3, 'b2c correct');
59is($p->bytes2chars(10),9, 'b2c correct');
60is($p->data_bytes(25,29), 'für', 'Text is identical');
61is($p->bytes2chars(25),21, 'b2c correct');
62is($p->bytes2chars(29),24, 'b2c correct');
63is($p->data_bytes(22,25), '„', 'Text is identical');
64is($p->bytes2chars(22),20, 'b2c correct');
65is($p->bytes2chars(25),21, 'b2c correct');
66is($p->data_bytes(48,51), '“', 'Text is identical');
67is($p->bytes2chars(48),43, 'b2c correct');
68is($p->bytes2chars(51),44, 'b2c correct');
69is($p->data_bytes(51,52), '.', 'Text is identical');
70is($p->bytes2chars(52),45, 'b2c correct');
71
72is(
73 $p->data(
74 $p->bytes2chars(17),
75 $p->bytes2chars(45)
76 ),
77 $p->data_bytes(17,45),
78 'Text is identical'
79);
80
81
82#ok($p = KorAP::Document::Primary->new($t), 'Constructor');
83is($p->xip2chars(0), 0, 'Fine');
84is($p->xip2chars(7), 6, 'Fine');
85#diag $p->data($p->latinbytes2chars(3),$p->latinbytes2chars(9));
86
87
88done_testing;