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