1use strict;
2use warnings;
3use utf8;
4use Test::More;
5use SQL::Maker;
6use SQL::QueryMaker qw(sql_eq);
7
8my $maker = SQL::Maker->new(
9    driver => 'SQLite',
10    quote_char => ':',
11    name_sep => '-',
12    new_line => ' ',
13);
14
15my @condition_cases = (
16    {
17        label => 'Condition',
18        cond_maker => sub {
19            my $cond = $maker->new_condition;
20            $cond->add('foo-bar' => 'buzz');
21            return $cond;
22        },
23    },
24    {
25        label => 'QueryMaker',
26        cond_maker => sub {
27            return sql_eq('foo-bar', 'buzz');
28        },
29    },
30    {
31        label => 'QueryMaker in Condition',
32        cond_maker => sub {
33            my $cond = $maker->new_condition;
34            $cond->add('foo-bar' => sql_eq('buzz'));
35            return $cond;
36        },
37    },
38);
39
40foreach my $cond_case (@condition_cases) {
41    subtest "select: $cond_case->{label}" => sub {
42        my $cond = $cond_case->{cond_maker}();
43        my ($sql, @binds) = $maker->select("table", ["*"], $cond);
44        like $sql, qr/:foo:-:bar:/;
45    };
46
47    subtest "update: $cond_case->{label}" => sub {
48        my $cond = $cond_case->{cond_maker}();
49        my ($sql, @binds) = $maker->update("table", ["a" => "A"], $cond);
50        like $sql, qr/:foo:-:bar:/;
51    };
52
53    subtest "delete: $cond_case->{label}" => sub {
54        my $cond = $cond_case->{cond_maker}();
55        my ($sql, @binds) = $maker->delete("table", $cond);
56        like $sql, qr/:foo:-:bar:/;
57    };
58
59    subtest "where: $cond_case->{label}" => sub {
60        my $cond = $cond_case->{cond_maker}();
61        my ($sql, @binds) = $maker->where($cond);
62        like $sql, qr/:foo:-:bar:/;
63    };
64}
65
66done_testing;
67