blob: 1dc3c4c2ae5edd2001ed6d699520f73f52fd8e7c [file] [log] [blame]
Akron26b59702020-05-19 12:14:41 +02001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use File::Basename;
6use File::Spec::Functions;
Akron26b59702020-05-19 12:14:41 +02007use Test::Output;
8use Mojo::JSON 'decode_json';
9
Akrondd0aa3a2024-04-10 11:03:38 +020010my $script = catfile(dirname(__FILE__), '..', 'script', 'cosmasvc2koralquery');
Akron26b59702020-05-19 12:14:41 +020011my $list1 = catfile(dirname(__FILE__), 'data', 'list1.txt');
12
13# Check STDOUT
14stdout_like(
15 sub {
Akrona3f74f52024-07-17 17:18:17 +020016 system($script, 'def', $list1);
Akron26b59702020-05-19 12:14:41 +020017 },
18 qr!^\{\"\@context\".+?\}$!,
19 "check stdout"
20);
21
22# Check JSON
Akrona3f74f52024-07-17 17:18:17 +020023my $json = decode_json(join('', `$script def $list1`));
Akron26b59702020-05-19 12:14:41 +020024
25is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
26is($json->{'collection'}->{'operation'}, 'operation:or', 'operation');
27
28my $op1 = $json->{'collection'}->{'operands'}->[0];
29is($op1->{'@type'}, 'koral:doc', 'type');
30is($op1->{'key'}, 'corpusSigle', 'key');
31is($op1->{'match'}, 'match:eq', 'match');
32is_deeply($op1->{'value'}, ["A02","A03"], 'value');
33
34my $op2 = $json->{'collection'}->{'operands'}->[1];
35is($op2->{'@type'}, 'koral:doc', 'type');
36is($op2->{'key'}, 'docSigle', 'key');
37is($op2->{'match'}, 'match:eq', 'match');
38is_deeply($op2->{'value'}, ["B04/X02","B04/X03"], 'value');
39
40my $op3 = $json->{'collection'}->{'operands'}->[2];
41is($op3->{'@type'}, 'koral:doc', 'type');
42is($op3->{'key'}, 'textSigle', 'key');
43is($op3->{'match'}, 'match:eq', 'match');
44is_deeply($op3->{'value'}, ["A01/B02/c04","A01/B02/c05"], 'value');
45
46
47# Check STDIN
Akrona3f74f52024-07-17 17:18:17 +020048my $json2 = decode_json(join('', `cat $list1 | $script def -`));
Akron26b59702020-05-19 12:14:41 +020049is_deeply($json, $json2);
50
51done_testing;