Added a lot more tests, now using the Schema object.
[dbsrgits/SQL-Translator.git] / t / 10excel.t
1 #!/usr/bin/perl
2 # vim: set ft=perl:
3 #
4
5 use Test::More 'no_plan'; # tests => 6;
6 use SQL::Translator;
7 use SQL::Translator::Parser::Excel 'parse';
8 use SQL::Translator::Schema::Constants;
9
10 my $tr     = SQL::Translator->new(parser => "Excel");
11 my $t      = $tr->translate(filename => "t/data/Excel/t.xls");
12 my $schema = $tr->schema;
13
14 #use Data::Dumper;
15 #print Dumper($schema), "\n";
16
17 #ok(scalar $tr->translate(producer => "MySQL"));
18
19 my @tables = $schema->get_tables;
20 is( scalar @tables, 1, 'Parsed 1 table' );
21
22 my $table = shift @tables;
23 is( $table->name, 'Sheet1', 'Table name is "Sheet1"' );
24
25 my @fields = $table->get_fields;
26 is( scalar @fields, 7, 'Table has 7 fields' );
27
28 my $f1 = shift @fields;
29 is( $f1->name, 'ID', 'First field name is "ID"' );
30 is( $f1->data_type, 'VARCHAR', 'Data type is "VARCHAR"' );
31 is( $f1->size, 255, 'Size is "255"' );
32 is( $f1->is_primary_key, 1, 'Field is PK' );
33
34 my $f2 = shift @fields;
35 is( $f2->name, 'text', 'Second field name is "text"' );
36 is( $f2->data_type, 'VARCHAR', 'Data type is "VARCHAR"' );
37 is( $f2->size, 255, 'Size is "255"' );
38 is( $f2->is_primary_key, 0, 'Field is not PK' );
39
40 my $f3 = shift @fields;
41 is( $f3->name, 'number', 'Third field name is "number"' );
42 is( $f3->data_type, 'VARCHAR', 'Data type is "VARCHAR"' );
43 is( $f3->size, 255, 'Size is "255"' );
44 is( $f3->is_primary_key, 0, 'Field is not PK' );
45
46 my $f4 = shift @fields;
47 is( $f4->name, 'math', 'Fourth field name is "math"' );
48 is( $f4->data_type, 'VARCHAR', 'Data type is "VARCHAR"' );
49 is( $f4->size, 255, 'Size is "255"' );
50 is( $f4->is_primary_key, 0, 'Field is not PK' );
51
52 my $f5 = shift @fields;
53 is( $f5->name, 'bitmap', 'Fifth field name is "bitmap"' );
54 is( $f5->data_type, 'VARCHAR', 'Data type is "VARCHAR"' );
55 is( $f5->size, 255, 'Size is "255"' );
56 is( $f5->is_primary_key, 0, 'Field is not PK' );
57
58 my $f6 = shift @fields;
59 is( $f6->name, 'today', 'Sixth field name is "today"' );
60 is( $f6->data_type, 'VARCHAR', 'Data type is "VARCHAR"' );
61 is( $f6->size, 255, 'Size is "255"' );
62 is( $f6->is_primary_key, 0, 'Field is not PK' );
63
64 my $f7 = shift @fields;
65 is( $f7->name, 'silly_field_with_random_characters', 
66     'Seventh field name is "silly_field_with_random_characters"' );
67 is( $f7->data_type, 'VARCHAR', 'Data type is "VARCHAR"' );
68 is( $f7->size, 255, 'Size is "255"' );
69 is( $f7->is_primary_key, 0, 'Field is not PK' );