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); |
9 | |
10 | $SQL::Translator::DEBUG = 0; |
11 | |
12 | my $tr = SQL::Translator->new; |
13 | my $data = q|One, Two, Three, Four, Five |
14 | I, Am, Some, Data, Yo |
15 | And, So, am, I, "you crazy, crazy bastard" |
16 | );|; |
17 | |
18 | BEGIN { print "1..10\n"; } |
19 | |
20 | my $val = parse($tr, $data); |
21 | |
22 | # $val holds the processed data structure. |
23 | |
24 | # The data structure should have one key: |
25 | print "not " if (scalar keys %{$val} != 1); |
26 | print "ok 1\n"; |
27 | |
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); |
31 | |
32 | # $val->{'table1'} should have a single index (since we haven't |
33 | # defined an index, but have defined a primary key) |
44fcd0b5 |
34 | my $indices = $val->{'table1'}->{'indices'}; |
35 | print "not " unless (scalar @{$indices} == 1); |
046f18e5 |
36 | print "ok 3 # correct index number\n"; |
37 | |
44fcd0b5 |
38 | print "not " unless ($indices->[0]->{'type'} eq 'primary_key'); |
046f18e5 |
39 | print "ok 4 # correct index type\n"; |
44fcd0b5 |
40 | print "not " unless ($indices->[0]->{'fields'}->[0] eq 'One'); |
046f18e5 |
41 | print "ok 5 # correct index name\n"; |
42 | |
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"; |
47 | |
48 | print "not " unless ($fields->{'One'}->{'data_type'} eq 'char'); |
49 | print "ok 7 # correct field type: One (char)\n"; |
50 | |
51 | print "not " unless ($fields->{'One'}->{'is_primary_key'} == 1); |
52 | print "ok 8 # correct key identification (One == key)\n"; |
53 | |
54 | print "not " if (defined $fields->{'Two'}->{'is_primary_key'}); |
55 | print "ok 9 # correct key identification (Two != key)\n"; |
56 | |
57 | # Test that the order is being maintained by the internal order |
58 | # data element |
59 | my @order = sort { $fields->{$a}->{'order'} |
60 | <=> |
61 | $fields->{$b}->{'order'} |
62 | } keys %{$fields}; |
63 | print "not " unless ($order[0] eq 'One' && $order[4] eq 'Five'); |
64 | print "ok 10 # ordering of fields\n"; |