Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 4 | |
| 5 | use FindBin; |
| 6 | BEGIN { |
| 7 | unshift @INC, "$FindBin::Bin/../lib"; |
| 8 | }; |
| 9 | |
Peter Harders | 42e18a6 | 2020-07-21 02:43:26 +0200 | [diff] [blame] | 10 | use Test::KorAP::XML::TEI qw!korap_tempfile!; |
| 11 | |
Akron | 0465e9e | 2020-07-27 15:55:21 +0200 | [diff] [blame^] | 12 | use_ok('KorAP::XML::TEI', 'remove_xml_comments', 'escape_xml'); |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 13 | |
Akron | 0465e9e | 2020-07-27 15:55:21 +0200 | [diff] [blame^] | 14 | subtest 'remove_xml_comments' => sub { |
| 15 | my ($fh, $filename) = korap_tempfile('tei'); |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 16 | |
Akron | 0465e9e | 2020-07-27 15:55:21 +0200 | [diff] [blame^] | 17 | print $fh <<'HTML'; |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 18 | mehrzeiliger |
| 19 | Kommentar |
| 20 | --> |
| 21 | Test |
| 22 | HTML |
| 23 | |
Akron | 0465e9e | 2020-07-27 15:55:21 +0200 | [diff] [blame^] | 24 | 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"); |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 27 | |
Akron | 0465e9e | 2020-07-27 15:55:21 +0200 | [diff] [blame^] | 28 | seek($fh, 0, 0); |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 29 | |
Akron | 0465e9e | 2020-07-27 15:55:21 +0200 | [diff] [blame^] | 30 | is(remove_xml_comments($fh, '<!--'), "Test\n"); |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 31 | |
Akron | 0465e9e | 2020-07-27 15:55:21 +0200 | [diff] [blame^] | 32 | seek($fh, 0, 0); |
Akron | 2d547bc | 2020-07-04 10:34:35 +0200 | [diff] [blame] | 33 | |
Akron | 0465e9e | 2020-07-27 15:55:21 +0200 | [diff] [blame^] | 34 | print $fh <<'HTML'; |
Akron | 2d547bc | 2020-07-04 10:34:35 +0200 | [diff] [blame] | 35 | mehrzeiliger |
| 36 | Kommentar |
| 37 | --><!-- Versuch |
| 38 | -->ist <!-- a --><!-- b --> ein Test |
| 39 | HTML |
| 40 | |
Akron | 0465e9e | 2020-07-27 15:55:21 +0200 | [diff] [blame^] | 41 | seek($fh, 0, 0); |
Akron | 2d547bc | 2020-07-04 10:34:35 +0200 | [diff] [blame] | 42 | |
Akron | 0465e9e | 2020-07-27 15:55:21 +0200 | [diff] [blame^] | 43 | is(remove_xml_comments($fh, 'Dies <!--'), "Dies ist ein Test\n"); |
Akron | 2d547bc | 2020-07-04 10:34:35 +0200 | [diff] [blame] | 44 | |
Akron | 0465e9e | 2020-07-27 15:55:21 +0200 | [diff] [blame^] | 45 | close($fh); |
| 46 | }; |
| 47 | |
| 48 | subtest 'escape_xml' => sub { |
| 49 | is( |
| 50 | escape_xml('"""'), |
| 51 | '"""' |
| 52 | ); |
| 53 | |
| 54 | is( |
| 55 | escape_xml('&&&'), |
| 56 | '&&&' |
| 57 | ); |
| 58 | |
| 59 | is( |
| 60 | escape_xml('<<<'), |
| 61 | '<<<' |
| 62 | ); |
| 63 | |
| 64 | is( |
| 65 | escape_xml('>>>'), |
| 66 | '>>>' |
| 67 | ); |
| 68 | |
| 69 | is( |
| 70 | escape_xml('<tag att1="foo" att2="bar">C&A</tag>'), |
| 71 | '<tag att1="foo" att2="bar">C&A</tag>' |
| 72 | ); |
| 73 | }; |
| 74 | |
Akron | 2d547bc | 2020-07-04 10:34:35 +0200 | [diff] [blame] | 75 | |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 76 | done_testing; |