Just the fairy.
[dbsrgits/SQL-Translator.git] / t / 19sybase-parser.t
CommitLineData
88d2bfd8 1#!/usr/bin/perl
2# vim: set ft=perl ts=4 et:
3#
4
5use strict;
6
7use FindBin qw/$Bin/;
52043773 8use Test::More tests => 41;
88d2bfd8 9use SQL::Translator;
d730d512 10use SQL::Translator::Schema::Constants;
88d2bfd8 11use SQL::Translator::Parser::Sybase qw(parse);
12
13my $file = "$Bin/data/sybase/create.sql";
14
15ok( -e $file, "File exists" );
16
d730d512 17my $data;
18{
19 local $/;
20 open my $fh, "<$file" or die "Can't read file '$file': $!\n";
21 $data = <$fh>;
22 close $fh;
23}
24
25ok( $data, 'Data' );
26
88d2bfd8 27my $t = SQL::Translator->new;
28
d730d512 29my $val = parse($t, $data);
30
31is( $val, 1, 'Parse' );
88d2bfd8 32
33my $schema = $t->schema;
d730d512 34
35isa_ok( $schema, 'SQL::Translator::Schema', 'Schema' );
36
88d2bfd8 37is( $schema->is_valid, 1, 'Schema is valid' );
d730d512 38
88d2bfd8 39my @tables = $schema->get_tables;
d730d512 40
41is( scalar @tables, 9, 'Nine tables' );
42
43{
44 my $t = $schema->get_table( 'jdbc_function_escapes' );
45 isa_ok( $t, 'SQL::Translator::Schema::Table', 'Table' );
46 is( $t->name, 'jdbc_function_escapes', "Name = 'jdbc_function_escapes'" );
47
48 my @fields = $t->get_fields;
49 is( scalar @fields, 2, 'Two fields' );
50
51 is( $fields[0]->name, 'escape_name', "First field name is 'escape_name'" );
52 is( $fields[0]->data_type, 'varchar', "First field is 'varchar'" );
53 is( $fields[0]->size, 40, "First field size is '40'" );
54 is( $fields[0]->is_nullable, 0, "First field cannot be null" );
55
56 is( $fields[1]->name, 'map_string', "Second field name is 'map_string'" );
57 is( $fields[1]->data_type, 'varchar', "Second field is 'varchar'" );
58 is( $fields[1]->size, 40, "Second field size is '40'" );
59 is( $fields[1]->is_nullable, 0, "Second field cannot be null" );
60}
61
62{
63 my $t = $schema->get_table( 'spt_jtext' );
64 isa_ok( $t, 'SQL::Translator::Schema::Table', 'Table' );
65 is( $t->name, 'spt_jtext', "Name = 'spt_jtext'" );
66
67 my @fields = $t->get_fields;
68 is( scalar @fields, 2, 'Two fields' );
69
70 is( $fields[0]->name, 'mdinfo', "First field name is 'mdinfo'" );
71 is( $fields[0]->data_type, 'varchar', "First field is 'varchar'" );
72 is( $fields[0]->size, 30, "First field size is '30'" );
73 is( $fields[0]->is_nullable, 0, "First field cannot be null" );
74
75 is( $fields[1]->name, 'value', "Second field name is 'value'" );
76 is( $fields[1]->data_type, 'text', "Second field is 'text'" );
77 is( $fields[1]->size, 0, "Second field size is '0'" );
78 is( $fields[1]->is_nullable, 0, "Second field cannot be null" );
79
80 my @constraints = $t->get_constraints;
81 is( scalar @constraints, 1, 'One constraint' );
82
83 is( $constraints[0]->type, UNIQUE, 'Constraint is UNIQUE' );
84 is( join(',', $constraints[0]->fields), 'mdinfo', 'On "mdinfo"' );
85}
86
87{
88 my $t = $schema->get_table( 'spt_mda' );
89 isa_ok( $t, 'SQL::Translator::Schema::Table', 'Table' );
90 is( $t->name, 'spt_mda', "Name = 'spt_mda'" );
91
92 my @fields = $t->get_fields;
93 is( scalar @fields, 7, 'Seven fields' );
94
95 is( $fields[0]->name, 'mdinfo', "First field name is 'mdinfo'" );
96 is( $fields[0]->data_type, 'varchar', "First field is 'varchar'" );
97 is( $fields[0]->size, 30, "First field size is '30'" );
98 is( $fields[0]->is_nullable, 0, "First field cannot be null" );
99
100 my @constraints = $t->get_constraints;
101 is( scalar @constraints, 1, 'One constraint' );
102
103 is( $constraints[0]->type, UNIQUE, 'Constraint is UNIQUE' );
104 is( join(',', $constraints[0]->fields),
105 'mdinfo,mdaver_end,srvver_end', 'On "mdinfo,mdaver_end,srvver_end"' );
106}