fix typo
[dbsrgits/SQL-Translator-2.0-ish.git] / t / 27sqlite-parser.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use FindBin qw/$Bin/;
5 use SQL::Translator;
6 use SQL::Translator::Constants qw(:sqlt_types :sqlt_constants);
7
8 my $file = "$Bin/data/sqlite/create.sql";
9
10 {
11     local $/;
12     open my $fh, "<$file" or die "Can't read file '$file': $!\n";
13     my $data = <$fh>;
14     my $t = SQL::Translator->new({ from => 'SQLite' });
15     $t->parse($data);
16
17     my $schema = $t->schema;
18
19     my @tables = $schema->get_tables;
20     is( scalar @tables, 2, 'Parsed two tables' );
21
22     my $t1 = shift @tables;
23     is( $t1->name, 'person', "'Person' table" );
24
25     my @fields = $t1->get_fields;
26     is( scalar @fields, 6, 'Six fields in "person" table');
27     my $fld1 = shift @fields;
28     is( $fld1->name, 'person_id', 'First field is "person_id"');
29     is( $fld1->is_auto_increment, 1, 'Is an autoincrement field');
30
31     my $t2 = shift @tables;
32     is( $t2->name, 'pet', "'Pet' table" );
33
34     my @constraints = $t2->get_constraints;
35     is( scalar @constraints, 3, '3 constraints on pet' );
36
37     my $c1 = pop @constraints;
38     is( $c1->type, 'FOREIGN KEY', 'FK constraint' );
39     is( $c1->reference_table, 'person', 'References person table' );
40     is( join(',', $c1->reference_fields), 'person_id', 
41         'References person_id field' );
42
43     my @views = $schema->get_views;
44     is( scalar @views, 1, 'Parsed one views' );
45
46     my @triggers = $schema->get_triggers;
47     is( scalar @triggers, 1, 'Parsed one triggers' );
48
49     done_testing;
50 }