Attached patch now includes tests.

Andrew
--- SQL-Translator-0.11005/lib/SQL/Translator/Producer/HTML.pm	2009-08-19 05:24:39.000000000 +1000
+++ /home/andrewp/workspace/libsql-translator-perl/lib/SQL/Translator/Producer/HTML.pm	2010-05-07 12:44:54.591450359 +1000
@@ -72,7 +72,8 @@
             $q->hr;
     }
 
-    @table_names = grep { length $_->name } $schema->get_tables; 
+    @table_names = grep { length $_->name } $schema->get_tables;
+    @table_names = sort @table_names if defined $args->{'sort'}; 
 
     if ($linktable) {
         # Generate top menu, with links to full table information
@@ -108,8 +109,8 @@
         push @html, $q->end_table;
     }
 
-    for my $table ($schema->get_tables) {
-        my $table_name = $table->name       or next;
+    for my $table_name (@table_names) {
+        my $table      = $schema->get_table($table_name);
         my @fields     = $table->get_fields or next;
         push @html,
             $q->comment("Starting table '$table_name'"),
--- SQL-Translator-0.11005/t/29html.t	2009-04-28 01:36:00.000000000 +1000
+++ /home/andrewp/workspace/libsql-translator-perl/t/29html.t	2010-05-31 12:45:46.000000000 +1000
@@ -13,7 +13,7 @@
 use SQL::Translator;
 
 BEGIN {
-    maybe_plan(5,
+    maybe_plan(7,
         'HTML::Parser',
         'SQL::Translator::Parser::MySQL',
         'SQL::Translator::Producer::HTML');
@@ -38,7 +38,7 @@
     $status = $p->parse($parsed);    
 };
 if ($@) {
-    daig $@;
+    diag $@;
     fail("Unable to parse the output!");
 }
 
@@ -64,6 +64,22 @@
 is($classes, 1, "SQLfairy plug is alive and well ");
 $tables = $classes = 0;
 
+$create .= <<'SQL';
+CREATE TABLE bar (
+    int id PRIMARY KEY AUTO_INCREMENT NOT NULL,
+    name VARCHAR(255)
+);
+SQL
+$tr = SQL::Translator->new(parser => 'MySQL', producer => 'HTML');
+$parsed = $tr->translate(data => $create) or die $tr->error;
+my @tables = $parsed =~ m{ <h3> ( [^<]+ ) </h3> }gx;
+is_deeply(\...@tables, [ 'foo', 'bar' ], 'tables in order of creation' );
+
+$tr->producer_args( sort => 1 );
+$parsed = $tr->translate(data => $create) or die $tr->error;
+...@tables = $parsed =~ m{ <h3> ( [^<]+ ) </h3> }gx;
+is_deeply(\...@tables, [ 'bar', 'foo' ], 'tables in sorted order' );
+
 # Handler functions for the parser
 BEGIN {
     %HANDLERS = (
------------------------------------------------------------------------------

-- 
sqlfairy-developers mailing list
sqlfairy-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlfairy-developers

Reply via email to