blob: d38d9ee58d1111afd17e3bbc6117c006fa5838d9 [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;
7
8use Test::Output;
9use Mojo::JSON 'decode_json';
10
11my $script = catfile(dirname(__FILE__), '..', 'list2vc.pl');
12my $list1 = catfile(dirname(__FILE__), 'data', 'list2.def');
13
14# Check STDOUT
15stdout_like(
16 sub {
17 system($script, $list1);
18 },
19 qr!^\{\"\@context\".+?\}$!,
20 "check stdout"
21);
22
23# Check JSON
24my $json = decode_json(join('', `$script $list1`));
25
26is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
27is($json->{'collection'}->{'operation'}, 'operation:or', 'operation');
28
29my $op1 = $json->{'collection'}->{'operands'}->[0];
30is($op1->{'@type'}, 'koral:doc', 'type');
31is($op1->{'key'}, 'docSigle', 'key');
32is($op1->{'match'}, 'match:eq', 'match');
33is($op1->{'value'}->[0], "BRZ05/SEP", 'value');
34is($op1->{'value'}->[1], ,"BRZ05/OKT", 'value');
35is($op1->{'value'}->[-1], ,"BRZ08/FEB", 'value');
Akron68746a12020-05-20 15:19:55 +020036
37my $op2 = $json->{'collection'}->{'operands'}->[1];
38is($op2->{'@type'}, 'koral:doc', 'type');
39is($op2->{'key'}, 'textSigle', 'key');
40is($op2->{'match'}, 'match:eq', 'match');
41is($op2->{'value'}->[0], "B19/AUG/01665", 'value');
42is($op2->{'value'}->[1], ,"B19/AUG/01666", 'value');
43
Akron323881c2020-05-20 17:15:42 +020044
45my $list2 = catfile(dirname(__FILE__), 'data', 'list3.def');
46
47# Check JSON
48# Only return extended area
49$json = decode_json(join('', `$script $list2`));
50
51is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
52is($json->{'collection'}->{'operation'}, 'operation:or', 'operation');
53
54$op1 = $json->{'collection'}->{'operands'}->[0];
55is($op1->{'@type'}, 'koral:doc', 'type');
56is($op1->{'key'}, 'textSigle', 'key');
57is($op1->{'match'}, 'match:eq', 'match');
58is($op1->{'value'}->[0], "A00/APR/23232", 'value');
59is($op1->{'value'}->[1], ,"A00/APR/23233", 'value');
60
Akron340a9cb2020-05-20 12:55:22 +020061done_testing;