Add exportable XML escape function
Change-Id: I50f2ee398e4b1c3dc5bb79009eaf3b204562887f
diff --git a/t/tei.t b/t/tei.t
index 6dca05c..928d28f 100644
--- a/t/tei.t
+++ b/t/tei.t
@@ -9,38 +9,68 @@
use Test::KorAP::XML::TEI qw!korap_tempfile!;
-use_ok('KorAP::XML::TEI', 'remove_xml_comments');
+use_ok('KorAP::XML::TEI', 'remove_xml_comments', 'escape_xml');
-my ($fh, $filename) = korap_tempfile('tei');
+subtest 'remove_xml_comments' => sub {
+ my ($fh, $filename) = korap_tempfile('tei');
-print $fh <<'HTML';
+ print $fh <<'HTML';
mehrzeiliger
Kommentar
-->
Test
HTML
-is(remove_xml_comments($fh, "hallo"),"hallo");
-is(remove_xml_comments($fh, "hallo <!-- Test -->"),"hallo ");
-is(remove_xml_comments($fh, "<!-- Test --> hallo")," hallo");
+ is(remove_xml_comments($fh, "hallo"),"hallo");
+ is(remove_xml_comments($fh, "hallo <!-- Test -->"),"hallo ");
+ is(remove_xml_comments($fh, "<!-- Test --> hallo")," hallo");
-seek($fh, 0, 0);
+ seek($fh, 0, 0);
-is(remove_xml_comments($fh, '<!--'), "Test\n");
+ is(remove_xml_comments($fh, '<!--'), "Test\n");
-seek($fh, 0, 0);
+ seek($fh, 0, 0);
-print $fh <<'HTML';
+ print $fh <<'HTML';
mehrzeiliger
Kommentar
--><!-- Versuch
-->ist <!-- a --><!-- b --> ein Test
HTML
-seek($fh, 0, 0);
+ seek($fh, 0, 0);
-is(remove_xml_comments($fh, 'Dies <!--'), "Dies ist ein Test\n");
+ is(remove_xml_comments($fh, 'Dies <!--'), "Dies ist ein Test\n");
-close($fh);
+ close($fh);
+};
+
+subtest 'escape_xml' => sub {
+ is(
+ escape_xml('"""'),
+ '"""'
+ );
+
+ is(
+ escape_xml('&&&'),
+ '&&&'
+ );
+
+ is(
+ escape_xml('<<<'),
+ '<<<'
+ );
+
+ is(
+ escape_xml('>>>'),
+ '>>>'
+ );
+
+ is(
+ escape_xml('<tag att1="foo" att2="bar">C&A</tag>'),
+ '<tag att1="foo" att2="bar">C&A</tag>'
+ );
+};
+
done_testing;