5 # For now, all this is testing is that Parse::RecDescent does not
6 # die with an error! I am not verifying the validity of the data
7 # returned here, just that the parser actually completed its parsing!
12 use SQL::Translator::Parser::MySQL qw(parse);
14 $SQL::Translator::DEBUG = 0;
16 my $tr = SQL::Translator->new;
17 my $data = q|create table sessions (
18 id char(32) not null primary key,
22 BEGIN { print "1..11\n"; }
24 my $val = parse($tr, $data);
26 # $val holds the processed data structure.
28 # The data structure should have one key:
29 print "not " if (scalar keys %{$val} != 1);
32 # The data structure should have a single key, named sessions
33 print "not " unless (defined $val->{'sessions'});
34 print qq(ok 2 # has a key named "sessions"\n);
36 # $val->{'sessions'} should have a single index (since we haven't
37 # defined an index, but have defined a primary key)
38 my $indeces = $val->{'sessions'}->{'indeces'};
39 print "not " unless (scalar @{$indeces} == 1);
40 print "ok 3 # correct index number\n";
42 print "not " unless ($indeces->[0]->{'type'} eq 'primary_key');
43 print "ok 4 # correct index type\n";
44 print "not " unless ($indeces->[0]->{'fields'}->[0] eq 'id');
45 print "ok 5 # correct index name\n";
47 # $val->{'sessions'} should have two fields, id and a_sessionn
48 my $fields = $val->{'sessions'}->{'fields'};
49 print "not " unless (scalar keys %{$fields} == 2);
50 print "ok 6 # correct fields number\n";
52 print "not " unless ($fields->{'id'}->{'data_type'} eq 'char');
53 print "ok 7 # correct field type: id (char)\n";
55 print "not " unless ($fields->{'a_session'}->{'data_type'} eq 'text');
56 print "ok 8 # correct field type: a_session (text)\n";
58 print "not " unless ($fields->{'id'}->{'is_primary_key'} == 1);
59 print "ok 9 # correct key identification (id == key)\n";
61 print "not " if (defined $fields->{'a_session'}->{'is_primary_key'});
62 print "ok 10 # correct key identification (a_session != key)\n";
64 # Test that the order is being maintained by the internal order
66 my @order = sort { $fields->{$a}->{'order'}
68 $fields->{$b}->{'order'}
70 print "not " unless ($order[0] eq 'id' && $order[1] eq 'a_session');
71 print "ok 11 # ordering of fields\n";