blob: 99a95ae3e491a60d6e3ec54a9af930aa81d022e3 [file] [log] [blame]
Akron818e8522017-07-22 12:34:01 +02001use Test::More;
2use strict;
3use warnings;
4use Data::Dumper;
5
6use_ok('Krawfish::Koral');
7
8my $koral = Krawfish::Koral->new;
9
10my $qb = $koral->query_builder;
11
12$koral->query(
13 $qb->seq(
14 $qb->term('x'),
15 $qb->repeat($qb->any, 2,3),
16 $qb->token(
Akronb945c572017-07-23 14:55:00 +020017 $qb->bool_and(
Akron818e8522017-07-22 12:34:01 +020018 'a',
Akronb945c572017-07-23 14:55:00 +020019 $qb->bool_or('b','c','d'),
Akron818e8522017-07-22 12:34:01 +020020 'e'
21 )
22 )
23 )
24);
25
26my $serial = $koral->to_koral_query;
27ok(!$serial->{corpus}, 'Corpus exists not');
28ok(my $query = $serial->{query}, 'Serialization successful');
29
30is($query->{'@type'}, 'koral:group', 'Group');
31is($query->{'operation'}, 'operation:sequence', 'operation');
32ok($query->{'operands'}, 'operands');
33
34my $ops = $query->{operands};
35my $op = $ops->[0];
36
37is($op->{'@type'}, 'koral:term', 'Operand is a term');
38is($op->{key}, 'x', 'Operand is a term');
39
40$op = $ops->[1];
41is($op->{'@type'}, 'koral:group', 'Operand is a group');
42is($op->{'operation'}, 'operation:repetition', 'operation');
43ok($op->{'operands'}, 'operands');
44ok($op->{boundary}, 'Operand has a boundary');
45
46$op = $op->{operands}->[0];
47is($op->{'@type'}, 'koral:token', 'Operand is just a token');
48is(scalar(keys %{$op}), 1, 'Nothing more');
49
50my $bound = $ops->[1]->{boundary};
51is($bound->{'@type'}, 'koral:boundary', 'Boundary type');
52is($bound->{'min'}, 2, 'min');
53is($bound->{'max'}, 3, 'max');
54
55$op = $ops->[2];
56is($op->{'@type'}, 'koral:token', 'Operand is a token');
57ok($op->{'wrap'}, 'wrap');
58
59$op = $op->{wrap};
60is($op->{'@type'}, 'koral:group', 'Operand is a group');
61is($op->{'operation'}, 'operation:termGroup', 'operation');
62is($op->{'relation'}, 'relation:and', 'operation');
63ok($op->{'operands'}, 'operands');
64
65$ops = $op->{operands};
66$op = $ops->[0];
67is($op->{'@type'}, 'koral:term', 'Operand is a term');
68is($op->{key}, 'a', 'Operand is a term');
69
70$op = $ops->[2];
71is($op->{'@type'}, 'koral:term', 'Operand is a term');
72is($op->{key}, 'e', 'Operand is a term');
73
74$op = $ops->[1];
75is($op->{'@type'}, 'koral:group', 'Operand is a group');
76is($op->{'operation'}, 'operation:termGroup', 'operation');
77is($op->{'relation'}, 'relation:or', 'operation');
78ok($op->{'operands'}, 'operands');
79
80$ops = $op->{operands};
81$op = $ops->[0];
82is($op->{'@type'}, 'koral:term', 'Operand is a term');
83is($op->{key}, 'b', 'Operand is a term');
84
85$op = $ops->[1];
86is($op->{'@type'}, 'koral:term', 'Operand is a term');
87is($op->{key}, 'c', 'Operand is a term');
88
89$op = $ops->[2];
90is($op->{'@type'}, 'koral:term', 'Operand is a term');
91is($op->{key}, 'd', 'Operand is a term');
92
93
94TODO: {
95 local $TODO = 'Test Serialization output';
Akron89440982017-07-28 14:48:28 +020096 ok($koral = $koral->to_nodes, 'Finalize query');
Akron818e8522017-07-22 12:34:01 +020097};
98
99
100done_testing;
101__END__
102