Fixed spelling of "indices" in various files, finished adding all of Tim
[dbsrgits/SQL-Translator.git] / t / 06xsv.t
CommitLineData
046f18e5 1#!/usr/bin/perl
2# vim: set ft=perl:
3#
4#
5
6use strict;
7use SQL::Translator;
8use SQL::Translator::Parser::xSV qw(parse);
9
10$SQL::Translator::DEBUG = 0;
11
12my $tr = SQL::Translator->new;
13my $data = q|One, Two, Three, Four, Five
14I, Am, Some, Data, Yo
15And, So, am, I, "you crazy, crazy bastard"
16);|;
17
18BEGIN { print "1..10\n"; }
19
20my $val = parse($tr, $data);
21
22# $val holds the processed data structure.
23
24# The data structure should have one key:
25print "not " if (scalar keys %{$val} != 1);
26print "ok 1\n";
27
28# The data structure should have a single key, named sessions
29print "not " unless (defined $val->{'table1'});
30print 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 34my $indices = $val->{'table1'}->{'indices'};
35print "not " unless (scalar @{$indices} == 1);
046f18e5 36print "ok 3 # correct index number\n";
37
44fcd0b5 38print "not " unless ($indices->[0]->{'type'} eq 'primary_key');
046f18e5 39print "ok 4 # correct index type\n";
44fcd0b5 40print "not " unless ($indices->[0]->{'fields'}->[0] eq 'One');
046f18e5 41print "ok 5 # correct index name\n";
42
43# $val->{'table1'} should have two fields, id and a_sessionn
44my $fields = $val->{'table1'}->{'fields'};
45print "not " unless (scalar keys %{$fields} == 5);
46print "ok 6 # correct number of fields (5)\n";
47
48print "not " unless ($fields->{'One'}->{'data_type'} eq 'char');
49print "ok 7 # correct field type: One (char)\n";
50
51print "not " unless ($fields->{'One'}->{'is_primary_key'} == 1);
52print "ok 8 # correct key identification (One == key)\n";
53
54print "not " if (defined $fields->{'Two'}->{'is_primary_key'});
55print "ok 9 # correct key identification (Two != key)\n";
56
57# Test that the order is being maintained by the internal order
58# data element
59my @order = sort { $fields->{$a}->{'order'}
60 <=>
61 $fields->{$b}->{'order'}
62 } keys %{$fields};
63print "not " unless ($order[0] eq 'One' && $order[4] eq 'Five');
64print "ok 10 # ordering of fields\n";