Release commit for 1.62
[dbsrgits/SQL-Translator.git] / t / 10excel.t
1 #!/usr/bin/perl
2 # vim: set ft=perl:
3
4 use Test::More;
5 use SQL::Translator;
6 use SQL::Translator::Schema::Constants;
7 use Test::SQL::Translator qw(maybe_plan);
8
9 BEGIN {
10     maybe_plan(31, 'SQL::Translator::Parser::Excel');
11     SQL::Translator::Parser::Excel->import('parse');
12 }
13
14 my $tr     = SQL::Translator->new(parser => "Excel");
15 my $t      = $tr->translate(filename => "t/data/Excel/t.xls");
16 my $schema = $tr->schema;
17
18 my @tables = $schema->get_tables;
19 is( scalar @tables, 1, 'Parsed 1 table' );
20
21 my $table = shift @tables;
22 is( $table->name, 'Sheet1', 'Table name is "Sheet1"' );
23
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"' );
29 is( lc $f1->data_type, 'integer', 'Data type is "integer"' );
30 is( $f1->size, 5, 'Size is "5"' );
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"' );
35 is( lc $f2->data_type, 'char', 'Data type is "char"' );
36 is( $f2->size, 7, 'Size is "7"' );
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"' );
41 is( lc $f3->data_type, 'integer', 'Data type is "integer"' );
42 is( $f3->size, 1, 'Size is "1"' );
43 is( $f3->is_primary_key, 0, 'Field is not PK' );
44
45 my $f4 = shift @fields;
46 TODO: {
47     eval { require Spreadsheet::ParseExcel };
48        todo_skip "Bug in Spreadsheet::ParseExcel, http://rt.cpan.org/Public/Bug/Display.html?id=39892", 4
49                if ( $Spreadsheet::ParseExcel::VERSION > 0.32 and $Spreadsheet::ParseExcel::VERSION < 0.41 );
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 }
56
57 my $f5 = shift @fields;
58 is( $f5->name, 'bitmap', 'Fifth field name is "bitmap"' );
59 is( lc $f5->data_type, 'char', 'Data type is "char"' );
60 is( $f5->size, 1, 'Size is "1"' );
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"' );
65 is( lc $f6->data_type, 'char', 'Data type is "CHAR"' );
66 is( $f6->size, 10, 'Size is "10"' );
67 is( $f6->is_primary_key, 0, 'Field is not PK' );
68
69 my $f7 = shift @fields;
70 is( $f7->name, 'silly_field_with_random_characters',
71     'Seventh field name is "silly_field_with_random_characters"' );
72 is( lc $f7->data_type, 'char', 'Data type is "CHAR"' );
73 is( $f7->size, 11, 'Size is "11"' );
74 is( $f7->is_primary_key, 0, 'Field is not PK' );