]> gitweb.factorcode.org Git - factor.git/commitdiff
clean up tests a bit, better error handling
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 27 Sep 2008 19:25:36 +0000 (14:25 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 27 Sep 2008 19:25:36 +0000 (14:25 -0500)
basis/db/tuples/tuples-tests.factor
basis/db/types/types.factor

index 85a3b73264b9b00a36616224e3f631d7a41067df..ddaee012a57503e99e166ef996473dfc18d9b6f7 100755 (executable)
@@ -7,6 +7,17 @@ db.postgresql accessors random math.bitwise
 math.ranges strings urls fry db.tuples.private ;
 IN: db.tuples.tests
 
+: test-sqlite ( quot -- )
+    [ ] swap '[
+        "tuples-test.db" temp-file sqlite-db _ with-db
+    ] unit-test ;
+
+: test-postgresql ( quot -- )
+    [ ] swap '[
+        { "localhost" "postgres" "foob" "factor-test" }
+        postgresql-db _ with-db
+    ] unit-test ;
+
 TUPLE: person the-id the-name the-number the-real
 ts date time blob factor-blob url ;
 
@@ -177,7 +188,7 @@ TUPLE: annotation n paste-id summary author mode contents ;
         { "channel" "CHANNEL" TEXT }
         { "mode" "MODE" TEXT }
         { "contents" "CONTENTS" TEXT }
-        { "date" "DATE" TIMESTAMP }
+        { "timestamp" "DATE" TIMESTAMP }
         { "annotations" { +has-many+ annotation } }
     } define-persistent
 
@@ -191,20 +202,20 @@ TUPLE: annotation n paste-id summary author mode contents ;
         { "contents" "CONTENTS" TEXT }
     } define-persistent ;
 
-! { "localhost" "postgres" "" "factor-test" } postgresql-db [
-    ! [ paste drop-table ] [ drop ] recover
-    ! [ annotation drop-table ] [ drop ] recover
-    ! [ paste drop-table ] [ drop ] recover
-    ! [ annotation drop-table ] [ drop ] recover
-    ! [ ] [ paste create-table ] unit-test
-    ! [ ] [ annotation create-table ] unit-test
-! ] with-db
+: test-paste-schema ( -- )
+    [ ] [ db-assigned-paste-schema ] unit-test
+    [ ] [ paste ensure-table ] unit-test
+    [ ] [ annotation ensure-table ] unit-test
+    [ ] [ annotation drop-table ] unit-test
+    [ ] [ paste drop-table ] unit-test
+    [ ] [ paste create-table ] unit-test
+    [ ] [ annotation create-table ] unit-test
 
-: test-sqlite ( quot -- )
-    [ ] swap '[ "tuples-test.db" temp-file sqlite-db _ with-db ] unit-test ;
+    ;
+
+! [ test-paste-schema ] test-sqlite
+! [ test-paste-schema ] test-postgresql
 
-: test-postgresql ( quot -- )
-    [ ] swap '[ { "localhost" "postgres" "foob" "factor-test" } postgresql-db _ with-db ] unit-test ;
 
 : test-repeated-insert
     [ ] [ person ensure-table ] unit-test
index 5ead216174b69c672563995f7e420df3d6ecf8c4..0563b677e8cb5ef748dfde75e97f9ac431ae6f38 100755 (executable)
@@ -116,12 +116,15 @@ FACTOR-BLOB NULL URL ;
 ! PostgreSQL Types:
 ! http://developer.postgresql.org/pgdocs/postgres/datatype.html
 
-ERROR: unknown-modifier ;
+ERROR: unknown-modifier modifier ;
+
+: ?at ( obj assoc -- value/obj ? )
+    dupd at* [ [ nip ] [ drop ] if ] keep ;
 
 : lookup-modifier ( obj -- string )
     {
         { [ dup array? ] [ unclip lookup-modifier swap compound ] }
-        [ persistent-table at* [ unknown-modifier ] unless third ]
+        [ persistent-table ?at [ unknown-modifier ] unless third ]
     } cond ;
 
 ERROR: no-sql-type ;