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