From: Matt S Trout Date: Sat, 5 Jun 2010 18:12:39 +0000 (+0100) Subject: fill out operator list and test not-currently-supported operators X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9e0200bc0560c1931484361aad28e2ddc2f83a57;p=dbsrgits%2FData-Query.git fill out operator list and test not-currently-supported operators --- diff --git a/lib/Data/Query/ExprBuilder.pm b/lib/Data/Query/ExprBuilder.pm index b1df317..0a2f75e 100644 --- a/lib/Data/Query/ExprBuilder.pm +++ b/lib/Data/Query/ExprBuilder.pm @@ -27,7 +27,12 @@ use overload ( }, }); } - } qw(==)) + } qw(+ - * / % ** << >> . < > == != lt le gt ge eq ne)), + (map { + my $op = $_; + $op => sub { die "Can't use operator $op on a ".ref($_[0]) } + } qw(<=> cmp x) + ), ); sub new { diff --git a/t/expr.t b/t/expr.t index cfbbb4e..cc33fe6 100644 --- a/t/expr.t +++ b/t/expr.t @@ -2,6 +2,7 @@ use strictures 1; use Test::More qw(no_plan); use Data::Query::ExprBuilder::Identifier; use Data::Query::Constants qw(DQ_IDENTIFIER DQ_OPERATOR DQ_VALUE); +use Test::Exception; sub expr (&) { _mk_expr($_[0]); @@ -81,3 +82,7 @@ expr_is { 3 == $_->foo } ], }, 'Operand reversed equality ok'; + +throws_ok { + expr { $_->foo <=> 3 } +} qr/\QCan't use operator <=>/, 'Exception on bad operator';