Commit | Line | Data |
d70ca130 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use SQL::Abstract::AST::Compat; |
5 | |
6 | use Test::More tests => 6; |
7 | use Test::Differences; |
8 | |
9 | ok(my $visitor = SQL::Abstract::AST::Compat->new); |
10 | |
11 | my $foo_eq_1 = { |
12 | -type => 'expr', |
13 | op => '==', |
14 | args => [ |
15 | { -type => 'name', args => [qw/foo/] }, |
16 | { -type => 'value', value => 1 } |
17 | ] |
18 | }; |
19 | |
20 | eq_or_diff |
21 | $visitor->generate({ foo => 1 }), |
22 | $foo_eq_1, |
23 | "Single value hash"; |
24 | |
25 | |
26 | my $bar_eq_str = { |
27 | -type => 'expr', |
28 | op => '==', |
29 | args => [ |
30 | { -type => 'name', args => [qw/bar/] }, |
31 | { -type => 'value', value => 'some str' } |
32 | ] |
33 | }; |
34 | |
35 | eq_or_diff |
36 | $visitor->generate({ foo => 1, bar => 'some str' }), |
37 | { -type => 'expr', |
38 | op => 'and', |
39 | args => [ |
40 | $bar_eq_str, |
41 | $foo_eq_1, |
42 | ] |
43 | }, |
44 | "two keys in hash"; |
45 | |
46 | eq_or_diff |
47 | $visitor->generate({ -or => { foo => 1, bar => 'some str' } }), |
48 | { -type => 'expr', |
49 | op => 'or', |
50 | args => [ |
51 | $bar_eq_str, |
52 | $foo_eq_1, |
53 | ] |
54 | }, |
55 | "-or key in hash"; |
56 | |
57 | |
58 | eq_or_diff |
59 | $visitor->generate([ -and => { foo => 1, bar => 'some str' } ]), |
60 | { -type => 'expr', |
61 | op => 'and', |
62 | args => [ |
63 | $bar_eq_str, |
64 | $foo_eq_1, |
65 | ] |
66 | }, |
67 | "-and as first element of array"; |
68 | |
69 | |
70 | eq_or_diff |
71 | $visitor->generate([ -and => { foo => 1, bar => 'some str' }, { foo => 1} ]), |
72 | { -type => 'expr', |
73 | op => 'or', |
74 | args => [ |
75 | { -type => 'expr', |
76 | op => 'and', |
77 | args => [ |
78 | $bar_eq_str, |
79 | $foo_eq_1, |
80 | ] |
81 | }, |
82 | $foo_eq_1, |
83 | ] |
84 | }, |
85 | "-and as first element of array"; |