1use strict; 2use warnings; 3use Test::More; 4use SQL::Maker::Condition; 5 6my $w1 = SQL::Maker::Condition->new(); 7$w1->add(x => 1); 8$w1->add(y => 2); 9 10my $w2 = SQL::Maker::Condition->new(); 11$w2->add(a => 3); 12$w2->add(b => 4); 13 14subtest 'and' => sub { 15 my $and = ($w1 & $w2); 16 is $and->as_sql, '((x = ?) AND (y = ?)) AND ((a = ?) AND (b = ?))'; 17 is join(', ', $and->bind), '1, 2, 3, 4'; 18 19 $and->add(z => 99); 20 is $and->as_sql, '((x = ?) AND (y = ?)) AND ((a = ?) AND (b = ?)) AND (z = ?)'; 21 is join(', ', $and->bind), '1, 2, 3, 4, 99'; 22}; 23 24subtest 'or' => sub { 25 my $or = ($w1 | $w2); 26 is $or->as_sql, '(((x = ?) AND (y = ?)) OR ((a = ?) AND (b = ?)))'; 27 is join(', ', $or->bind), '1, 2, 3, 4'; 28 29 $or->add(z => 99); 30 is $or->as_sql, '(((x = ?) AND (y = ?)) OR ((a = ?) AND (b = ?))) AND (z = ?)'; 31 is join(', ', $or->bind), '1, 2, 3, 4, 99'; 32}; 33 34done_testing; 35 36