SELECT a, b FROM foo
[dbsrgits/Data-Query.git] / t / expr.t
CommitLineData
9ee33178 1use strictures 1;
2use Test::More qw(no_plan);
9e0200bc 3use Test::Exception;
9ee33178 4
7f666d37 5BEGIN { require 't/expr.include' }
9ee33178 6
7sub expr_is (&;@) {
8 my $sub = shift;
2cf0bb42 9 is_deeply(_run_expr($sub)->{expr}, @_);
9ee33178 10}
11
12expr_is { $_->foo }
13 {
14 type => DQ_IDENTIFIER,
15 elements => [ 'foo' ]
16 },
17 'Simple identifier ok';
18
19
20expr_is { $_->foo->bar }
21 {
22 type => DQ_IDENTIFIER,
23 elements => [ 'foo', 'bar' ]
24 },
25 'Nested identifier ok';
b616bc41 26
27expr_is { $_->foo == 3 }
28 {
29 type => DQ_OPERATOR,
d68bc999 30 operator => { Perl => '==' },
b616bc41 31 args => [
32 expr { $_->foo },
33 {
34 type => DQ_VALUE,
d68bc999 35 subtype => { Perl => 'Scalar' },
b616bc41 36 value => 3,
37 },
38 ],
39 },
40 'Simple equality ok';
ef94e94d 41
42expr_is { $_->foo == 3 }
43 {
44 type => DQ_OPERATOR,
d68bc999 45 operator => { Perl => '==' },
ef94e94d 46 args => [
47 expr { $_->foo },
48 {
49 type => DQ_VALUE,
d68bc999 50 subtype => { Perl => 'Scalar' },
ef94e94d 51 value => 3,
52 },
53 ],
54 },
55 'Simple equality ok';
56
57expr_is { 3 == $_->foo }
58 {
59 type => DQ_OPERATOR,
d68bc999 60 operator => { Perl => '==' },
ef94e94d 61 args => [
62 {
63 type => DQ_VALUE,
d68bc999 64 subtype => { Perl => 'Scalar' },
ef94e94d 65 value => 3,
66 },
67 expr { $_->foo },
68 ],
69 },
70 'Operand reversed equality ok';
9e0200bc 71
72throws_ok {
73 expr { $_->foo <=> 3 }
74} qr/\QCan't use operator <=>/, 'Exception on bad operator';
7e599929 75
76expr_is { $_->foo & $_->bar }
77 {
78 type => DQ_OPERATOR,
d68bc999 79 operator => { Perl => 'and' },
7e599929 80 args => [
81 expr { $_->foo },
82 expr { $_->bar },
83 ],
84 },
85 'Masquerade for & as and ok';
86
87expr_is { $_->foo | $_->bar }
88 {
89 type => DQ_OPERATOR,
d68bc999 90 operator => { Perl => 'or' },
7e599929 91 args => [
92 expr { $_->foo },
93 expr { $_->bar },
94 ],
95 },
96 'Masquerade for | as or ok';
c3633a0e 97
98expr_is { !$_->foo }
99 {
100 type => DQ_OPERATOR,
d68bc999 101 operator => { Perl => '!' },
c3633a0e 102 args => [ expr { $_->foo } ],
103 },
104 '! ok';