Added list of constants exported to the docs.
[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;
046f18e5 11use SQL::Translator::Parser::xSV qw(parse);
dddbae2a 12use Test::More tests => 25;
046f18e5 13
14my $tr = SQL::Translator->new;
6b73ef23 15my $s = SQL::Translator::Schema->new;
9c62867a 16my $data = q|One, Two, Three, Four, Five, Six, Seven
17I, Am, Some, Data, Yo, -10, .04
18And, So, am, I, "you crazy, crazy bastard", 500982, 1.1
19|;
046f18e5 20
9c62867a 21$tr->parser_args( trim_fields => 1, scan_fields => 1 );
6b73ef23 22my $val = parse($tr, $data, $s);
046f18e5 23
dddbae2a 24my $schema = $tr->schema;
25my @tables = $schema->get_tables;
26is( scalar @tables, 1, 'Correct number of tables (1)' );
27
28my $table = shift @tables;
29is( $table->name, 'table1', 'Table is named "table1"' );
30
31my @fields = $table->get_fields;
32is( scalar @fields, 7, 'Correct number of fields (7)' );
33
34my $f1 = $fields[0];
35is( $f1->name, 'One', 'First field name is "One"' );
36is( $f1->data_type, 'char', 'Data type is "char"' );
37is( $f1->size, '3', 'Size is "3"' );
38is( $f1->is_primary_key, 1, 'Field is PK' );
39
40my $f2 = $fields[1];
41is( $f2->name, 'Two', 'First field name is "Two"' );
42is( $f2->data_type, 'char', 'Data type is "char"' );
43is( $f2->size, '2', 'Size is "2"' );
44is( $f2->is_primary_key, 0, 'Field is not PK' );
45
46my $f5 = $fields[4];
47is( $f5->name, 'Five', 'Fifth field name is "Five"' );
48is( $f5->data_type, 'char', 'Data type is "char"' );
49is( $f5->size, '26', 'Size is "26"' );
50is( $f5->is_primary_key, 0, 'Field is not PK' );
51
52my $f6 = $fields[5];
53is( $f6->name, 'Six', 'Sixth field name is "Six"' );
54is( $f6->data_type, 'integer', 'Data type is "integer"' );
55is( $f6->size, '6', 'Size is "6"' );
56
57my $f7 = $fields[6];
58is( $f7->name, 'Seven', 'Seventh field name is "Seven"' );
59is( $f7->data_type, 'float', 'Data type is "float"' );
923c7bb8 60is( $f7->size, '3,2', 'Size is "3,2"' );
dddbae2a 61
62my @indices = $table->get_indices;
63is( scalar @indices, 0, 'Correct number of indices (0)' );
64
65my @constraints = $table->get_constraints;
66is( scalar @constraints, 1, 'Correct number of constraints (1)' );
67my $c = shift @constraints;
68is( $c->type, PRIMARY_KEY, 'Constraint is a PK' );
69is( join(',', $c->fields), 'One', 'On field "One"' );