9 use Test::More tests => 9;
13 my $pargs = $tr->parser_args;
15 my @fields = split /$pargs->{'delimiter'}/, $data;
17 my $schema = $tr->schema;
18 my $table = $schema->add_table( name => 'foo') or die $schema->error;
19 for my $value ( @fields ) {
20 my $field = $table->add_field( name => $value ) or die $table->error;
26 # The "data" to be parsed
27 my $data = q(Id|Name|Phone Number|Favorite Flavor|);
29 my $tr = SQL::Translator->new;
31 # Pass parser_args as an explicit method call
32 $tr->parser(\&silly_parser);
33 $tr->parser_args(delimiter => '\|');
35 my $pargs = $tr->parser_args;
36 $tr->translate(\$data);
37 my $schema = $tr->schema;
39 is($pargs->{'delimiter'}, '\|', "parser_args works when called directly");
40 my @tables = $schema->get_tables;
41 is(scalar @tables, 1, "right number of tables");
42 my $table = shift @tables;
43 my @fields = $table->get_fields;
44 is(scalar @fields, 4, "right number of fields");
47 # Blow away the existing schema object.
49 $tr->{'schema'} = undef;
51 # Now, pass parser_args indirectly...
52 $tr->parser(\&silly_parser, { delimiter => "\t" });
55 $pargs = $tr->parser_args;
56 $tr->translate(\$data);
58 is($pargs->{'delimiter'}, "\t",
59 "parser_args works when called indirectly");
61 @tables = $schema->get_tables;
62 is(scalar @tables, 1, "right number of tables");
63 $table = shift @tables;
64 @fields = $table->get_fields;
65 is(scalar @fields, 4, "right number of fields");
68 $tr = SQL::Translator->new(parser => \&silly_parser,
69 parser_args => { delimiter => ":" });
71 $pargs = $tr->parser_args;
72 $tr->translate(\$data);
74 is($pargs->{'delimiter'}, ":",
75 "parser_args works when called as constructor arg");
77 @tables = $schema->get_tables;
78 is(scalar @tables, 1, "right number of tables");
79 $table = shift @tables;
80 @fields = $table->get_fields;
81 is(scalar @fields, 4, "right number of fields with new delimiter");