Making a more thorough check of things.
Ken Youens-Clark [Thu, 6 Nov 2003 19:17:34 +0000 (19:17 +0000)]
t/24yaml.t

index 4df9fd6..335397d 100644 (file)
@@ -5,70 +5,167 @@ use strict;
 use Test::More tests => 2;
 use Test::Differences;
 use SQL::Translator;
+use FindBin '$Bin';
 
-my $create = q|
-CREATE TABLE random (
-    id int auto_increment PRIMARY KEY,
-    foo varchar(255) not null default '',
-    updated timestamp
-);
-|;
-
-my $yaml = q|--- #YAML:1.0
+my $yaml = q/--- #YAML:1.0
 schema:
   procedures: {}
   tables:
-    random:
+    person:
       comments: ''
       fields:
-        foo:
+        age:
+          data_type: integer
+          default_value: ~
+          extra: {}
+          is_nullable: 1
+          is_primary_key: 0
+          is_unique: 0
+          name: age
+          order: 3
+          size:
+            - 0
+        description:
+          data_type: text
+          default_value: ~
+          extra: {}
+          is_nullable: 1
+          is_primary_key: 0
+          is_unique: 0
+          name: description
+          order: 6
+          size:
+            - 0
+        iq:
+          data_type: tinyint
+          default_value: 0
+          extra: {}
+          is_nullable: 1
+          is_primary_key: 0
+          is_unique: 0
+          name: iq
+          order: 5
+          size:
+            - 0
+        name:
           data_type: varchar
-          default_value: ''
+          default_value: ~
           extra: {}
           is_nullable: 0
           is_primary_key: 0
-          is_unique: 0
-          name: foo
+          is_unique: 1
+          name: name
           order: 2
           size:
-            - 255
-        id:
-          data_type: int
+            - 20
+        person_id:
+          data_type: INTEGER
           default_value: ~
           extra: {}
           is_nullable: 0
           is_primary_key: 1
           is_unique: 0
-          name: id
+          name: person_id
           order: 1
           size:
+            - 0
+        weight:
+          data_type: double
+          default_value: ~
+          extra: {}
+          is_nullable: 1
+          is_primary_key: 0
+          is_unique: 0
+          name: weight
+          order: 4
+          size:
             - 11
-        updated:
-          data_type: timestamp
+            - 2
+      indices: {}
+      name: person
+      options: []
+      order: 1
+    pet:
+      comments: ''
+      fields:
+        age:
+          data_type: int
           default_value: ~
           extra: {}
           is_nullable: 1
           is_primary_key: 0
           is_unique: 0
-          name: updated
-          order: 3
+          name: age
+          order: 10
+          size:
+            - 0
+        name:
+          data_type: varchar
+          default_value: ~
+          extra: {}
+          is_nullable: 1
+          is_primary_key: 0
+          is_unique: 0
+          name: name
+          order: 9
+          size:
+            - 30
+        person_id:
+          data_type: int
+          default_value: ~
+          extra: {}
+          is_nullable: 0
+          is_primary_key: 1
+          is_unique: 0
+          name: person_id
+          order: 8
+          size:
+            - 0
+        pet_id:
+          data_type: int
+          default_value: ~
+          extra: {}
+          is_nullable: 0
+          is_primary_key: 1
+          is_unique: 0
+          name: pet_id
+          order: 7
           size:
             - 0
       indices: {}
-      name: random
+      name: pet
       options: []
+      order: 2
+  triggers:
+    after:
+      action:
+        for_each: ~
+        steps:
+          - update name=name
+        when: ~
+      database_event: insert
+      fields: ~
+      name: after
+      on_table: ~
+      order: 1
+      perform_action_when: ~
+  views:
+    person_pet:
+      fields: ~
+      name: person_pet
       order: 1
-  triggers: {}
-  views: {}
-|;
+      sql: |
+        select pr.person_id, pr.name as person_name, pt.name as pet_name
+          from   person pr, pet pt
+          where  person.person_id=pet.pet_id
+/;
 
-my $out;
 my $tr = SQL::Translator->new(
-    parser   => "MySQL",
-    producer => "YAML"
+    parser   => 'SQLite',
+    producer => 'YAML',
+    filename => "$Bin/data/sqlite/create.sql",
 );
 
-
-ok($out = $tr->translate(\$create), 'Translate MySQL to YAML');
-eq_or_diff($out, $yaml, 'YAML matches expected');
-
+my $out;
+ok( $out = $tr->translate, 'Translate SQLite to YAML' );
+eq_or_diff( $out, $yaml, 'YAML matches expected' );