Akron | 5fb5e8d | 2020-07-23 17:45:13 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 4 | use Test::XML::Loy; |
Akron | 5fb5e8d | 2020-07-23 17:45:13 +0200 | [diff] [blame] | 5 | |
| 6 | use FindBin; |
| 7 | BEGIN { |
| 8 | unshift @INC, "$FindBin::Bin/../lib"; |
| 9 | }; |
| 10 | |
Akron | fe1aa54 | 2020-07-31 19:14:38 +0200 | [diff] [blame] | 11 | use_ok('Test::KorAP::XML::TEI','korap_tempfile', 'i5_template', 'test_tei2korapxml'); |
| 12 | |
Akron | 5fb5e8d | 2020-07-23 17:45:13 +0200 | [diff] [blame] | 13 | |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 14 | subtest 'korap_tempfile' => sub { |
| 15 | my ($fh, $filename) = korap_tempfile('test'); |
| 16 | ok($fh, 'Filehandle created'); |
| 17 | ok($filename, 'Filename returned'); |
| 18 | close($fh); |
Akron | 5fb5e8d | 2020-07-23 17:45:13 +0200 | [diff] [blame] | 19 | |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 20 | like($filename, qr!KorAP-XML-TEI_test_.+?\.tmp$!, 'Filename pattern'); |
Akron | 5fb5e8d | 2020-07-23 17:45:13 +0200 | [diff] [blame] | 21 | |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 22 | ($fh, $filename) = korap_tempfile(); |
| 23 | ok($fh, 'Filehandle created'); |
| 24 | ok($filename, 'Filename returned'); |
| 25 | close($fh); |
Akron | 5fb5e8d | 2020-07-23 17:45:13 +0200 | [diff] [blame] | 26 | |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 27 | like($filename, qr!KorAP-XML-TEI_.+?\.tmp$!, 'Filename pattern'); |
| 28 | }; |
| 29 | |
Akron | fe1aa54 | 2020-07-31 19:14:38 +0200 | [diff] [blame] | 30 | |
Akron | 54e363c | 2020-07-29 11:01:03 +0200 | [diff] [blame] | 31 | subtest '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 | }; |
Akron | 5fb5e8d | 2020-07-23 17:45:13 +0200 | [diff] [blame] | 54 | |
Akron | fe1aa54 | 2020-07-31 19:14:38 +0200 | [diff] [blame] | 55 | |
| 56 | subtest '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 | ) |
Akron | 9157792 | 2021-02-19 10:32:54 +0100 | [diff] [blame^] | 66 | ->stderr_like(qr!tei2korapxml:.*? text_id=a_b\.1!) |
Akron | fe1aa54 | 2020-07-31 19:14:38 +0200 | [diff] [blame] | 67 | ->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 | |
Akron | 5fb5e8d | 2020-07-23 17:45:13 +0200 | [diff] [blame] | 75 | done_testing; |