SQLite parser: handle named constraints, and don't choke on a comment
[dbsrgits/SQL-Translator.git] / t / 27sqlite-parser.t
index c221312..198d8c3 100644 (file)
@@ -10,7 +10,7 @@ use SQL::Translator;
 use SQL::Translator::Schema::Constants;
 
 BEGIN {
-    maybe_plan(12,
+    maybe_plan(19,
         'SQL::Translator::Parser::SQLite');
 }
 SQL::Translator::Parser::SQLite->import('parse');
@@ -56,3 +56,31 @@ my $file = "$Bin/data/sqlite/create.sql";
     my @triggers = $schema->get_triggers;
     is( scalar @triggers, 1, 'Parsed one triggers' );
 }
+
+$file = "$Bin/data/sqlite/named.sql";
+{
+    local $/;
+    open my $fh, "<$file" or die "Can't read file '$file': $!\n";
+    my $data = <$fh>;
+    my $t = SQL::Translator->new;
+    parse($t, $data);
+
+    my $schema = $t->schema;
+
+    my @tables = $schema->get_tables;
+    is( scalar @tables, 1, 'Parsed one table' );
+
+    my $t1 = shift @tables;
+    is( $t1->name, 'pet', "'Pet' table" );
+
+    my @constraints = $t1->get_constraints;
+    is( scalar @constraints, 3, '3 constraints on pet' );
+
+    my $c1 = pop @constraints;
+    is( $c1->type, 'FOREIGN KEY', 'FK constraint' );
+    is( $c1->reference_table, 'person', 'References person table' );
+    is( $c1->name, 'fk_person_id', 'Constraint name fk_person_id' );
+    is( join(',', $c1->reference_fields), 'person_id', 
+        'References person_id field' );
+
+}