| 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; | 
| Akron | 36a9b87 | 2020-05-25 11:28:30 +0200 | [diff] [blame] | 7 | use Data::Dumper; | 
| Akron | 1839cb1 | 2020-05-20 12:55:22 +0200 | [diff] [blame] | 8 |  | 
|  | 9 | use Test::Output; | 
|  | 10 | use Mojo::JSON 'decode_json'; | 
|  | 11 |  | 
|  | 12 | my $script = catfile(dirname(__FILE__), '..', 'list2vc.pl'); | 
|  | 13 | my $list1 = catfile(dirname(__FILE__), 'data', 'list2.def'); | 
|  | 14 |  | 
|  | 15 | # Check STDOUT | 
|  | 16 | stdout_like( | 
|  | 17 | sub { | 
|  | 18 | system($script, $list1); | 
|  | 19 | }, | 
|  | 20 | qr!^\{\"\@context\".+?\}$!, | 
|  | 21 | "check stdout" | 
|  | 22 | ); | 
|  | 23 |  | 
|  | 24 | # Check JSON | 
|  | 25 | my $json = decode_json(join('', `$script $list1`)); | 
|  | 26 |  | 
|  | 27 | is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type'); | 
|  | 28 | is($json->{'collection'}->{'operation'}, 'operation:or', 'operation'); | 
|  | 29 |  | 
|  | 30 | my $op1 = $json->{'collection'}->{'operands'}->[0]; | 
|  | 31 | is($op1->{'@type'}, 'koral:doc', 'type'); | 
|  | 32 | is($op1->{'key'}, 'docSigle', 'key'); | 
|  | 33 | is($op1->{'match'}, 'match:eq', 'match'); | 
|  | 34 | is($op1->{'value'}->[0], "BRZ05/SEP", 'value'); | 
|  | 35 | is($op1->{'value'}->[1], ,"BRZ05/OKT", 'value'); | 
|  | 36 | is($op1->{'value'}->[-1], ,"BRZ08/FEB", 'value'); | 
| Akron | ee2073d | 2020-05-20 15:19:55 +0200 | [diff] [blame] | 37 |  | 
|  | 38 | my $op2 = $json->{'collection'}->{'operands'}->[1]; | 
|  | 39 | is($op2->{'@type'}, 'koral:doc', 'type'); | 
|  | 40 | is($op2->{'key'}, 'textSigle', 'key'); | 
|  | 41 | is($op2->{'match'}, 'match:eq', 'match'); | 
|  | 42 | is($op2->{'value'}->[0], "B19/AUG/01665", 'value'); | 
|  | 43 | is($op2->{'value'}->[1], ,"B19/AUG/01666", 'value'); | 
|  | 44 |  | 
| Akron | 36a9b87 | 2020-05-25 11:28:30 +0200 | [diff] [blame] | 45 | my $list3 = catfile(dirname(__FILE__), 'data', 'list3.def'); | 
| Akron | 1d3bd4a | 2020-05-20 17:15:42 +0200 | [diff] [blame] | 46 |  | 
| Akron | 7dacd01 | 2020-05-27 12:18:57 +0200 | [diff] [blame] | 47 |  | 
| Akron | 1d3bd4a | 2020-05-20 17:15:42 +0200 | [diff] [blame] | 48 | # Check JSON | 
|  | 49 | # Only return extended area | 
| Akron | 36a9b87 | 2020-05-25 11:28:30 +0200 | [diff] [blame] | 50 | $json = decode_json(join('', `$script $list3`)); | 
| Akron | 1d3bd4a | 2020-05-20 17:15:42 +0200 | [diff] [blame] | 51 |  | 
| Akron | 7dacd01 | 2020-05-27 12:18:57 +0200 | [diff] [blame] | 52 | is($json->{'collection'}->{'@type'}, 'koral:doc', 'type'); | 
|  | 53 |  | 
|  | 54 |  | 
| Akron | 701139e | 2020-05-25 17:07:48 +0200 | [diff] [blame] | 55 | is($json->{'collection'}->{'comment'}, 'name:"VAS-N91 (Stand \"2013\", korr. 2017)"', 'type'); | 
| Akron | 1d3bd4a | 2020-05-20 17:15:42 +0200 | [diff] [blame] | 56 |  | 
| Akron | 7dacd01 | 2020-05-27 12:18:57 +0200 | [diff] [blame] | 57 | $op1 = $json->{'collection'}; | 
| Akron | 1d3bd4a | 2020-05-20 17:15:42 +0200 | [diff] [blame] | 58 | is($op1->{'@type'}, 'koral:doc', 'type'); | 
|  | 59 | is($op1->{'key'}, 'textSigle', 'key'); | 
|  | 60 | is($op1->{'match'}, 'match:eq', 'match'); | 
|  | 61 | is($op1->{'value'}->[0], "A00/APR/23232", 'value'); | 
| Akron | 701139e | 2020-05-25 17:07:48 +0200 | [diff] [blame] | 62 | is($op1->{'value'}->[1], "A00/APR/23233", 'value'); | 
| Akron | 1d3bd4a | 2020-05-20 17:15:42 +0200 | [diff] [blame] | 63 |  | 
| Akron | 36a9b87 | 2020-05-25 11:28:30 +0200 | [diff] [blame] | 64 | my $list4 = catfile(dirname(__FILE__), 'data', 'list4.def'); | 
|  | 65 |  | 
|  | 66 | # Only contains intended area | 
|  | 67 | $json = decode_json(join('', `$script $list4`)); | 
|  | 68 |  | 
|  | 69 | is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type'); | 
| Akron | 7dacd01 | 2020-05-27 12:18:57 +0200 | [diff] [blame] | 70 | is($json->{'collection'}->{'comment'}, 'name:"VAS N91"', 'name'); | 
| Akron | 701139e | 2020-05-25 17:07:48 +0200 | [diff] [blame] | 71 | like($json->{'collection'}->{'comment'}, qr!^name:"VAS N91"!, 'name'); | 
| Akron | 36a9b87 | 2020-05-25 11:28:30 +0200 | [diff] [blame] | 72 |  | 
| Akron | 7dacd01 | 2020-05-27 12:18:57 +0200 | [diff] [blame] | 73 |  | 
|  | 74 | my $bz = $json->{'collection'}->{operands}->[0]->{operands}->[0]; | 
|  | 75 | is($bz->{operation}, 'operation:and', 'Intersection'); | 
|  | 76 | is(scalar @{$bz->{operands}}, 3, 'Flatten operands'); | 
|  | 77 |  | 
|  | 78 | my $faz = $json->{'collection'}->{operands}->[0]->{operands}->[1]; | 
|  | 79 | is($faz->{'@type'}, 'koral:doc', 'DocVec'); | 
|  | 80 | is($faz->{value}->[0], 'F97', 'Value'); | 
|  | 81 | is($faz->{value}->[1], 'F99', 'Value'); | 
| Akron | 36a9b87 | 2020-05-25 11:28:30 +0200 | [diff] [blame] | 82 |  | 
| Akron | 1839cb1 | 2020-05-20 12:55:22 +0200 | [diff] [blame] | 83 | done_testing; | 
| Akron | 7dacd01 | 2020-05-27 12:18:57 +0200 | [diff] [blame] | 84 | __END__ |