8 use SQL::Translator::Parser::xSV qw(parse);
10 $SQL::Translator::DEBUG = 0;
12 my $tr = SQL::Translator->new;
13 my $data = q|One, Two, Three, Four, Five
15 And, So, am, I, "you crazy, crazy bastard"
18 BEGIN { print "1..10\n"; }
20 my $val = parse($tr, $data);
22 # $val holds the processed data structure.
24 # The data structure should have one key:
25 print "not " if (scalar keys %{$val} != 1);
28 # The data structure should have a single key, named sessions
29 print "not " unless (defined $val->{'table1'});
30 print qq(ok 2 # has a key named "table1"\n);
32 # $val->{'table1'} should have a single index (since we haven't
33 # defined an index, but have defined a primary key)
34 my $indices = $val->{'table1'}->{'indices'};
35 print "not " unless (scalar @{$indices} == 1);
36 print "ok 3 # correct index number\n";
38 print "not " unless ($indices->[0]->{'type'} eq 'primary_key');
39 print "ok 4 # correct index type\n";
40 print "not " unless ($indices->[0]->{'fields'}->[0] eq 'One');
41 print "ok 5 # correct index name\n";
43 # $val->{'table1'} should have two fields, id and a_sessionn
44 my $fields = $val->{'table1'}->{'fields'};
45 print "not " unless (scalar keys %{$fields} == 5);
46 print "ok 6 # correct number of fields (5)\n";
48 print "not " unless ($fields->{'One'}->{'data_type'} eq 'char');
49 print "ok 7 # correct field type: One (char)\n";
51 print "not " unless ($fields->{'One'}->{'is_primary_key'} == 1);
52 print "ok 8 # correct key identification (One == key)\n";
54 print "not " if (defined $fields->{'Two'}->{'is_primary_key'});
55 print "ok 9 # correct key identification (Two != key)\n";
57 # Test that the order is being maintained by the internal order
59 my @order = sort { $fields->{$a}->{'order'}
61 $fields->{$b}->{'order'}
63 print "not " unless ($order[0] eq 'One' && $order[4] eq 'Five');
64 print "ok 10 # ordering of fields\n";