Updated to use Text::RecordParser and added scanning of fields, more
[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);
37ac104a 9use Test::More;
046f18e5 10
37ac104a 11plan tests => 10;
046f18e5 12
13my $tr = SQL::Translator->new;
14my $data = q|One, Two, Three, Four, Five
15I, Am, Some, Data, Yo
16And, So, am, I, "you crazy, crazy bastard"
17);|;
18
046f18e5 19my $val = parse($tr, $data);
20
21# $val holds the processed data structure.
22
23# The data structure should have one key:
37ac104a 24is(scalar keys %{$val}, 1, "One table...");
046f18e5 25
26# The data structure should have a single key, named sessions
37ac104a 27ok(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 31my $indices = $val->{'table1'}->{'indices'};
37ac104a 32is(scalar @{$indices}, 1, "correct index number");
046f18e5 33
37ac104a 34is($indices->[0]->{'type'}, 'primary_key', "correct index type");
35is($indices->[0]->{'fields'}->[0], 'One', "correct index name");
046f18e5 36
37# $val->{'table1'} should have two fields, id and a_sessionn
38my $fields = $val->{'table1'}->{'fields'};
37ac104a 39is(scalar keys %{$fields} => 5 => "5 fields in %fields");
046f18e5 40
37ac104a 41is($fields->{'One'}->{'data_type'}, 'char',
42 "\$fields->{'One'}->{'data_type'} == 'char'");
046f18e5 43
37ac104a 44is($fields->{'One'}->{'is_primary_key'} => 1,
45 "\$fields->{'One'}->{'is_primary_key'} == 1");
046f18e5 46
37ac104a 47ok(! 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
52my @order = sort { $fields->{$a}->{'order'}
53 <=>
54 $fields->{$b}->{'order'}
55 } keys %{$fields};
37ac104a 56ok($order[0] eq 'One' && $order[4] eq 'Five', "Ordering OK");