From: Ken Youens-Clark Date: Thu, 1 May 2003 04:23:11 +0000 (+0000) Subject: Adding new schema test, commiting fixes to MySQL parser test. X-Git-Tag: v0.02~162 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4d878d2f07e3628c7ccf525966da7a85962cda94;p=dbsrgits%2FSQL-Translator.git Adding new schema test, commiting fixes to MySQL parser test. --- diff --git a/t/02mysql-parser.t b/t/02mysql-parser.t index ddfd4de..cee9620 100644 --- a/t/02mysql-parser.t +++ b/t/02mysql-parser.t @@ -32,7 +32,7 @@ ok(defined $val->{'sessions'}); # $val->{'sessions'} should have a single index (since we haven't # defined an index, but have defined a primary key) my $indices = $val->{'sessions'}->{'indices'}; -is(scalar @{$indices}, 1, "correct index number"); +is(scalar @{$indices || []}, 1, "correct index number"); is($indices->[0]->{'type'}, 'primary_key', "correct index type"); is($indices->[0]->{'fields'}->[0], 'id', "correct index name"); diff --git a/t/13schema.t b/t/13schema.t new file mode 100644 index 0000000..21839ab --- /dev/null +++ b/t/13schema.t @@ -0,0 +1,83 @@ +#!/usr/bin/perl + +use strict; +use Test::More 'no_plan'; # plans => 1; + +require_ok( 'SQL::Translator::Schema' ); + +# +# Schema +# +my $schema = SQL::Translator::Schema->new; + +isa_ok( $schema, 'SQL::Translator::Schema' ); + +# +# Table default new +# +my $foo_table = $schema->add_table; +isa_ok( $foo_table, 'SQL::Translator::Schema::Table', 'Schema' ); +is( $foo_table->name, '', 'Table name is empty' ); +is( $foo_table->is_valid, 0, 'Table is not yet valid' ); +my %fields = $foo_table->fields; +cmp_ok( scalar keys %fields, '==', 0, 'No fields' ); + +# +# Table methods +# +is( $foo_table->name('foo'), 'foo', 'Table name is "foo"' ); + +# +# New table with args +# +my $person_table = $schema->add_table( name => 'person' ); +is( $person_table->name, 'person', 'Table name is "person"' ); +is( $person_table->is_valid, 0, 'Table is still not valid' ); + +# +# Field default new +# +my $name = $person_table->add_field or warn $person_table->error; +isa_ok( $name, 'SQL::Translator::Schema::Field', 'Field' ); +is( $name->name, '', 'Field name is blank' ); +is( $name->data_type, '', 'Field data type is blank' ); +is( $name->size, 0, 'Field size is "0"' ); +is( $name->is_primary_key, '0', 'Field is_primary_key is negative' ); + +# +# Field methods +# +is( $name->name('person_name'), 'person_name', 'Field name is "person_name"' ); +is( $name->data_type('varchar'), 'varchar', 'Field data type is "varchar"' ); +is( $name->size(30), '30', 'Field size is "30"' ); +is( $name->is_primary_key(0), '0', 'Field is_primary_key is negative' ); + +# +# New field with args +# +my $age = $person_table->add_field( + name => 'age', + data_type => 'integer', + size => 3, +); +is( $age->name, 'age', 'Field name is "age"' ); +is( $age->data_type, 'integer', 'Field data type is "integer"' ); +is( $age->size, '3', 'Field size is "3"' ); + +# +# Index +# +my $index = $person_table->add_index or warn $person_table->error; +isa_ok( $index, 'SQL::Translator::Schema::Index', 'Index' ); + +# +# Constraint +# +my $constraint = $person_table->add_constraint or warn $person_table->error; +isa_ok( $constraint, 'SQL::Translator::Schema::Constraint', 'Constraint' ); + +# +# View +# +my $view = $schema->add_view or warn $schema->error; +isa_ok( $view, 'SQL::Translator::Schema::View', 'View' );