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; |
2d691ec1 |
7 | use Test::SQL::Translator qw(maybe_plan); |
fc4e23d3 |
8 | |
2d691ec1 |
9 | BEGIN { |
10 | maybe_plan(31, 'SQL::Translator::Parser::Excel'); |
fbc0552f |
11 | SQL::Translator::Parser::Excel->import('parse'); |
fbc0552f |
12 | } |
aee4b66e |
13 | |
b1a69c78 |
14 | my $tr = SQL::Translator->new(parser => "Excel"); |
15 | my $t = $tr->translate(filename => "t/data/Excel/t.xls"); |
16 | my $schema = $tr->schema; |
fc4e23d3 |
17 | |
b1a69c78 |
18 | my @tables = $schema->get_tables; |
19 | is( scalar @tables, 1, 'Parsed 1 table' ); |
ab0aa010 |
20 | |
b1a69c78 |
21 | my $table = shift @tables; |
22 | is( $table->name, 'Sheet1', 'Table name is "Sheet1"' ); |
ab0aa010 |
23 | |
b1a69c78 |
24 | my @fields = $table->get_fields; |
25 | is( scalar @fields, 7, 'Table has 7 fields' ); |
26 | |
27 | my $f1 = shift @fields; |
28 | is( $f1->name, 'ID', 'First field name is "ID"' ); |
71e9c5e4 |
29 | is( lc $f1->data_type, 'integer', 'Data type is "integer"' ); |
30 | is( $f1->size, 5, 'Size is "5"' ); |
b1a69c78 |
31 | is( $f1->is_primary_key, 1, 'Field is PK' ); |
32 | |
33 | my $f2 = shift @fields; |
34 | is( $f2->name, 'text', 'Second field name is "text"' ); |
71e9c5e4 |
35 | is( lc $f2->data_type, 'char', 'Data type is "char"' ); |
36 | is( $f2->size, 7, 'Size is "7"' ); |
b1a69c78 |
37 | is( $f2->is_primary_key, 0, 'Field is not PK' ); |
38 | |
39 | my $f3 = shift @fields; |
40 | is( $f3->name, 'number', 'Third field name is "number"' ); |
beb8e233 |
41 | is( lc $f3->data_type, 'integer', 'Data type is "integer"' ); |
42 | is( $f3->size, 1, 'Size is "1"' ); |
b1a69c78 |
43 | is( $f3->is_primary_key, 0, 'Field is not PK' ); |
44 | |
45 | my $f4 = shift @fields; |
2c273e34 |
46 | TODO: { |
47 | eval { require Spreadsheet::ParseExcel }; |
aee4b66e |
48 | todo_skip "Bug in Spreadsheet::ParseExcel, http://rt.cpan.org/Public/Bug/Display.html?id=39892", 4 |
cc48d354 |
49 | if ( $Spreadsheet::ParseExcel::VERSION > 0.32 and $Spreadsheet::ParseExcel::VERSION < 0.41 ); |
2c273e34 |
50 | |
51 | is( $f4->name, 'math', 'Fourth field name is "math"' ); |
52 | is( lc $f4->data_type, 'float', 'Data type is "float"' ); |
53 | is( $f4->size, '3,1', 'Size is "3,1"' ); |
54 | is( $f4->is_primary_key, 0, 'Field is not PK' ); |
55 | } |
b1a69c78 |
56 | |
57 | my $f5 = shift @fields; |
58 | is( $f5->name, 'bitmap', 'Fifth field name is "bitmap"' ); |
cc558ea2 |
59 | is( lc $f5->data_type, 'char', 'Data type is "char"' ); |
c77202c4 |
60 | is( $f5->size, 1, 'Size is "1"' ); |
b1a69c78 |
61 | is( $f5->is_primary_key, 0, 'Field is not PK' ); |
62 | |
63 | my $f6 = shift @fields; |
64 | is( $f6->name, 'today', 'Sixth field name is "today"' ); |
71e9c5e4 |
65 | is( lc $f6->data_type, 'char', 'Data type is "CHAR"' ); |
66 | is( $f6->size, 10, 'Size is "10"' ); |
b1a69c78 |
67 | is( $f6->is_primary_key, 0, 'Field is not PK' ); |
68 | |
69 | my $f7 = shift @fields; |
aee4b66e |
70 | is( $f7->name, 'silly_field_with_random_characters', |
b1a69c78 |
71 | 'Seventh field name is "silly_field_with_random_characters"' ); |
71e9c5e4 |
72 | is( lc $f7->data_type, 'char', 'Data type is "CHAR"' ); |
73 | is( $f7->size, 11, 'Size is "11"' ); |
b1a69c78 |
74 | is( $f7->is_primary_key, 0, 'Field is not PK' ); |