blob: a3b60e7ca1d4e87c9b2968dd14174cdd3e013f4e [file] [log] [blame]
Akron340a9cb2020-05-20 12:55:22 +02001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use File::Basename;
6use File::Spec::Functions;
Akron1c070452020-05-25 11:28:30 +02007use Data::Dumper;
Akron340a9cb2020-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');
Akron68746a12020-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
Akron1c070452020-05-25 11:28:30 +020045my $list3 = catfile(dirname(__FILE__), 'data', 'list3.def');
Akron323881c2020-05-20 17:15:42 +020046
Akron34a4f582020-05-27 12:18:57 +020047
Akron323881c2020-05-20 17:15:42 +020048# Check JSON
49# Only return extended area
Akron1c070452020-05-25 11:28:30 +020050$json = decode_json(join('', `$script $list3`));
Akron323881c2020-05-20 17:15:42 +020051
Akron34a4f582020-05-27 12:18:57 +020052is($json->{'collection'}->{'@type'}, 'koral:doc', 'type');
53
54
Akron286b46e2020-05-25 17:07:48 +020055is($json->{'collection'}->{'comment'}, 'name:"VAS-N91 (Stand \"2013\", korr. 2017)"', 'type');
Akron323881c2020-05-20 17:15:42 +020056
Akron34a4f582020-05-27 12:18:57 +020057$op1 = $json->{'collection'};
Akron323881c2020-05-20 17:15:42 +020058is($op1->{'@type'}, 'koral:doc', 'type');
59is($op1->{'key'}, 'textSigle', 'key');
60is($op1->{'match'}, 'match:eq', 'match');
61is($op1->{'value'}->[0], "A00/APR/23232", 'value');
Akron286b46e2020-05-25 17:07:48 +020062is($op1->{'value'}->[1], "A00/APR/23233", 'value');
Akron323881c2020-05-20 17:15:42 +020063
Akron1c070452020-05-25 11:28:30 +020064my $list4 = catfile(dirname(__FILE__), 'data', 'list4.def');
65
66# Only contains intended area
67$json = decode_json(join('', `$script $list4`));
68
69is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
Akron34a4f582020-05-27 12:18:57 +020070is($json->{'collection'}->{'comment'}, 'name:"VAS N91"', 'name');
Akron286b46e2020-05-25 17:07:48 +020071like($json->{'collection'}->{'comment'}, qr!^name:"VAS N91"!, 'name');
Akron1c070452020-05-25 11:28:30 +020072
Akron34a4f582020-05-27 12:18:57 +020073
74my $bz = $json->{'collection'}->{operands}->[0]->{operands}->[0];
75is($bz->{operation}, 'operation:and', 'Intersection');
76is(scalar @{$bz->{operands}}, 3, 'Flatten operands');
77
78my $faz = $json->{'collection'}->{operands}->[0]->{operands}->[1];
79is($faz->{'@type'}, 'koral:doc', 'DocVec');
80is($faz->{value}->[0], 'F97', 'Value');
81is($faz->{value}->[1], 'F99', 'Value');
Akron1c070452020-05-25 11:28:30 +020082
Akron340a9cb2020-05-20 12:55:22 +020083done_testing;
Akron34a4f582020-05-27 12:18:57 +020084__END__