Just the fairy.
[dbsrgits/SQL-Translator.git] / t / 06xsv.t
CommitLineData
046f18e5 1#!/usr/bin/perl
2# vim: set ft=perl:
9c62867a 3
046f18e5 4#
9c62867a 5# Tests for xSV parser
046f18e5 6#
046f18e5 7use strict;
8use SQL::Translator;
6b73ef23 9use SQL::Translator::Schema;
dddbae2a 10use SQL::Translator::Schema::Constants;
fbc0552f 11use Test::More;
12
13eval {
14 require SQL::Translator::Parser::xSV;
15 SQL::Translator::Parser::xSV->import('parse');
16};
17if ($@) {
18 plan skip_all => "$@";
19}
20else {
21 plan tests => 25;
22}
046f18e5 23
24my $tr = SQL::Translator->new;
6b73ef23 25my $s = SQL::Translator::Schema->new;
9c62867a 26my $data = q|One, Two, Three, Four, Five, Six, Seven
27I, Am, Some, Data, Yo, -10, .04
28And, So, am, I, "you crazy, crazy bastard", 500982, 1.1
29|;
046f18e5 30
9c62867a 31$tr->parser_args( trim_fields => 1, scan_fields => 1 );
6b73ef23 32my $val = parse($tr, $data, $s);
046f18e5 33
dddbae2a 34my $schema = $tr->schema;
35my @tables = $schema->get_tables;
36is( scalar @tables, 1, 'Correct number of tables (1)' );
37
38my $table = shift @tables;
39is( $table->name, 'table1', 'Table is named "table1"' );
40
41my @fields = $table->get_fields;
42is( scalar @fields, 7, 'Correct number of fields (7)' );
43
44my $f1 = $fields[0];
45is( $f1->name, 'One', 'First field name is "One"' );
46is( $f1->data_type, 'char', 'Data type is "char"' );
47is( $f1->size, '3', 'Size is "3"' );
48is( $f1->is_primary_key, 1, 'Field is PK' );
49
50my $f2 = $fields[1];
51is( $f2->name, 'Two', 'First field name is "Two"' );
52is( $f2->data_type, 'char', 'Data type is "char"' );
53is( $f2->size, '2', 'Size is "2"' );
54is( $f2->is_primary_key, 0, 'Field is not PK' );
55
56my $f5 = $fields[4];
57is( $f5->name, 'Five', 'Fifth field name is "Five"' );
58is( $f5->data_type, 'char', 'Data type is "char"' );
59is( $f5->size, '26', 'Size is "26"' );
60is( $f5->is_primary_key, 0, 'Field is not PK' );
61
62my $f6 = $fields[5];
63is( $f6->name, 'Six', 'Sixth field name is "Six"' );
64is( $f6->data_type, 'integer', 'Data type is "integer"' );
65is( $f6->size, '6', 'Size is "6"' );
66
67my $f7 = $fields[6];
68is( $f7->name, 'Seven', 'Seventh field name is "Seven"' );
69is( $f7->data_type, 'float', 'Data type is "float"' );
923c7bb8 70is( $f7->size, '3,2', 'Size is "3,2"' );
dddbae2a 71
72my @indices = $table->get_indices;
73is( scalar @indices, 0, 'Correct number of indices (0)' );
74
75my @constraints = $table->get_constraints;
76is( scalar @constraints, 1, 'Correct number of constraints (1)' );
77my $c = shift @constraints;
78is( $c->type, PRIMARY_KEY, 'Constraint is a PK' );
79is( join(',', $c->fields), 'One', 'On field "One"' );