From: Dagfinn Ilmari Mannsåker Date: Thu, 9 Jan 2014 18:32:07 +0000 (+0000) Subject: Use ExprDeclare in tests instead of expr.include X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ee4f475695be375f8a901ebd7f7673f8dbcfacc8;p=dbsrgits%2FData-Query.git Use ExprDeclare in tests instead of expr.include --- diff --git a/t/expr.include b/t/expr.include deleted file mode 100644 index 7215502..0000000 --- a/t/expr.include +++ /dev/null @@ -1,57 +0,0 @@ -use strictures 1; -use Data::Query::ExprBuilder::Identifier; -use Data::Query::ExprHelpers; -use Data::Query::Constants; - -sub expr (&) { - _run_expr($_[0])->{expr}; -} - -sub _run_expr { - local $_ = Data::Query::ExprBuilder::Identifier->new({ - expr => Identifier(), - }); - $_[0]->(); -} - -sub AS { - my $as = shift; - (bless(\$as, 'LIES::AS'), @_); -} - -sub SELECT (&;@) { - my @select = map +( - ref() - ? $_ - : { expr => perl_scalar_value($_) } - ), _run_expr(shift); - my @final; - while (@select) { - my $e = shift @select; - push @final, - (ref($select[0]) eq 'LIES::AS' - ? Alias(${shift(@select)}, $e->{expr}) - : $e->{expr} - ); - } - - return +{ - expr => Select(\@final, ($_[0]||{})->{expr}) - }; -} - -sub BY (&;@) { @_ } - -sub FROM (&;@) { - my @from = _run_expr(shift); - if (@from == 2 and ref($from[1]) eq 'LIES::AS') { - return +{ - expr => Alias(${$from[1]}, $from[0]) - }; - } elsif (@from == 1) { - return { expr => $from[0] }; - } - die "Huh?" -} - -1; diff --git a/t/expr.t b/t/expr.t index 3621e11..f53f61f 100644 --- a/t/expr.t +++ b/t/expr.t @@ -2,11 +2,12 @@ use strictures 1; use Test::More qw(no_plan); use Test::Exception; -BEGIN { require 't/expr.include' } +use Data::Query::ExprDeclare; +use Data::Query::Constants; sub expr_is (&;@) { my $sub = shift; - is_deeply(_run_expr($sub)->{expr}, @_); + is_deeply(Data::Query::ExprDeclare::_run_expr($sub)->{expr}, @_); } expr_is { $_->foo } diff --git a/t/perl.t b/t/perl.t index d8a4f38..e29b0ae 100644 --- a/t/perl.t +++ b/t/perl.t @@ -4,8 +4,8 @@ use Test::More qw(no_plan); use Devel::Dwarn; use Data::Query::Renderer::Perl; use Data::Query::ExprHelpers qw(perl_scalar_value); - -BEGIN { require 't/expr.include' } +use Data::Query::ExprDeclare; +use Scalar::Util qw(blessed); my $rend = Data::Query::Renderer::Perl->new; @@ -13,9 +13,11 @@ sub binding { map perl_scalar_value($_), @_ } sub expr_perl_is (&;@) { my $sub = shift; - @_ - ? is_deeply($rend->render(_run_expr($sub)->{expr}), @_) - : ::Dwarn($rend->render(_run_expr($sub)->{expr})); + my $e = Data::Query::ExprDeclare::_run_expr($sub); + $e = blessed($e) ? $e->{expr} : $e; + @_ + ? is_deeply($rend->render($e), @_) + : ::Dwarn($rend->render($e)); } expr_perl_is { $_->foo } diff --git a/t/sql.t b/t/sql.t index a8cc66d..6bf46e8 100644 --- a/t/sql.t +++ b/t/sql.t @@ -1,11 +1,11 @@ use strictures 1; use Test::More qw(no_plan); +use Scalar::Util qw(blessed); use Devel::Dwarn; use Data::Query::Renderer::SQL::Naive; use Data::Query::ExprHelpers qw(perl_scalar_value); - -BEGIN { require 't/expr.include' } +use Data::Query::ExprDeclare qw(SELECT AS expr); my $rend = Data::Query::Renderer::SQL::Naive->new({ quote_chars => [ "'" ] }); @@ -13,9 +13,11 @@ sub binding { map perl_scalar_value($_), @_ } sub expr_sql_is (&;@) { my $sub = shift; + my $e = Data::Query::ExprDeclare::_run_expr($sub); + $e = blessed($e) ? $e->{expr} : $e; @_ - ? is_deeply($rend->render(_run_expr($sub)->{expr}), @_) - : ::Dwarn($rend->render(_run_expr($sub)->{expr})); + ? is_deeply($rend->render($e), @_) + : ::Dwarn($rend->render($e)); } expr_sql_is { $_->foo }