Normalize handling of expected warnings/exceptions in tests
[dbsrgits/SQL-Abstract.git] / t / 00new.t
CommitLineData
32eab2da 1use strict;
41751122 2use warnings;
3use Test::More;
32eab2da 4
46dc2f3e 5use SQL::Abstract::Test import => ['is_same_sql'];
6use SQL::Abstract;
96449e8e 7
32eab2da 8my @handle_tests = (
9 #1
10 {
11 args => {logic => 'OR'},
96449e8e 12 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
32eab2da 13 },
14 #2
15 {
16 args => {},
17 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
18 },
19 #3
20 {
21 args => {case => "upper"},
22 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
23 },
24 #4
25 {
26 args => {case => "upper", cmp => "="},
27 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
28 },
29 #5
30 {
31 args => {cmp => "=", logic => 'or'},
96449e8e 32 stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )'
32eab2da 33 },
34 #6
35 {
36 args => {cmp => "like"},
37 stmt => 'SELECT * FROM test WHERE ( a LIKE ? AND b LIKE ? )'
38 },
39 #7
40 {
41 args => {logic => "or", cmp => "like"},
96449e8e 42 stmt => 'SELECT * FROM test WHERE ( a LIKE ? AND b LIKE ? )'
32eab2da 43 },
44 #8
45 {
46 args => {case => "lower"},
47 stmt => 'select * from test where ( a = ? and b = ? )'
48 },
49 #9
50 {
51 args => {case => "lower", cmp => "="},
52 stmt => 'select * from test where ( a = ? and b = ? )'
53 },
54 #10
55 {
56 args => {case => "lower", cmp => "like"},
57 stmt => 'select * from test where ( a like ? and b like ? )'
58 },
59 #11
60 {
61 args => {case => "lower", convert => "lower", cmp => "like"},
62 stmt => 'select * from test where ( lower(a) like lower(?) and lower(b) like lower(?) )'
63 },
64 #12
65 {
66 args => {convert => "Round"},
67 stmt => 'SELECT * FROM test WHERE ( ROUND(a) = ROUND(?) AND ROUND(b) = ROUND(?) )',
68 },
69 #13
70 {
71 args => {convert => "lower"},
72 stmt => 'SELECT * FROM test WHERE ( ( LOWER(ticket) = LOWER(?) ) OR ( LOWER(hostname) = LOWER(?) ) OR ( LOWER(taco) = LOWER(?) ) OR ( LOWER(salami) = LOWER(?) ) )',
96449e8e 73 where => [ { ticket => 11 }, { hostname => 11 }, { taco => 'salad' }, { salami => 'punch' } ],
32eab2da 74 },
75 #14
76 {
77 args => {convert => "upper"},
e30faf88 78 stmt => 'SELECT * FROM test WHERE ( ( UPPER(hostname) IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) AND ( ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) ) ) OR ( UPPER(tack) BETWEEN UPPER(?) AND UPPER(?) ) OR ( ( ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) ) AND ( ( UPPER(e) != UPPER(?) ) OR ( UPPER(e) != UPPER(?) ) ) AND UPPER(q) NOT IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) ) )',
428975b0 79 where => [ { ticket => [11, 12, 13],
96449e8e 80 hostname => { in => ['ntf', 'avd', 'bvd', '123'] } },
32eab2da 81 { tack => { between => [qw/tick tock/] } },
428975b0 82 { a => [qw/b c d/],
83 e => { '!=', [qw(f g)] },
96449e8e 84 q => { 'not in', [14..20] } } ],
32eab2da 85 },
86);
87
88for (@handle_tests) {
46dc2f3e 89 my $sqla = SQL::Abstract->new($_->{args});
90 my($stmt) = $sqla->select(
91 'test',
92 '*',
93 $_->{where} || { a => 4, b => 0}
94 );
96449e8e 95
46dc2f3e 96 is_same_sql($stmt, $_->{stmt});
32eab2da 97}
98
10e6c946 99done_testing;