blob: 93b522648b90bd9f467e7849fb3607d62ebe468b [file] [log] [blame]
Akron1e6f4d42020-05-19 12:14:41 +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', 'list1.txt');
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'}, 'corpusSigle', 'key');
32is($op1->{'match'}, 'match:eq', 'match');
33is_deeply($op1->{'value'}, ["A02","A03"], 'value');
34
35my $op2 = $json->{'collection'}->{'operands'}->[1];
36is($op2->{'@type'}, 'koral:doc', 'type');
37is($op2->{'key'}, 'docSigle', 'key');
38is($op2->{'match'}, 'match:eq', 'match');
39is_deeply($op2->{'value'}, ["B04/X02","B04/X03"], 'value');
40
41my $op3 = $json->{'collection'}->{'operands'}->[2];
42is($op3->{'@type'}, 'koral:doc', 'type');
43is($op3->{'key'}, 'textSigle', 'key');
44is($op3->{'match'}, 'match:eq', 'match');
45is_deeply($op3->{'value'}, ["A01/B02/c04","A01/B02/c05"], 'value');
46
47
48# Check STDIN
49my $json2 = decode_json(join('', `cat $list1 | $script -`));
50is_deeply($json, $json2);
51
52done_testing;