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 Test::More tests => 11;
14 use SQL::Translator::Parser::MySQL qw(parse);
16 my $tr = SQL::Translator->new;
17 my $data = q|create table sessions (
18 id char(32) not null primary key,
22 my $val = parse($tr, $data);
24 # $val holds the processed data structure.
26 # The data structure should have one key:
27 is(scalar keys %{$val}, 1);
29 # The data structure should have a single key, named sessions
30 ok(defined $val->{'sessions'});
32 # $val->{'sessions'} should have a single index (since we haven't
33 # defined an index, but have defined a primary key)
34 my $indices = $val->{'sessions'}->{'indices'};
35 is(scalar @{$indices}, 1, "correct index number");
37 is($indices->[0]->{'type'}, 'primary_key', "correct index type");
38 is($indices->[0]->{'fields'}->[0], 'id', "correct index name");
40 # $val->{'sessions'} should have two fields, id and a_sessionn
41 my $fields = $val->{'sessions'}->{'fields'};
42 is(scalar keys %{$fields}, 2, "correct fields number");
44 is($fields->{'id'}->{'data_type'}, 'char',
45 "correct field type: id (char)");
47 is ($fields->{'a_session'}->{'data_type'}, 'text',
48 "correct field type: a_session (text)");
50 is($fields->{'id'}->{'is_primary_key'}, 1,
51 "correct key identification (id == key)");
53 ok(! defined $fields->{'a_session'}->{'is_primary_key'},
54 "correct key identification (a_session != key)");
56 # Test that the order is being maintained by the internal order
58 my @order = sort { $fields->{$a}->{'order'}
60 $fields->{$b}->{'order'}
63 ok($order[0] eq 'id' && $order[1] eq 'a_session', "ordering of fields");