Akron | 1e6f4d4 | 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; |
| 7 | |
| 8 | use Test::Output; |
| 9 | use Mojo::JSON 'decode_json'; |
| 10 | |
| 11 | my $script = catfile(dirname(__FILE__), '..', 'list2vc.pl'); |
| 12 | my $list1 = catfile(dirname(__FILE__), 'data', 'list1.txt'); |
| 13 | |
| 14 | # Check STDOUT |
| 15 | stdout_like( |
| 16 | sub { |
| 17 | system($script, $list1); |
| 18 | }, |
| 19 | qr!^\{\"\@context\".+?\}$!, |
| 20 | "check stdout" |
| 21 | ); |
| 22 | |
| 23 | # Check JSON |
| 24 | my $json = decode_json(join('', `$script $list1`)); |
| 25 | |
| 26 | is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type'); |
| 27 | is($json->{'collection'}->{'operation'}, 'operation:or', 'operation'); |
| 28 | |
| 29 | my $op1 = $json->{'collection'}->{'operands'}->[0]; |
| 30 | is($op1->{'@type'}, 'koral:doc', 'type'); |
| 31 | is($op1->{'key'}, 'corpusSigle', 'key'); |
| 32 | is($op1->{'match'}, 'match:eq', 'match'); |
| 33 | is_deeply($op1->{'value'}, ["A02","A03"], 'value'); |
| 34 | |
| 35 | my $op2 = $json->{'collection'}->{'operands'}->[1]; |
| 36 | is($op2->{'@type'}, 'koral:doc', 'type'); |
| 37 | is($op2->{'key'}, 'docSigle', 'key'); |
| 38 | is($op2->{'match'}, 'match:eq', 'match'); |
| 39 | is_deeply($op2->{'value'}, ["B04/X02","B04/X03"], 'value'); |
| 40 | |
| 41 | my $op3 = $json->{'collection'}->{'operands'}->[2]; |
| 42 | is($op3->{'@type'}, 'koral:doc', 'type'); |
| 43 | is($op3->{'key'}, 'textSigle', 'key'); |
| 44 | is($op3->{'match'}, 'match:eq', 'match'); |
| 45 | is_deeply($op3->{'value'}, ["A01/B02/c04","A01/B02/c05"], 'value'); |
| 46 | |
| 47 | |
| 48 | # Check STDIN |
| 49 | my $json2 = decode_json(join('', `cat $list1 | $script -`)); |
| 50 | is_deeply($json, $json2); |
| 51 | |
| 52 | done_testing; |