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