4 use SQL::Abstract::Compat;
6 use Test::More tests => 12;
9 ok(my $visitor = SQL::Abstract::Compat->new);
12 my $foo_id = { -type => 'name', args => [qw/foo/] };
13 my $bar_id = { -type => 'name', args => [qw/bar/] };
15 my $foo_eq_1 = field_op_value($foo_id, '==', 1);
16 my $bar_eq_str = field_op_value($bar_id, '==', 'some str');
19 $visitor->recurse_where({ foo => 1 }),
26 $visitor->recurse_where({ foo => 1, bar => 'some str' }),
37 $visitor->recurse_where({ -or => { foo => 1, bar => 'some str' } }),
49 $visitor->recurse_where([ -and => { foo => 1, bar => 'some str' } ]),
57 "-and as first element of array";
61 $visitor->recurse_where([ -and => { foo => 1, bar => 'some str' }, { foo => 1} ]),
75 "-and as first element of array + hash";
78 $visitor->recurse_where({ foo => { '!=' => 'bar' } }),
79 field_op_value($foo_id, '!=', 'bar'),
80 "foo => { '!=' => 'bar' }";
83 $visitor->recurse_where({ foo => [ 1, 'bar' ] }),
88 field_op_value($foo_id, '==', 'bar'),
91 "foo => [ 1, 'bar' ]";
94 $visitor->recurse_where({ foo => { -in => [ 1, 'bar' ] } }),
99 { -type => 'value', value => 1 },
100 { -type => 'value', value => 'bar' },
103 "foo => { -in => [ 1, 'bar' ] }";
106 $visitor->recurse_where({ foo => { -not_in => [ 1, 'bar' ] } }),
111 { -type => 'value', value => 1 },
112 { -type => 'value', value => 'bar' },
115 "foo => { -not_in => [ 1, 'bar' ] }";
118 $visitor->recurse_where({ foo => { -in => [ ] } }),
125 "foo => { -in => [ ] }";
127 my $worker_eq = sub {
132 { -type => 'name', args => ['worker'] },
133 { -type => 'value', value => $_[0] },
138 $visitor->recurse_where( {
140 worker => ['nwiger', 'rcwe', 'sfz'],
141 status => { '!=', 'completed' }
146 field_op_value(qw/status != completed/),
150 field_op_value(qw/worker == nwiger/),
151 field_op_value(qw/worker == rcwe/),
152 field_op_value(qw/worker == sfz/),
155 field_op_value(qw/requestor == inna/),
163 my ($field, $op, $value) = @_;
165 $field = ref $field eq 'HASH'
167 : ref $field eq 'ARRAY'
168 ? { -type => 'name', args => $field }
169 : { -type => 'name', args => [$field] };
171 $value = ref $value eq 'HASH'
173 : { -type => 'value', value => $value };