Akron | 1839cb1 | 2020-05-20 12:55:22 +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', 'list2.def'); |
| 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'}, 'docSigle', 'key'); |
| 32 | is($op1->{'match'}, 'match:eq', 'match'); |
| 33 | is($op1->{'value'}->[0], "BRZ05/SEP", 'value'); |
| 34 | is($op1->{'value'}->[1], ,"BRZ05/OKT", 'value'); |
| 35 | is($op1->{'value'}->[-1], ,"BRZ08/FEB", 'value'); |
Akron | ee2073d | 2020-05-20 15:19:55 +0200 | [diff] [blame] | 36 | |
| 37 | my $op2 = $json->{'collection'}->{'operands'}->[1]; |
| 38 | is($op2->{'@type'}, 'koral:doc', 'type'); |
| 39 | is($op2->{'key'}, 'textSigle', 'key'); |
| 40 | is($op2->{'match'}, 'match:eq', 'match'); |
| 41 | is($op2->{'value'}->[0], "B19/AUG/01665", 'value'); |
| 42 | is($op2->{'value'}->[1], ,"B19/AUG/01666", 'value'); |
| 43 | |
Akron | 1d3bd4a | 2020-05-20 17:15:42 +0200 | [diff] [blame] | 44 | |
| 45 | my $list2 = catfile(dirname(__FILE__), 'data', 'list3.def'); |
| 46 | |
| 47 | # Check JSON |
| 48 | # Only return extended area |
| 49 | $json = decode_json(join('', `$script $list2`)); |
| 50 | |
| 51 | is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type'); |
| 52 | is($json->{'collection'}->{'operation'}, 'operation:or', 'operation'); |
Akron | 5368b6c | 2020-05-20 17:50:38 +0200 | [diff] [blame^] | 53 | is($json->{'collection'}->{'comment'}, 'Name: "VAS-N91 (Stand \"2013\", korr. 2017)"', 'type'); |
| 54 | |
Akron | 1d3bd4a | 2020-05-20 17:15:42 +0200 | [diff] [blame] | 55 | |
| 56 | $op1 = $json->{'collection'}->{'operands'}->[0]; |
| 57 | is($op1->{'@type'}, 'koral:doc', 'type'); |
| 58 | is($op1->{'key'}, 'textSigle', 'key'); |
| 59 | is($op1->{'match'}, 'match:eq', 'match'); |
| 60 | is($op1->{'value'}->[0], "A00/APR/23232", 'value'); |
| 61 | is($op1->{'value'}->[1], ,"A00/APR/23233", 'value'); |
| 62 | |
Akron | 1839cb1 | 2020-05-20 12:55:22 +0200 | [diff] [blame] | 63 | done_testing; |