[Bast-commits] r5985 - in SQL-Abstract/1.x/trunk: lib/SQL t

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Fri Apr 24 21:17:32 GMT 2009


Author: ribasushi
Date: 2009-04-24 22:17:32 +0100 (Fri, 24 Apr 2009)
New Revision: 5985

Modified:
   SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm
   SQL-Abstract/1.x/trunk/t/06order_by.t
Log:
Wrap up order_by saga

Modified: SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm
===================================================================
--- SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm	2009-04-24 19:53:07 UTC (rev 5984)
+++ SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm	2009-04-24 21:17:32 UTC (rev 5985)
@@ -2086,33 +2086,29 @@
 column name,) a hash of C<< { -desc => 'col' } >> or C<< { -asc => 'col' } >>,
 or an array of either of the two previous forms. Examples:
 
-               Given           |         Will Generate
-    ---------------------------------------------------------
-                               |
-    \'colA DESC'               | ORDER BY colA DESC
-                               |
-    'colA'                     | ORDER BY colA
-                               |
-    [qw/colA colB/]            | ORDER BY colA, colB
-                               |
-    {-asc  => 'colA'}          | ORDER BY colA ASC
-                               |
-    {-desc => 'colB'}          | ORDER BY colB DESC
-                               |
-    [                          | ORDER BY colA ASC, colB DESC
-      {-asc  => 'colA'},       |
-      {-desc => 'colB'}        |
-    ]                          |
-                               |
-    ['colA', {-asc => 'colB'}] | ORDER BY colA, colB ASC
-                               |
-    { -asc => [qw/colA colB] } | ORDER BY colA ASC, colB ASC
-                               |
-    {                          |
-      -asc => [qw/colA colB/], | ORDER BY colA ASC, colB ASC,
-      -desc => [qw/colC colD/],|          colC DESC, colD DESC
-    }                          |
-    ==========================================================
+               Given            |         Will Generate
+    ----------------------------------------------------------
+                                |
+    \'colA DESC'                | ORDER BY colA DESC
+                                |
+    'colA'                      | ORDER BY colA
+                                |
+    [qw/colA colB/]             | ORDER BY colA, colB
+                                |
+    {-asc  => 'colA'}           | ORDER BY colA ASC
+                                |
+    {-desc => 'colB'}           | ORDER BY colB DESC
+                                |
+    ['colA', {-asc => 'colB'}]  | ORDER BY colA, colB ASC
+                                |
+    { -asc => [qw/colA colB] }  | ORDER BY colA ASC, colB ASC
+                                |
+    [                           |
+      { -asc => 'colA' },       | ORDER BY colA ASC, colB DESC,
+      { -desc => [qw/colB/],    |          colC ASC, colD ASC
+      { -asc => [qw/colC colD/],|
+    ]                           |
+    ===========================================================
 
 
 

Modified: SQL-Abstract/1.x/trunk/t/06order_by.t
===================================================================
--- SQL-Abstract/1.x/trunk/t/06order_by.t	2009-04-24 19:53:07 UTC (rev 5984)
+++ SQL-Abstract/1.x/trunk/t/06order_by.t	2009-04-24 21:17:32 UTC (rev 5985)
@@ -3,6 +3,7 @@
 use strict;
 use warnings;
 use Test::More;
+use Test::Exception;
 
 use SQL::Abstract;
 
@@ -81,15 +82,14 @@
     expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` DESC',
    },
    {
-    given => [{-desc => [ qw/colA colB/ ], -asc => [ qw/colC colD/ ] }],
-    expects => ' ORDER BY colA DESC, colB DESC, colC ASC, colD ASC',
-    expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` ASC, `colD` ASC',
+    given => [{ -asc => 'colA' }, { -desc => [qw/colB/] }, { -asc => [qw/colC colD/] }],
+    expects => ' ORDER BY colA ASC, colB DESC, colC ASC, colD ASC',
+    expects_quoted => ' ORDER BY `colA` ASC, `colB` DESC, `colC` ASC, `colD` ASC',
    },
-
   );
 
 
-plan tests => (scalar(@cases) * 2);
+plan tests => (scalar(@cases) * 2) + 2;
 
 my $sql  = SQL::Abstract->new;
 my $sqlq = SQL::Abstract->new({quote_char => '`'});
@@ -98,3 +98,15 @@
   is($sql->_order_by($case->{given}), $case->{expects});
   is($sqlq->_order_by($case->{given}), $case->{expects_quoted});
 }
+
+throws_ok (
+  sub { $sql->_order_by({-desc => 'colA', -asc => 'colB' }) },
+  qr/hash passed .+ must have exactly one key/,
+  'Undeterministic order exception',
+);
+
+throws_ok (
+  sub { $sql->_order_by({-desc => [ qw/colA colB/ ], -asc => [ qw/colC colD/ ] }) },
+  qr/hash passed .+ must have exactly one key/,
+  'Undeterministic order exception',
+);




More information about the Bast-commits mailing list