Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use File::Temp 'tempfile'; |
| 5 | |
| 6 | use FindBin; |
| 7 | BEGIN { |
| 8 | unshift @INC, "$FindBin::Bin/../lib"; |
| 9 | }; |
| 10 | |
Peter Harders | 57c884e | 2020-07-16 01:28:52 +0200 | [diff] [blame] | 11 | our %ENV; |
| 12 | # default: remove temp. file created by func. tempfile |
| 13 | # to keep temp. files use e.g. 'KORAPXMLTEI_DONTUNLINK=1 prove -lr t/script.t' |
| 14 | my $_UNLINK = $ENV{KORAPXMLTEI_DONTUNLINK}?0:1; |
| 15 | |
Akron | 95bc98a | 2020-07-11 12:00:12 +0200 | [diff] [blame] | 16 | use_ok('KorAP::XML::TEI', 'remove_xml_comments'); |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 17 | |
Peter Harders | 57c884e | 2020-07-16 01:28:52 +0200 | [diff] [blame] | 18 | my ($fh, $filename) = tempfile("KorAP-XML-TEI_tei_XXXXXXXXXX", SUFFIX => ".tmp", TMPDIR => 1, UNLINK => $_UNLINK); |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 19 | |
| 20 | print $fh <<'HTML'; |
| 21 | mehrzeiliger |
| 22 | Kommentar |
| 23 | --> |
| 24 | Test |
| 25 | HTML |
| 26 | |
Akron | 95bc98a | 2020-07-11 12:00:12 +0200 | [diff] [blame] | 27 | is(remove_xml_comments($fh, "hallo"),"hallo"); |
| 28 | is(remove_xml_comments($fh, "hallo <!-- Test -->"),"hallo "); |
| 29 | is(remove_xml_comments($fh, "<!-- Test --> hallo")," hallo"); |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 30 | |
| 31 | seek($fh, 0, 0); |
| 32 | |
Akron | 95bc98a | 2020-07-11 12:00:12 +0200 | [diff] [blame] | 33 | is(remove_xml_comments($fh, '<!--'), "Test\n"); |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 34 | |
Akron | 2d547bc | 2020-07-04 10:34:35 +0200 | [diff] [blame] | 35 | seek($fh, 0, 0); |
| 36 | |
| 37 | print $fh <<'HTML'; |
| 38 | mehrzeiliger |
| 39 | Kommentar |
| 40 | --><!-- Versuch |
| 41 | -->ist <!-- a --><!-- b --> ein Test |
| 42 | HTML |
| 43 | |
| 44 | seek($fh, 0, 0); |
| 45 | |
Akron | 95bc98a | 2020-07-11 12:00:12 +0200 | [diff] [blame] | 46 | is(remove_xml_comments($fh, 'Dies <!--'), "Dies ist ein Test\n"); |
Akron | 2d547bc | 2020-07-04 10:34:35 +0200 | [diff] [blame] | 47 | |
| 48 | close($fh); |
| 49 | |
Akron | 4f67cd4 | 2020-07-02 12:27:58 +0200 | [diff] [blame] | 50 | done_testing; |