Add IRC metadata and update repository and bugtracker URLs
[dbsrgits/SQL-Translator.git] / t / 10excel.t
CommitLineData
fc4e23d3 1#!/usr/bin/perl
2# vim: set ft=perl:
fc4e23d3 3
fbc0552f 4use Test::More;
fc4e23d3 5use SQL::Translator;
b1a69c78 6use SQL::Translator::Schema::Constants;
2d691ec1 7use Test::SQL::Translator qw(maybe_plan);
fc4e23d3 8
2d691ec1 9BEGIN {
10 maybe_plan(31, 'SQL::Translator::Parser::Excel');
fbc0552f 11 SQL::Translator::Parser::Excel->import('parse');
fbc0552f 12}
aee4b66e 13
b1a69c78 14my $tr = SQL::Translator->new(parser => "Excel");
15my $t = $tr->translate(filename => "t/data/Excel/t.xls");
16my $schema = $tr->schema;
fc4e23d3 17
b1a69c78 18my @tables = $schema->get_tables;
19is( scalar @tables, 1, 'Parsed 1 table' );
ab0aa010 20
b1a69c78 21my $table = shift @tables;
22is( $table->name, 'Sheet1', 'Table name is "Sheet1"' );
ab0aa010 23
b1a69c78 24my @fields = $table->get_fields;
25is( scalar @fields, 7, 'Table has 7 fields' );
26
27my $f1 = shift @fields;
28is( $f1->name, 'ID', 'First field name is "ID"' );
71e9c5e4 29is( lc $f1->data_type, 'integer', 'Data type is "integer"' );
30is( $f1->size, 5, 'Size is "5"' );
b1a69c78 31is( $f1->is_primary_key, 1, 'Field is PK' );
32
33my $f2 = shift @fields;
34is( $f2->name, 'text', 'Second field name is "text"' );
71e9c5e4 35is( lc $f2->data_type, 'char', 'Data type is "char"' );
36is( $f2->size, 7, 'Size is "7"' );
b1a69c78 37is( $f2->is_primary_key, 0, 'Field is not PK' );
38
39my $f3 = shift @fields;
40is( $f3->name, 'number', 'Third field name is "number"' );
beb8e233 41is( lc $f3->data_type, 'integer', 'Data type is "integer"' );
42is( $f3->size, 1, 'Size is "1"' );
b1a69c78 43is( $f3->is_primary_key, 0, 'Field is not PK' );
44
45my $f4 = shift @fields;
2c273e34 46TODO: {
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
57my $f5 = shift @fields;
58is( $f5->name, 'bitmap', 'Fifth field name is "bitmap"' );
cc558ea2 59is( lc $f5->data_type, 'char', 'Data type is "char"' );
c77202c4 60is( $f5->size, 1, 'Size is "1"' );
b1a69c78 61is( $f5->is_primary_key, 0, 'Field is not PK' );
62
63my $f6 = shift @fields;
64is( $f6->name, 'today', 'Sixth field name is "today"' );
71e9c5e4 65is( lc $f6->data_type, 'char', 'Data type is "CHAR"' );
66is( $f6->size, 10, 'Size is "10"' );
b1a69c78 67is( $f6->is_primary_key, 0, 'Field is not PK' );
68
69my $f7 = shift @fields;
aee4b66e 70is( $f7->name, 'silly_field_with_random_characters',
b1a69c78 71 'Seventh field name is "silly_field_with_random_characters"' );
71e9c5e4 72is( lc $f7->data_type, 'char', 'Data type is "CHAR"' );
73is( $f7->size, 11, 'Size is "11"' );
b1a69c78 74is( $f7->is_primary_key, 0, 'Field is not PK' );