5 # For now, all this is testing is that Parse::RecDescent does not
6 # die with an error! I am not verifying the validity of the data
7 # returned here, just that the parser actually completed its parsing!
12 use Test::More tests => 15;
14 use SQL::Translator::Parser::MySQL qw(parse);
17 my $tr = SQL::Translator->new;
18 my $data = q|create table sessions (
19 id char(32) not null primary key,
23 my $val = parse($tr, $data);
25 # $val holds the processed data structure.
27 # The data structure should have one key:
28 is(scalar keys %{$val}, 1);
30 # The data structure should have a single key, named sessions
31 ok(defined $val->{'sessions'});
33 # $val->{'sessions'} should have a single index (since we haven't
34 # defined an index, but have defined a primary key)
35 my $indices = $val->{'sessions'}->{'indices'};
36 is(scalar @{$indices || []}, 1, "correct index number");
38 is($indices->[0]->{'type'}, 'primary_key', "correct index type");
39 is($indices->[0]->{'fields'}->[0], 'id', "correct index name");
41 # $val->{'sessions'} should have two fields, id and a_sessionn
42 my $fields = $val->{'sessions'}->{'fields'};
43 is(scalar keys %{$fields}, 2, "correct fields number");
45 is($fields->{'id'}->{'data_type'}, 'char',
46 "correct field type: id (char)");
48 is ($fields->{'a_session'}->{'data_type'}, 'text',
49 "correct field type: a_session (text)");
51 is($fields->{'id'}->{'is_primary_key'}, 1,
52 "correct key identification (id == key)");
54 ok(! defined $fields->{'a_session'}->{'is_primary_key'},
55 "correct key identification (a_session != key)");
57 # Test that the order is being maintained by the internal order
59 my @order = sort { $fields->{$a}->{'order'}
61 $fields->{$b}->{'order'}
64 ok($order[0] eq 'id' && $order[1] eq 'a_session', "ordering of fields");
68 my $tr = SQL::Translator->new;
72 id int(7) unsigned zerofill NOT NULL default '0000000'
73 auto_increment primary key,
74 successful date NOT NULL default '0000-00-00',
75 unsuccessful date default '0000-00-00',
76 i1 int(11) default '0' not null,
77 s1 set('a','b','c') default 'b',
78 e1 enum('a','b','c') default 'c',
79 name varchar(30) default NULL,
80 foo_type enum('vk','ck') NOT NULL default 'vk',
82 time_stamp2 timestamp,
86 KEY name_idx (name(10))
87 ) TYPE=MyISAM PACK_KEYS=1;
91 is(scalar keys %{$data}, 1);
92 ok(defined $data->{'check'});
96 my $tr = SQL::Translator->new;
100 order_id int NOT NULL auto_increment,
101 member_id varchar(255),
102 billing_address_id int,
103 shipping_address_id int,
105 status smallint NOT NULL,
106 store_id varchar(255) NOT NULL REFERENCES store,
108 shipping_charge decimal(8,2),
109 price_paid decimal(8,2),
110 PRIMARY KEY (order_id),
112 KEY (billing_address_id),
113 KEY (shipping_address_id),
114 KEY (member_id, store_id),
115 FOREIGN KEY (status) REFERENCES order_status(id),
116 FOREIGN KEY (billing_address_id) REFERENCES address(address_id),
117 FOREIGN KEY (shipping_address_id) REFERENCES address(address_id)
122 is(scalar keys %{$data}, 1);
123 ok(defined $data->{'orders'});