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