blob: 928d28ff9c59499b4447d0fef1afb6edba1e9893 [file] [log] [blame]
Akron4f67cd42020-07-02 12:27:58 +02001use strict;
2use warnings;
3use Test::More;
Akron4f67cd42020-07-02 12:27:58 +02004
5use FindBin;
6BEGIN {
7 unshift @INC, "$FindBin::Bin/../lib";
8};
9
Peter Harders42e18a62020-07-21 02:43:26 +020010use Test::KorAP::XML::TEI qw!korap_tempfile!;
11
Akron0465e9e2020-07-27 15:55:21 +020012use_ok('KorAP::XML::TEI', 'remove_xml_comments', 'escape_xml');
Akron4f67cd42020-07-02 12:27:58 +020013
Akron0465e9e2020-07-27 15:55:21 +020014subtest 'remove_xml_comments' => sub {
15 my ($fh, $filename) = korap_tempfile('tei');
Akron4f67cd42020-07-02 12:27:58 +020016
Akron0465e9e2020-07-27 15:55:21 +020017 print $fh <<'HTML';
Akron4f67cd42020-07-02 12:27:58 +020018mehrzeiliger
19Kommentar
20 -->
21Test
22HTML
23
Akron0465e9e2020-07-27 15:55:21 +020024 is(remove_xml_comments($fh, "hallo"),"hallo");
25 is(remove_xml_comments($fh, "hallo <!-- Test -->"),"hallo ");
26 is(remove_xml_comments($fh, "<!-- Test --> hallo")," hallo");
Akron4f67cd42020-07-02 12:27:58 +020027
Akron0465e9e2020-07-27 15:55:21 +020028 seek($fh, 0, 0);
Akron4f67cd42020-07-02 12:27:58 +020029
Akron0465e9e2020-07-27 15:55:21 +020030 is(remove_xml_comments($fh, '<!--'), "Test\n");
Akron4f67cd42020-07-02 12:27:58 +020031
Akron0465e9e2020-07-27 15:55:21 +020032 seek($fh, 0, 0);
Akron2d547bc2020-07-04 10:34:35 +020033
Akron0465e9e2020-07-27 15:55:21 +020034 print $fh <<'HTML';
Akron2d547bc2020-07-04 10:34:35 +020035mehrzeiliger
36Kommentar
37 --><!-- Versuch
38-->ist <!-- a --><!-- b --> ein Test
39HTML
40
Akron0465e9e2020-07-27 15:55:21 +020041 seek($fh, 0, 0);
Akron2d547bc2020-07-04 10:34:35 +020042
Akron0465e9e2020-07-27 15:55:21 +020043 is(remove_xml_comments($fh, 'Dies <!--'), "Dies ist ein Test\n");
Akron2d547bc2020-07-04 10:34:35 +020044
Akron0465e9e2020-07-27 15:55:21 +020045 close($fh);
46};
47
48subtest 'escape_xml' => sub {
49 is(
50 escape_xml('"""'),
51 '&quot;&quot;&quot;'
52 );
53
54 is(
55 escape_xml('&&&'),
56 '&amp;&amp;&amp;'
57 );
58
59 is(
60 escape_xml('<<<'),
61 '&lt;&lt;&lt;'
62 );
63
64 is(
65 escape_xml('>>>'),
66 '&gt;&gt;&gt;'
67 );
68
69 is(
70 escape_xml('<tag att1="foo" att2="bar">C&A</tag>'),
71 '&lt;tag att1=&quot;foo&quot; att2=&quot;bar&quot;&gt;C&amp;A&lt;/tag&gt;'
72 );
73};
74
Akron2d547bc2020-07-04 10:34:35 +020075
Akron4f67cd42020-07-02 12:27:58 +020076done_testing;