Commit | Line | Data |
fc4e23d3 |
1 | #!/usr/bin/perl |
2 | # vim: set ft=perl: |
fc4e23d3 |
3 | |
fbc0552f |
4 | use Test::More; |
fc4e23d3 |
5 | use SQL::Translator; |
b1a69c78 |
6 | use SQL::Translator::Schema::Constants; |
fc4e23d3 |
7 | |
fbc0552f |
8 | eval { |
9 | require SQL::Translator::Parser::Excel; |
10 | SQL::Translator::Parser::Excel->import('parse'); |
11 | }; |
12 | if ($@) { |
13 | plan skip_all => "$@"; |
14 | } |
15 | else { |
16 | plan tests => 31; |
17 | } |
18 | |
b1a69c78 |
19 | my $tr = SQL::Translator->new(parser => "Excel"); |
20 | my $t = $tr->translate(filename => "t/data/Excel/t.xls"); |
21 | my $schema = $tr->schema; |
fc4e23d3 |
22 | |
b1a69c78 |
23 | my @tables = $schema->get_tables; |
24 | is( scalar @tables, 1, 'Parsed 1 table' ); |
ab0aa010 |
25 | |
b1a69c78 |
26 | my $table = shift @tables; |
27 | is( $table->name, 'Sheet1', 'Table name is "Sheet1"' ); |
ab0aa010 |
28 | |
b1a69c78 |
29 | my @fields = $table->get_fields; |
30 | is( scalar @fields, 7, 'Table has 7 fields' ); |
31 | |
32 | my $f1 = shift @fields; |
33 | is( $f1->name, 'ID', 'First field name is "ID"' ); |
71e9c5e4 |
34 | is( lc $f1->data_type, 'integer', 'Data type is "integer"' ); |
35 | is( $f1->size, 5, 'Size is "5"' ); |
b1a69c78 |
36 | is( $f1->is_primary_key, 1, 'Field is PK' ); |
37 | |
38 | my $f2 = shift @fields; |
39 | is( $f2->name, 'text', 'Second field name is "text"' ); |
71e9c5e4 |
40 | is( lc $f2->data_type, 'char', 'Data type is "char"' ); |
41 | is( $f2->size, 7, 'Size is "7"' ); |
b1a69c78 |
42 | is( $f2->is_primary_key, 0, 'Field is not PK' ); |
43 | |
44 | my $f3 = shift @fields; |
45 | is( $f3->name, 'number', 'Third field name is "number"' ); |
beb8e233 |
46 | is( lc $f3->data_type, 'integer', 'Data type is "integer"' ); |
47 | is( $f3->size, 1, 'Size is "1"' ); |
b1a69c78 |
48 | is( $f3->is_primary_key, 0, 'Field is not PK' ); |
49 | |
50 | my $f4 = shift @fields; |
51 | is( $f4->name, 'math', 'Fourth field name is "math"' ); |
beb8e233 |
52 | is( lc $f4->data_type, 'float', 'Data type is "float"' ); |
53 | is( $f4->size, '3,1', 'Size is "3,1"' ); |
b1a69c78 |
54 | is( $f4->is_primary_key, 0, 'Field is not PK' ); |
55 | |
56 | my $f5 = shift @fields; |
57 | is( $f5->name, 'bitmap', 'Fifth field name is "bitmap"' ); |
cc558ea2 |
58 | is( lc $f5->data_type, 'char', 'Data type is "char"' ); |
c77202c4 |
59 | is( $f5->size, 1, 'Size is "1"' ); |
b1a69c78 |
60 | is( $f5->is_primary_key, 0, 'Field is not PK' ); |
61 | |
62 | my $f6 = shift @fields; |
63 | is( $f6->name, 'today', 'Sixth field name is "today"' ); |
71e9c5e4 |
64 | is( lc $f6->data_type, 'char', 'Data type is "CHAR"' ); |
65 | is( $f6->size, 10, 'Size is "10"' ); |
b1a69c78 |
66 | is( $f6->is_primary_key, 0, 'Field is not PK' ); |
67 | |
68 | my $f7 = shift @fields; |
69 | is( $f7->name, 'silly_field_with_random_characters', |
70 | 'Seventh field name is "silly_field_with_random_characters"' ); |
71e9c5e4 |
71 | is( lc $f7->data_type, 'char', 'Data type is "CHAR"' ); |
72 | is( $f7->size, 11, 'Size is "11"' ); |
b1a69c78 |
73 | is( $f7->is_primary_key, 0, 'Field is not PK' ); |