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