From: Darren Chamberlain Date: Thu, 21 Mar 2002 15:49:11 +0000 (+0000) Subject: Broke the 1 test out into 11 different tests, each one of which tests a specific... X-Git-Tag: v0.01~58^2~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b8661f30688cbc3d859ed640815fcb9b32498208;p=dbsrgits%2FSQL-Translator.git Broke the 1 test out into 11 different tests, each one of which tests a specific part of the data structure returned by parse. --- diff --git a/t/02mysql-parser.t b/t/02mysql-parser.t index 19a672c..d51b4b0 100644 --- a/t/02mysql-parser.t +++ b/t/02mysql-parser.t @@ -7,21 +7,65 @@ # returned here, just that the parser actually completed its parsing! # -use Symbol; -use Data::Dumper; +use strict; +use SQL::Translator; use SQL::Translator::Parser::MySQL qw(parse); -my $datafile = "t/data/mysql/Apache-Session-MySQL.sql"; -my $data; -my $fh = gensym; +$SQL::Translator::DEBUG = 0; -open $fh, $datafile or die "Can't open '$datafile' for reading: $!"; -read($fh, $data, -s $datafile); -close $fh or die "Can't close '$datafile': $!"; +my $tr = SQL::Translator->new; +my $data = q|create table sessions ( + id char(32) not null primary key, + a_session text +);|; -BEGIN { print "1..1\n"; } +BEGIN { print "1..11\n"; } -eval { parse($data); }; +my $val = parse($tr, $data); -print "not " if $@; +# $val holds the processed data structure. + +# The data structure should have one key: +print "not " if (scalar keys %{$val} != 1); print "ok 1\n"; + +# The data structure should have a single key, named sessions +print "not " unless (defined $val->{'sessions'}); +print qq(ok 2 # has a key named "sessions"\n); + +# $val->{'sessions'} should have a single index (since we haven't +# defined an index, but have defined a primary key) +my $indeces = $val->{'sessions'}->{'indeces'}; +print "not " unless (scalar @{$indeces} == 1); +print "ok 3 # correct index number\n"; + +print "not " unless ($indeces->[0]->{'type'} eq 'primary_key'); +print "ok 4 # correct index type\n"; +print "not " unless ($indeces->[0]->{'fields'}->[0] eq 'id'); +print "ok 5 # correct index name\n"; + +# $val->{'sessions'} should have two fields, id and a_sessionn +my $fields = $val->{'sessions'}->{'fields'}; +print "not " unless (scalar keys %{$fields} == 2); +print "ok 6 # correct fields number\n"; + +print "not " unless ($fields->{'id'}->{'data_type'} eq 'char'); +print "ok 7 # correct field type: id (char)\n"; + +print "not " unless ($fields->{'a_session'}->{'data_type'} eq 'text'); +print "ok 8 # correct field type: a_session (text)\n"; + +print "not " unless ($fields->{'id'}->{'is_primary_key'} == 1); +print "ok 9 # correct key identification (id == key)\n"; + +print "not " if (defined $fields->{'a_session'}->{'is_primary_key'}); +print "ok 10 # correct key identification (a_session != key)\n"; + +# Test that the order is being maintained by the internal order +# data element +my @order = sort { $fields->{$a}->{'order'} + <=> + $fields->{$b}->{'order'} + } keys %{$fields}; +print "not " unless ($order[0] eq 'id' && $order[1] eq 'a_session'); +print "ok 11 # ordering of fields\n";