File: 06xsv.t

package info (click to toggle)
libsql-translator-perl 0.11011-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,380 kB
  • sloc: perl: 251,748; sql: 3,805; xml: 233; makefile: 7
file content (74 lines) | stat: -rw-r--r-- 2,266 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl
# vim: set ft=perl:

#
# Tests for xSV parser
#
use strict;
use SQL::Translator;
use SQL::Translator::Schema;
use SQL::Translator::Schema::Constants;
use Test::More;
use Test::SQL::Translator qw(maybe_plan);

BEGIN {
    maybe_plan(25, 'SQL::Translator::Parser::xSV');
    SQL::Translator::Parser::xSV->import('parse');
}

my $tr = SQL::Translator->new;
my $s  = SQL::Translator::Schema->new;
my $data = q|One, Two, Three, Four, Five, Six, Seven
I, Am, Some, Data, Yo, -10, .04
And, So, am, I, "you crazy, crazy bastard", 500982, 1.1
|;

$tr->parser_args( trim_fields => 1, scan_fields => 1 );
my $val = parse($tr, $data, $s);

my $schema = $tr->schema;
my @tables = $schema->get_tables;
is( scalar @tables, 1, 'Correct number of tables (1)' );

my $table = shift @tables;
is( $table->name, 'table1', 'Table is named "table1"' );

my @fields = $table->get_fields;
is( scalar @fields, 7, 'Correct number of fields (7)' );

my $f1 = $fields[0];
is( $f1->name, 'One', 'First field name is "One"' );
is( $f1->data_type, 'char', 'Data type is "char"' );
is( $f1->size, '3', 'Size is "3"' );
is( $f1->is_primary_key, 1, 'Field is PK' );

my $f2 = $fields[1];
is( $f2->name, 'Two', 'First field name is "Two"' );
is( $f2->data_type, 'char', 'Data type is "char"' );
is( $f2->size, '2', 'Size is "2"' );
is( $f2->is_primary_key, 0, 'Field is not PK' );

my $f5 = $fields[4];
is( $f5->name, 'Five', 'Fifth field name is "Five"' );
is( $f5->data_type, 'char', 'Data type is "char"' );
is( $f5->size, '26', 'Size is "26"' );
is( $f5->is_primary_key, 0, 'Field is not PK' );

my $f6 = $fields[5];
is( $f6->name, 'Six', 'Sixth field name is "Six"' );
is( $f6->data_type, 'integer', 'Data type is "integer"' );
is( $f6->size, '6', 'Size is "6"' );

my $f7 = $fields[6];
is( $f7->name, 'Seven', 'Seventh field name is "Seven"' );
is( $f7->data_type, 'float', 'Data type is "float"' );
is( $f7->size, '3,2', 'Size is "3,2"' );

my @indices = $table->get_indices;
is( scalar @indices, 0, 'Correct number of indices (0)' );

my @constraints = $table->get_constraints;
is( scalar @constraints, 1, 'Correct number of constraints (1)' );
my $c = shift @constraints;
is( $c->type, PRIMARY_KEY, 'Constraint is a PK' );
is( join(',', $c->fields), 'One', 'On field "One"' );