From c6e9b55361558f703a86e31d528217027be8a9cf Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 27 Sep 2008 14:25:36 -0500 Subject: [PATCH] clean up tests a bit, better error handling --- basis/db/tuples/tuples-tests.factor | 37 +++++++++++++++++++---------- basis/db/types/types.factor | 7 ++++-- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/basis/db/tuples/tuples-tests.factor b/basis/db/tuples/tuples-tests.factor index 85a3b73264..ddaee012a5 100755 --- a/basis/db/tuples/tuples-tests.factor +++ b/basis/db/tuples/tuples-tests.factor @@ -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 diff --git a/basis/db/types/types.factor b/basis/db/types/types.factor index 5ead216174..0563b677e8 100755 --- a/basis/db/types/types.factor +++ b/basis/db/types/types.factor @@ -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 ;