Robustify the tests a little.
[dbsrgits/SQL-Translator.git] / t / 15oracle-parser.t
index 1a87477..6377ad2 100644 (file)
@@ -1,10 +1,21 @@
 #!/usr/bin/perl
+# vim: set ft=perl:
 
 use strict;
-use Test::More tests => 72;
+use Test::More;
 use SQL::Translator;
 use SQL::Translator::Schema::Constants;
-use SQL::Translator::Parser::Oracle qw(parse);
+
+eval {
+    require SQL::Translator::Parser::Oracle;
+    SQL::Translator::Parser::Oracle->import('parse');
+};
+if ($@) {
+    plan skip_all => "$@";
+}
+else {
+    plan tests => 76;
+}
 
 my $t   = SQL::Translator->new( trace => 0 );
 my $sql = q[
@@ -19,6 +30,7 @@ my $sql = q[
     comment on column qtl_trait_category.qtl_trait_category_id 
         is 'the primary key!';
 
+    -- foo bar comment
     CREATE TABLE qtl_trait
     (
         qtl_trait_id            NUMBER(11)      NOT NULL    
@@ -31,11 +43,13 @@ my $sql = q[
         FOREIGN KEY ( qtl_trait_category_id ) REFERENCES qtl_trait_category
     );
 
+    /* qtl table comment */
     CREATE TABLE qtl
     (
+        /* qtl_id comment */
         qtl_id              NUMBER(11)      NOT NULL    
             CONSTRAINT pk_qtl PRIMARY KEY,
-        qtl_accession_id    VARCHAR2(20)    NOT NULL,
+        qtl_accession_id    VARCHAR2(20)    NOT NULL /* accession comment */,
         published_symbol    VARCHAR2(100),
         qtl_trait_id        NUMBER(11)      NOT NULL,
         linkage_group       VARCHAR2(32)    NOT NULL,
@@ -84,7 +98,7 @@ is( $f1->size, 11, 'Size is "11"' );
 is( $f1->is_nullable, 0, 'Field cannot be null' );
 is( $f1->default_value, undef, 'Default value is undefined' );
 is( $f1->is_primary_key, 1, 'Field is PK' );
-is( $f1->comments, 'the primary key!', 'Comment = "the primary key!"' );
+is( join(',', $f1->comments), 'the primary key!', 'Comment = "the primary key!"' );
 
 my $f2 = shift @t1_fields;
 is( $f2->name, 'trait_category', 'Second field is "trait_category"' );
@@ -117,6 +131,7 @@ is( join(',', $c2->fields), 'trait_category',
 #
 my $t2 = shift @tables;
 is( $t2->name, 'qtl_trait', 'Table "qtl_trait" exists' );
+is( $t2->comments, 'foo bar comment', 'Comment "foo bar" exists' );
 
 my @t2_fields = $t2->get_fields;
 is( scalar @t2_fields, 4, '4 fields in table' );
@@ -198,6 +213,15 @@ is( scalar @t3_fields, 8, '8 fields in table' );
 my @t3_constraints = $t3->get_constraints;
 is( scalar @t3_constraints, 3, '3 constraints on table' );
 
+is( $t3->comments, 'qtl table comment', 'Comment "qtl table comment" exists' );
+
+my $t3_f1     = shift @t3_fields;
+is( $t3_f1->comments, 'qtl_id comment', 'Comment "qtl_id comment" exists' );
+
+my $t3_f2     = shift @t3_fields;
+is( $t3_f2->comments, 'accession comment', 
+    'Comment "accession comment" exists' );
+
 #
 # qtl_trait_synonym
 #