7bee0de1b0023fde99ea85a3156dcd2274ec0b68
[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
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
19 my $tr     = SQL::Translator->new(parser => "Excel");
20 my $t      = $tr->translate(filename => "t/data/Excel/t.xls");
21 my $schema = $tr->schema;
22
23 my @tables = $schema->get_tables;
24 is( scalar @tables, 1, 'Parsed 1 table' );
25
26 my $table = shift @tables;
27 is( $table->name, 'Sheet1', 'Table name is "Sheet1"' );
28
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"' );
34 is( lc $f1->data_type, 'integer', 'Data type is "integer"' );
35 is( $f1->size, 5, 'Size is "5"' );
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"' );
40 is( lc $f2->data_type, 'char', 'Data type is "char"' );
41 is( $f2->size, 7, 'Size is "7"' );
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"' );
46 is( lc $f3->data_type, 'integer', 'Data type is "integer"' );
47 is( $f3->size, 1, 'Size is "1"' );
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"' );
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 my $f5 = shift @fields;
57 is( $f5->name, 'bitmap', 'Fifth field name is "bitmap"' );
58 is( lc $f5->data_type, 'char', 'Data type is "char"' );
59 is( $f5->size, 1, 'Size is "1"' );
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"' );
64 is( lc $f6->data_type, 'char', 'Data type is "CHAR"' );
65 is( $f6->size, 10, 'Size is "10"' );
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"' );
71 is( lc $f7->data_type, 'char', 'Data type is "CHAR"' );
72 is( $f7->size, 11, 'Size is "11"' );
73 is( $f7->is_primary_key, 0, 'Field is not PK' );