Commit | Line | Data |
046f18e5 |
1 | #!/usr/bin/perl |
2 | # vim: set ft=perl: |
3 | # |
4 | # |
5 | |
6 | use strict; |
7 | use SQL::Translator; |
8 | use SQL::Translator::Parser::xSV qw(parse); |
37ac104a |
9 | use Test::More; |
046f18e5 |
10 | |
37ac104a |
11 | plan tests => 10; |
046f18e5 |
12 | |
13 | my $tr = SQL::Translator->new; |
14 | my $data = q|One, Two, Three, Four, Five |
15 | I, Am, Some, Data, Yo |
16 | And, So, am, I, "you crazy, crazy bastard" |
17 | );|; |
18 | |
046f18e5 |
19 | my $val = parse($tr, $data); |
20 | |
21 | # $val holds the processed data structure. |
22 | |
23 | # The data structure should have one key: |
37ac104a |
24 | is(scalar keys %{$val}, 1, "One table..."); |
046f18e5 |
25 | |
26 | # The data structure should have a single key, named sessions |
37ac104a |
27 | ok(defined $val->{'table1'} => "...named 'table1'"); |
046f18e5 |
28 | |
29 | # $val->{'table1'} should have a single index (since we haven't |
30 | # defined an index, but have defined a primary key) |
44fcd0b5 |
31 | my $indices = $val->{'table1'}->{'indices'}; |
37ac104a |
32 | is(scalar @{$indices}, 1, "correct index number"); |
046f18e5 |
33 | |
37ac104a |
34 | is($indices->[0]->{'type'}, 'primary_key', "correct index type"); |
35 | is($indices->[0]->{'fields'}->[0], 'One', "correct index name"); |
046f18e5 |
36 | |
37 | # $val->{'table1'} should have two fields, id and a_sessionn |
38 | my $fields = $val->{'table1'}->{'fields'}; |
37ac104a |
39 | is(scalar keys %{$fields} => 5 => "5 fields in %fields"); |
046f18e5 |
40 | |
37ac104a |
41 | is($fields->{'One'}->{'data_type'}, 'char', |
42 | "\$fields->{'One'}->{'data_type'} == 'char'"); |
046f18e5 |
43 | |
37ac104a |
44 | is($fields->{'One'}->{'is_primary_key'} => 1, |
45 | "\$fields->{'One'}->{'is_primary_key'} == 1"); |
046f18e5 |
46 | |
37ac104a |
47 | ok(! defined $fields->{'Two'}->{'is_primary_key'}, |
48 | "\$fields->{'Two'}->{'is_primary_key'} == 0"); |
046f18e5 |
49 | |
50 | # Test that the order is being maintained by the internal order |
51 | # data element |
52 | my @order = sort { $fields->{$a}->{'order'} |
53 | <=> |
54 | $fields->{$b}->{'order'} |
55 | } keys %{$fields}; |
37ac104a |
56 | ok($order[0] eq 'One' && $order[4] eq 'Five', "Ordering OK"); |