blob: 73c3515c24b71e52ddf78c692e17cd777b8c63a9 [file] [log] [blame]
Marc Kupietzbb739b02020-09-22 16:49:34 +02001use strict;
2use warnings;
3use Test::More;
4use Test::Script;
Marc Kupietz79ba1e52021-02-12 17:26:54 +01005use Test::TempDir::Tiny;
6use File::Copy;
Marc Kupietzbb739b02020-09-22 16:49:34 +02007
8script_runs([ 'script/korapxml2conllu', '-h' ], { exit => 255 });
9script_stderr_like "Description", "Can print help message";
10
11for my $morpho_fname (glob("t/data/*\.*\.zip")) {
12 my $base_fname = $morpho_fname =~ s/(.*)\..*\.zip/$1.zip/r;
13 die "cannot find $base_fname" if (!-e $base_fname);
14
Marc Kupietzd8455832021-02-11 17:30:29 +010015 my $conllu_fname = $base_fname =~ s/(.*)\.zip/$1.morpho.conllu/r;
Marc Kupietzbb739b02020-09-22 16:49:34 +020016 die "cannot find $conllu_fname" if (!-e $conllu_fname);
17
18 my $expected;
19 open(my $fh, '<', $conllu_fname) or die "cannot open file $conllu_fname"; {
20 local $/;
21 $expected = <$fh>;
22 }
23 close($fh);
Marc Kupietz13994d12021-02-12 17:25:36 +010024 script_runs([ 'script/korapxml2conllu', $morpho_fname ], "Runs korapxml2conllu with pos and lemma annotated input");
Marc Kupietzbb739b02020-09-22 16:49:34 +020025 script_stdout_is $expected, "Converts $morpho_fname correctly";
26}
Marc Kupietzd8455832021-02-11 17:30:29 +010027
28for my $base_fname (glob("t/data/*\.zip")) {
Marc Kupietzd8455832021-02-11 17:30:29 +010029 my $conllu_fname = $base_fname =~ s/(.*)\.zip/$1.conllu/r;
Marc Kupietz628893e2021-02-12 15:50:29 +010030 next if (!-e $conllu_fname);
Marc Kupietzd8455832021-02-11 17:30:29 +010031
32 my $expected;
33 open(my $fh, '<', $conllu_fname) or die "cannot open file $conllu_fname"; {
34 local $/;
35 $expected = <$fh>;
36 }
37 close($fh);
Marc Kupietz13994d12021-02-12 17:25:36 +010038 script_runs([ 'script/korapxml2conllu', $base_fname ], "Runs korapxml2conllu with base input");
39 script_stdout_is $expected, "Converts $base_fname correctly to CoNLL-U";
Marc Kupietzd8455832021-02-11 17:30:29 +010040}
41
Marc Kupietz79ba1e52021-02-12 17:26:54 +010042my $test_tempdir = tempdir();
43my $expected;
44open(my $fh, '<', "t/data/goe.morpho.conllu"); {
45 local $/;
46 $expected = <$fh>;
47}
48close($fh);
49
50my $zipfile = "$test_tempdir/goe.tree_tagger.zip";
51my $zipcontent;
52script_runs([ 'script/conllu2korapxml', "t/data/goe.morpho.conllu" ], {stdout => \$zipcontent},
53 "Converts t/data/goe.morpho.conllu to KorAP-XML zip");
54open(my $fh, ">", $zipfile) or fail("cannot open file $zipfile for writing");
55print $fh $zipcontent;
56close($fh);
57
58copy("t/data/goe.zip", $test_tempdir);
59script_runs([ 'script/korapxml2conllu', "$test_tempdir/goe.tree_tagger.zip" ],
60 "Converts $test_tempdir/goe.tree_tagger.zip to CoNLL-U");
61script_stdout_is $expected, "Full round trip: Converts goe.morpho.conllu to KorAP-XML and back to CoNLL-U correctly";
62
63done_testing;