blob: 1ef8bf9c1dfb2c22b615c38a014853d81728a02a [file] [log] [blame]
Akron5fb5e8d2020-07-23 17:45:13 +02001use strict;
2use warnings;
3use Test::More;
Akron54e363c2020-07-29 11:01:03 +02004use Test::XML::Loy;
Akron5fb5e8d2020-07-23 17:45:13 +02005
6use FindBin;
7BEGIN {
8 unshift @INC, "$FindBin::Bin/../lib";
9};
10
Akronfe1aa542020-07-31 19:14:38 +020011use_ok('Test::KorAP::XML::TEI','korap_tempfile', 'i5_template', 'test_tei2korapxml');
12
Akron5fb5e8d2020-07-23 17:45:13 +020013
Akron54e363c2020-07-29 11:01:03 +020014subtest 'korap_tempfile' => sub {
15 my ($fh, $filename) = korap_tempfile('test');
16 ok($fh, 'Filehandle created');
17 ok($filename, 'Filename returned');
18 close($fh);
Akron5fb5e8d2020-07-23 17:45:13 +020019
Akron54e363c2020-07-29 11:01:03 +020020 like($filename, qr!KorAP-XML-TEI_test_.+?\.tmp$!, 'Filename pattern');
Akron5fb5e8d2020-07-23 17:45:13 +020021
Akron54e363c2020-07-29 11:01:03 +020022 ($fh, $filename) = korap_tempfile();
23 ok($fh, 'Filehandle created');
24 ok($filename, 'Filename returned');
25 close($fh);
Akron5fb5e8d2020-07-23 17:45:13 +020026
Akron54e363c2020-07-29 11:01:03 +020027 like($filename, qr!KorAP-XML-TEI_.+?\.tmp$!, 'Filename pattern');
28};
29
Akronfe1aa542020-07-31 19:14:38 +020030
Akron54e363c2020-07-29 11:01:03 +020031subtest 'i5_template' => sub {
32 my $tpl = i5_template();
33 my $t = Test::XML::Loy->new($tpl);
34 $t->text_is('korpusSigle', 'AAA')
35 ->text_is('dokumentSigle', 'AAA/BBB')
36 ->text_is('textSigle', 'AAA/BBB.00000')
37 ->text_like('text', qr!Lorem ipsum!)
38 ;
39
40 $tpl = i5_template(
41 korpusSigle => 'BBB',
42 dokumentSigle => 'BBB/CCC',
43 textSigle => 'BBB/CCC.11111',
44 text => 'Ein Versuch'
45 );
46 $t = Test::XML::Loy->new($tpl);
47 $t->text_is('korpusSigle', 'BBB')
48 ->text_is('dokumentSigle', 'BBB/CCC')
49 ->text_is('textSigle', 'BBB/CCC.11111')
50 ->text_unlike('text', qr!Lorem ipsum!)
51 ->text_like('text', qr!Ein Versuch!)
52 ;
53};
Akron5fb5e8d2020-07-23 17:45:13 +020054
Akronfe1aa542020-07-31 19:14:38 +020055
56subtest 'test_tei2korapxml_i5_template' => sub {
57 test_tei2korapxml(
58 template => {
59 text => 'Das ist ein gutes Beispiel',
60 korpusSigle => 'a',
61 dokumentSigle => 'a/b',
62 textSigle => 'a/b.1'
63 },
64 param => '-ti'
65 )
Akron91577922021-02-19 10:32:54 +010066 ->stderr_like(qr!tei2korapxml:.*? text_id=a_b\.1!)
Akronfe1aa542020-07-31 19:14:38 +020067 ->file_exists('a/b/1/header.xml')
68 ->file_exists('a/b/header.xml')
69 ->file_exists('a/header.xml')
70 ->unzip_xml('a/b/1/data.xml')
71 ->attr_is('raw_text', 'docid', 'a_b.1')
72 ->text_is('text', 'Das ist ein gutes Beispiel');
73};
74
Akron5fb5e8d2020-07-23 17:45:13 +020075done_testing;