blob: 5d60594e0d4ced8b6b4322176a1e8f1a62982fbb [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');
Akron9e69a222024-07-26 12:28:12 +020012my $list1b = catfile(dirname(__FILE__), 'data', 'list1b.txt');
Akron26b59702020-05-19 12:14:41 +020013
14# Check STDOUT
15stdout_like(
16 sub {
Akrona3f74f52024-07-17 17:18:17 +020017 system($script, 'def', $list1);
Akron26b59702020-05-19 12:14:41 +020018 },
19 qr!^\{\"\@context\".+?\}$!,
20 "check stdout"
21);
22
23# Check JSON
Akrona3f74f52024-07-17 17:18:17 +020024my $json = decode_json(join('', `$script def $list1`));
Akron26b59702020-05-19 12:14:41 +020025
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
Akron9e69a222024-07-26 12:28:12 +020048# Check old sigles format
49$json = decode_json(join('', `$script def $list1b`));
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'}, 'corpusSigle', 'key');
57is($op1->{'match'}, 'match:eq', 'match');
58is_deeply($op1->{'value'}, ["A02","A03"], 'value');
59
60$op2 = $json->{'collection'}->{'operands'}->[1];
61is($op2->{'@type'}, 'koral:doc', 'type');
62is($op2->{'key'}, 'docSigle', 'key');
63is($op2->{'match'}, 'match:eq', 'match');
64is_deeply($op2->{'value'}, ["B04/X02","B04/X03"], 'value');
65
66$op3 = $json->{'collection'}->{'operands'}->[2];
67is($op3->{'@type'}, 'koral:doc', 'type');
68is($op3->{'key'}, 'textSigle', 'key');
69is($op3->{'match'}, 'match:eq', 'match');
70is_deeply($op3->{'value'}, ["A01/B02/c04","A01/B02/c05"], 'value');
71
72
Akron26b59702020-05-19 12:14:41 +020073# Check STDIN
Akrona3f74f52024-07-17 17:18:17 +020074my $json2 = decode_json(join('', `cat $list1 | $script def -`));
Akron26b59702020-05-19 12:14:41 +020075is_deeply($json, $json2);
76
77done_testing;