From: Ken Youens-Clark Date: Wed, 11 Jun 2003 03:58:09 +0000 (+0000) Subject: These tests relied on now deprecated action that the raw data structure X-Git-Tag: v0.02~35 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=307d95603a49f1ff8056963822538c726cde481f;p=dbsrgits%2FSQL-Translator.git These tests relied on now deprecated action that the raw data structure was returned by the parser. The tests were updated to use the schema object. --- diff --git a/t/04file,fh,string.t b/t/04file,fh,string.t index e4b28e4..9f1100b 100644 --- a/t/04file,fh,string.t +++ b/t/04file,fh,string.t @@ -12,24 +12,32 @@ use strict; use IO::File; +use Storable 'freeze'; use SQL::Translator; use Test::More tests => 3; -# Our object; uses the default parser and producer -my $tr = SQL::Translator->new; # The filename, holder for all the data, and the filehandle my $datafile = "t/data/mysql/Apache-Session-MySQL.sql"; my $data; my $fh = IO::File->new($datafile); -# Pass filename: simplest way -my $translated_datafile = $tr->translate($datafile); +my ($v1, $v2); +{ + my $tr = SQL::Translator->new; + # Pass filename: simplest way + $tr->translate($datafile); + $v1 = freeze( $tr->schema ); +} -# Pass string reference -read($fh, $data, -s $datafile); -my $translated_data = $tr->translate(\$data); +{ + my $tr = SQL::Translator->new; + # Pass string reference + read($fh, $data, -s $datafile); + $tr->translate(\$data); + $v2 = freeze( $tr->schema ); +} -ok(length $translated_datafile, "passing string (filename) works"); -ok(length $translated_data, "passing string as SCALAR reference"); -is($translated_datafile, $translated_data, "from file == from string"); +ok(length $v1, "passing string (filename) works"); +ok(length $v2, "passing string as SCALAR reference"); +is($v1, $v2, "from file == from string"); diff --git a/t/07p_args.t b/t/07p_args.t index 76b922e..988987b 100644 --- a/t/07p_args.t +++ b/t/07p_args.t @@ -6,7 +6,7 @@ use strict; use SQL::Translator; -use Test::More tests => 6; +use Test::More tests => 9; sub silly_parser { my ($tr, $data) = @_; @@ -14,7 +14,13 @@ sub silly_parser { my @fields = split /$pargs->{'delimiter'}/, $data; - return \@fields; + my $schema = $tr->schema; + my $table = $schema->add_table( name => 'foo') or die $schema->error; + for my $value ( @fields ) { + my $field = $table->add_field( name => $value ) or die $table->error; + } + + return 1; } # The "data" to be parsed @@ -26,37 +32,50 @@ my $tr = SQL::Translator->new; $tr->parser(\&silly_parser); $tr->parser_args(delimiter => '\|'); -my $pargs = $tr->parser_args; -my $parsed = $tr->translate(\$data); +my $pargs = $tr->parser_args; +$tr->translate(\$data); +my $schema = $tr->schema; -is($pargs->{'delimiter'}, '\|', - "parser_args works when called directly"); -is(scalar @{$parsed}, 4, - "right number of fields"); +is($pargs->{'delimiter'}, '\|', "parser_args works when called directly"); +my @tables = $schema->get_tables; +is(scalar @tables, 1, "right number of tables"); +my $table = shift @tables; +my @fields = $table->get_fields; +is(scalar @fields, 4, "right number of fields"); + +# +# Blow away the existing schema object. +# +$tr->{'schema'} = undef; # Now, pass parser_args indirectly... $tr->parser(\&silly_parser, { delimiter => "\t" }); $data =~ s/\|/\t/g; $pargs = $tr->parser_args; -$parsed = $tr->translate(\$data); +$tr->translate(\$data); is($pargs->{'delimiter'}, "\t", "parser_args works when called indirectly"); -is(scalar @{$parsed}, 4, - "right number of fields with new delimiter"); +@tables = $schema->get_tables; +is(scalar @tables, 1, "right number of tables"); +$table = shift @tables; +@fields = $table->get_fields; +is(scalar @fields, 4, "right number of fields"); undef $tr; $tr = SQL::Translator->new(parser => \&silly_parser, parser_args => { delimiter => ":" }); $data =~ s/\t/:/g; $pargs = $tr->parser_args; -$parsed = $tr->translate(\$data); +$tr->translate(\$data); is($pargs->{'delimiter'}, ":", "parser_args works when called as constructor arg"); -is(scalar @{$parsed}, 4, - "right number of fields with new delimiter"); - +@tables = $schema->get_tables; +is(scalar @tables, 1, "right number of tables"); +$table = shift @tables; +@fields = $table->get_fields; +is(scalar @fields, 4, "right number of fields with new delimiter");