X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F48xml-to-sqlite.t;h=4dd1da7debb70d0e9345d83cd0c4f9f699390e1d;hb=ee91ab6f05e09efae723b85bb50e71aab15869e2;hp=53f37dbab6b6b2a918877f220c4e96a7ddd290ee;hpb=b08b5416f45bfbe381637ee3091202524c78ecab;p=dbsrgits%2FSQL-Translator.git diff --git a/t/48xml-to-sqlite.t b/t/48xml-to-sqlite.t index 53f37db..4dd1da7 100644 --- a/t/48xml-to-sqlite.t +++ b/t/48xml-to-sqlite.t @@ -5,13 +5,14 @@ use FindBin qw/$Bin/; use Test::More; use Test::SQL::Translator; use Test::Exception; +use Test::Differences; use Data::Dumper; use SQL::Translator; use SQL::Translator::Schema::Constants; BEGIN { - maybe_plan(1, 'SQL::Translator::Parser::XML::SQLFairy', + maybe_plan(2, 'SQL::Translator::Parser::XML::SQLFairy', 'SQL::Translator::Producer::SQLite'); } @@ -20,7 +21,7 @@ my $xmlfile = "$Bin/data/xml/schema.xml"; my $sqlt; $sqlt = SQL::Translator->new( no_comments => 1, - show_warnings => 1, + show_warnings => 0, add_drop_table => 1, ); @@ -32,13 +33,13 @@ my $sql = $sqlt->translate( filename => $xmlfile, ) or die $sqlt->error; -# print ">>$sql<<\n"; +eq_or_diff($sql, << "SQL"); -is($sql, << "SQL"); -BEGIN TRANSACTION; +BEGIN TRANSACTION; DROP TABLE Basic; + CREATE TABLE Basic ( id INTEGER PRIMARY KEY NOT NULL, title varchar(100) NOT NULL DEFAULT 'hello', @@ -52,14 +53,62 @@ CREATE TABLE Basic ( timest timestamp ); -CREATE INDEX titleindex_Basic on Basic (title); -CREATE UNIQUE INDEX emailuniqueindex_Basic on Basic (email); +CREATE INDEX titleindex_Basic ON Basic (title); + +CREATE UNIQUE INDEX emailuniqueindex_Basic ON Basic (email); DROP TABLE Another; + CREATE TABLE Another ( id INTEGER PRIMARY KEY NOT NULL ); +DROP VIEW IF EXISTS email_list; +CREATE VIEW email_list AS + SELECT email FROM Basic WHERE email IS NOT NULL; + +DROP TRIGGER IF EXISTS foo_trigger; + +CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END; COMMIT; SQL + +# Test in list context +my @sql = $sqlt->translate( + from => 'XML-SQLFairy', + to => 'SQLite', + filename => $xmlfile, +) or die $sqlt->error; + +eq_or_diff(\@sql, + [ + "\n\nBEGIN TRANSACTION", + 'DROP TABLE Basic', + 'CREATE TABLE Basic ( + id INTEGER PRIMARY KEY NOT NULL, + title varchar(100) NOT NULL DEFAULT \'hello\', + description text DEFAULT \'\', + email varchar(255), + explicitnulldef varchar, + explicitemptystring varchar DEFAULT \'\', + -- Hello emptytagdef + emptytagdef varchar DEFAULT \'\', + another_id int(10) DEFAULT \'2\', + timest timestamp +)', + 'CREATE INDEX titleindex_Basic02 ON Basic (title)', + 'CREATE UNIQUE INDEX emailuniqueindex_Basic02 ON Basic (email)', + 'DROP TABLE Another', + 'CREATE TABLE Another ( + id INTEGER PRIMARY KEY NOT NULL +)', + 'DROP VIEW IF EXISTS email_list; +CREATE VIEW email_list AS + SELECT email FROM Basic WHERE email IS NOT NULL', + 'DROP TRIGGER IF EXISTS foo_trigger', + 'CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END', + 'COMMIT' + ], 'SQLite translate in list context matches'); + +