From: Mark Addison Date: Sun, 29 Feb 2004 20:11:19 +0000 (+0000) Subject: Now uses schema_ok X-Git-Tag: v0.06~165 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9c36b41b5f9647d2464ac0027954eaf4373d7ab6;p=dbsrgits%2FSQL-Translator.git Now uses schema_ok --- diff --git a/t/16xml-parser.t b/t/16xml-parser.t index a863ba4..0661c98 100644 --- a/t/16xml-parser.t +++ b/t/16xml-parser.t @@ -26,7 +26,7 @@ use constant DEBUG => (exists $opt{d} ? 1 : 0); # Testing 1,2,3,4... #============================================================================= -plan tests => 274; +plan tests => 284; foreach ( "$Bin/data/xml/schema-basic.xml", @@ -55,117 +55,112 @@ sub do_file { # Test the schema objs generted from the XML # my $scma = $obj->schema; - my @tblnames = map {$_->name} $scma->get_tables; - is_deeply( \@tblnames, [qw/Basic/], "tables"); - - # Basic - my $tbl = $scma->get_table("Basic"); - is_deeply( [map {$_->name} $tbl->get_fields], [qw/ - id title description email explicitnulldef explicitemptystring emptytagdef - /] , "Table Basic's fields"); - - table_ok( $scma->get_table("Basic"), { - name => "Basic", - fields => [ - { - name => "id", - data_type => "int", - default_value => undef, - is_nullable => 0, - size => 10, - is_primary_key => 1, - is_auto_increment => 1, - }, - { - name => "title", - data_type => "varchar", - is_nullable => 0, - default_value => "hello", - size => 100, - }, - { - name => "description", - data_type => "text", - is_nullable => 1, - default_value => "", - }, - { - name => "email", - data_type => "varchar", - size => 255, - is_unique => 1, - default_value => undef, - is_nullable => 1, - }, - { - name => "explicitnulldef", - data_type => "varchar", - default_value => undef, - is_nullable => 1, - }, - { - name => "explicitemptystring", - data_type => "varchar", - default_value => "", - is_nullable => 1, - }, - { - name => "emptytagdef", - data_type => "varchar", - default_value => "", - is_nullable => 1, - }, - ], - constraints => [ - { - type => PRIMARY_KEY, - fields => ["id"], - }, - { - name => 'emailuniqueindex', - type => UNIQUE, - fields => ["email"], - } + + # Hmmm, when using schema_ok the field test data gets a bit too nested and + # fiddly to work with. (See 28xml-xmi-parser-sqlfairy.t for more split out + # version) + schema_ok( $scma, { + tables => [ + { + name => "Basic", + fields => [ + { + name => "id", + data_type => "int", + default_value => undef, + is_nullable => 0, + size => 10, + is_primary_key => 1, + is_auto_increment => 1, + }, + { + name => "title", + data_type => "varchar", + is_nullable => 0, + default_value => "hello", + size => 100, + }, + { + name => "description", + data_type => "text", + is_nullable => 1, + default_value => "", + }, + { + name => "email", + data_type => "varchar", + size => 255, + is_unique => 1, + default_value => undef, + is_nullable => 1, + }, + { + name => "explicitnulldef", + data_type => "varchar", + default_value => undef, + is_nullable => 1, + }, + { + name => "explicitemptystring", + data_type => "varchar", + default_value => "", + is_nullable => 1, + }, + { + name => "emptytagdef", + data_type => "varchar", + default_value => "", + is_nullable => 1, + }, + ], + constraints => [ + { + type => PRIMARY_KEY, + fields => ["id"], + }, + { + name => 'emailuniqueindex', + type => UNIQUE, + fields => ["email"], + } + ], + indices => [ + { + name => "titleindex", + fields => ["title"], + }, + ], + } # end table Basic + ], # end tables + + views => [ + { + name => 'email_list', + sql => "SELECT email FROM Basic WHERE email IS NOT NULL", + fields => ['email'], + }, ], - indices => [ - { - name => "titleindex", - fields => ["title"], - }, + + triggers => [ + { + name => 'foo_trigger', + perform_action_when => 'after', + database_event => 'insert', + on_table => 'foo', + action => 'update modified=timestamp();', + }, ], - }); - # - # View - # - my @views = $scma->get_views; - view_ok( $views[0], { - name => 'email_list', - sql => "SELECT email FROM Basic WHERE email IS NOT NULL", - fields => ['email'], - }); - - my @triggs = $scma->get_triggers; - trigger_ok( $triggs[0], { - name => 'foo_trigger', - perform_action_when => 'after', - database_event => 'insert', - on_table => 'foo', - action => 'update modified=timestamp();', - }); + procedures => [ + { + name => 'foo_proc', + sql => 'select foo from bar', + parameters => ['foo', 'bar'], + owner => 'Nomar', + comments => 'Go Sox!', + }, + ], + }); # end schema - # - # Procedure - # - my @procs = $scma->get_procedures; - procedure_ok( $procs[0], { - name => 'foo_proc', - sql => 'select foo from bar', - parameters => ['foo', 'bar'], - owner => 'Nomar', - comments => 'Go Sox!', - }); - - print "Debug:", Dumper($obj) if DEBUG; -} # /Test of schema +} # end do_file()