Commit | Line | Data |
0494e672 |
1 | #!/usr/bin/perl |
2 | # vim: set ft=perl: |
3 | # |
4 | # NOTE!!!! |
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! |
8 | # |
9 | |
b8661f30 |
10 | use strict; |
44fb27ae |
11 | |
12 | use Test::More tests => 11; |
b8661f30 |
13 | use SQL::Translator; |
0494e672 |
14 | use SQL::Translator::Parser::MySQL qw(parse); |
15 | |
b8661f30 |
16 | my $tr = SQL::Translator->new; |
17 | my $data = q|create table sessions ( |
18 | id char(32) not null primary key, |
19 | a_session text |
20 | );|; |
0494e672 |
21 | |
b8661f30 |
22 | my $val = parse($tr, $data); |
0494e672 |
23 | |
b8661f30 |
24 | # $val holds the processed data structure. |
25 | |
26 | # The data structure should have one key: |
44fb27ae |
27 | is(scalar keys %{$val}, 1); |
b8661f30 |
28 | |
29 | # The data structure should have a single key, named sessions |
44fb27ae |
30 | ok(defined $val->{'sessions'}); |
b8661f30 |
31 | |
32 | # $val->{'sessions'} should have a single index (since we haven't |
33 | # defined an index, but have defined a primary key) |
44fcd0b5 |
34 | my $indices = $val->{'sessions'}->{'indices'}; |
44fb27ae |
35 | is(scalar @{$indices}, 1, "correct index number"); |
b8661f30 |
36 | |
44fb27ae |
37 | is($indices->[0]->{'type'}, 'primary_key', "correct index type"); |
38 | is($indices->[0]->{'fields'}->[0], 'id', "correct index name"); |
b8661f30 |
39 | |
40 | # $val->{'sessions'} should have two fields, id and a_sessionn |
41 | my $fields = $val->{'sessions'}->{'fields'}; |
44fb27ae |
42 | is(scalar keys %{$fields}, 2, "correct fields number"); |
b8661f30 |
43 | |
44fb27ae |
44 | is($fields->{'id'}->{'data_type'}, 'char', |
45 | "correct field type: id (char)"); |
b8661f30 |
46 | |
44fb27ae |
47 | is ($fields->{'a_session'}->{'data_type'}, 'text', |
48 | "correct field type: a_session (text)"); |
b8661f30 |
49 | |
44fb27ae |
50 | is($fields->{'id'}->{'is_primary_key'}, 1, |
51 | "correct key identification (id == key)"); |
b8661f30 |
52 | |
44fb27ae |
53 | ok(! defined $fields->{'a_session'}->{'is_primary_key'}, |
54 | "correct key identification (a_session != key)"); |
b8661f30 |
55 | |
56 | # Test that the order is being maintained by the internal order |
57 | # data element |
58 | my @order = sort { $fields->{$a}->{'order'} |
59 | <=> |
60 | $fields->{$b}->{'order'} |
61 | } keys %{$fields}; |
44fb27ae |
62 | |
63 | ok($order[0] eq 'id' && $order[1] eq 'a_session', "ordering of fields"); |