blob: baaefda1b29dff53891aa6dfb1774d6b5caa62e6 [file] [log] [blame]
Akron1839cb12020-05-20 12:55:22 +02001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use File::Basename;
6use File::Spec::Functions;
Akron36a9b872020-05-25 11:28:30 +02007use Data::Dumper;
Akron1839cb12020-05-20 12:55:22 +02008
9use Test::Output;
10use Mojo::JSON 'decode_json';
11
12my $script = catfile(dirname(__FILE__), '..', 'list2vc.pl');
13my $list1 = catfile(dirname(__FILE__), 'data', 'list2.def');
14
15# Check STDOUT
16stdout_like(
17 sub {
18 system($script, $list1);
19 },
20 qr!^\{\"\@context\".+?\}$!,
21 "check stdout"
22);
23
24# Check JSON
25my $json = decode_json(join('', `$script $list1`));
26
27is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
28is($json->{'collection'}->{'operation'}, 'operation:or', 'operation');
29
30my $op1 = $json->{'collection'}->{'operands'}->[0];
31is($op1->{'@type'}, 'koral:doc', 'type');
32is($op1->{'key'}, 'docSigle', 'key');
33is($op1->{'match'}, 'match:eq', 'match');
34is($op1->{'value'}->[0], "BRZ05/SEP", 'value');
35is($op1->{'value'}->[1], ,"BRZ05/OKT", 'value');
36is($op1->{'value'}->[-1], ,"BRZ08/FEB", 'value');
Akronee2073d2020-05-20 15:19:55 +020037
38my $op2 = $json->{'collection'}->{'operands'}->[1];
39is($op2->{'@type'}, 'koral:doc', 'type');
40is($op2->{'key'}, 'textSigle', 'key');
41is($op2->{'match'}, 'match:eq', 'match');
42is($op2->{'value'}->[0], "B19/AUG/01665", 'value');
43is($op2->{'value'}->[1], ,"B19/AUG/01666", 'value');
44
Akron36a9b872020-05-25 11:28:30 +020045my $list3 = catfile(dirname(__FILE__), 'data', 'list3.def');
Akron1d3bd4a2020-05-20 17:15:42 +020046
47# Check JSON
48# Only return extended area
Akron36a9b872020-05-25 11:28:30 +020049$json = decode_json(join('', `$script $list3`));
Akron1d3bd4a2020-05-20 17:15:42 +020050
51is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
52is($json->{'collection'}->{'operation'}, 'operation:or', 'operation');
Akron701139e2020-05-25 17:07:48 +020053is($json->{'collection'}->{'comment'}, 'name:"VAS-N91 (Stand \"2013\", korr. 2017)"', 'type');
Akron1d3bd4a2020-05-20 17:15:42 +020054
55$op1 = $json->{'collection'}->{'operands'}->[0];
56is($op1->{'@type'}, 'koral:doc', 'type');
57is($op1->{'key'}, 'textSigle', 'key');
58is($op1->{'match'}, 'match:eq', 'match');
59is($op1->{'value'}->[0], "A00/APR/23232", 'value');
Akron701139e2020-05-25 17:07:48 +020060is($op1->{'value'}->[1], "A00/APR/23233", 'value');
Akron1d3bd4a2020-05-20 17:15:42 +020061
Akron36a9b872020-05-25 11:28:30 +020062
63my $list4 = catfile(dirname(__FILE__), 'data', 'list4.def');
64
65# Only contains intended area
66$json = decode_json(join('', `$script $list4`));
67
68is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
69is($json->{'collection'}->{'operation'}, 'operation:or', 'operation');
Akron701139e2020-05-25 17:07:48 +020070like($json->{'collection'}->{'comment'}, qr!^name:"VAS N91"!, 'name');
71like($json->{'collection'}->{'comment'}, qr!embed:\[name:"Berliner Zeitung",redabs:143237\]!, 'embed');
72like($json->{'collection'}->{'comment'}, qr!embed:\[name:"Frankfurter Allgemeine",redabs:301166\]!, 'embed');
Akron36a9b872020-05-25 11:28:30 +020073
Akron701139e2020-05-25 17:07:48 +020074$op1 = $json->{'collection'}->{'operands'}->[0];
75is($op1->{'@type'}, 'koral:doc', 'type');
76is($op1->{'key'}, 'corpusSigle', 'key');
77is($op1->{'match'}, 'match:eq', 'match');
78is($op1->{'value'}->[0], "F97", 'value');
79is($op1->{'value'}->[1], "F99", 'value');
Akron36a9b872020-05-25 11:28:30 +020080
Akron1839cb12020-05-20 12:55:22 +020081done_testing;