Fixes per RT#37814 (parsing of field/index names with double quotes, also fix
[dbsrgits/SQL-Translator.git] / t / 27sqlite-parser.t
CommitLineData
5fcc85af 1#!/usr/bin/perl
2# vim: set ft=perl:
3
4use strict;
2d691ec1 5use Test::More;
6use Test::SQL::Translator qw(maybe_plan);
153b2e77 7use FindBin qw/$Bin/;
8
5fcc85af 9use SQL::Translator;
5fcc85af 10use SQL::Translator::Schema::Constants;
11
2d691ec1 12BEGIN {
7d8f0a61 13 maybe_plan(9,
2d691ec1 14 'SQL::Translator::Parser::SQLite');
15}
16SQL::Translator::Parser::SQLite->import('parse');
17
153b2e77 18my $file = "$Bin/data/sqlite/create.sql";
19
5fcc85af 20{
153b2e77 21 local $/;
22 open my $fh, "<$file" or die "Can't read file '$file': $!\n";
23 my $data = <$fh>;
5fcc85af 24 my $t = SQL::Translator->new;
153b2e77 25 parse($t, $data);
26
27 my $schema = $t->schema;
28
29 my @tables = $schema->get_tables;
30 is( scalar @tables, 2, 'Parsed two tables' );
31
32 my $t1 = shift @tables;
33 is( $t1->name, 'person', "'Person' table" );
34
35 my $t2 = shift @tables;
36 is( $t2->name, 'pet', "'Pet' table" );
37
7d8f0a61 38 my @constraints = $t2->get_constraints;
39 is( scalar @constraints, 3, '3 constraints on pet' );
40
41 my $c1 = pop @constraints;
42 is( $c1->type, 'FOREIGN KEY', 'FK constraint' );
43 is( $c1->reference_table, 'person', 'References person table' );
44 is( join(',', $c1->reference_fields), 'person_id',
45 'References person_id field' );
46
153b2e77 47 my @views = $schema->get_views;
48 is( scalar @views, 1, 'Parsed one views' );
49
50 my @triggers = $schema->get_triggers;
51 is( scalar @triggers, 1, 'Parsed one triggers' );
5fcc85af 52}