2 (defpackage :cl-postgres-simple-date-tests
3 (:use
:common-lisp
:fiveam
:cl-postgres
:cl-postgres-error
:simple-date
)
4 (:export
#:prompt-connection
#:*test-connection
*))
6 (in-package :cl-postgres-simple-date-tests
)
8 (defparameter *test-connection
* '("test" "test" "" "localhost"))
10 (defun prompt-connection (&optional
(list *test-connection
*))
11 (flet ((ask (name pos
)
12 (format *query-io
* "~a (enter to keep '~a'): " name
(nth pos list
))
13 (finish-output *query-io
*)
14 (let ((answer (read-line *query-io
*)))
15 (unless (string= answer
"") (setf (nth pos list
) answer
)))))
16 (format *query-io
* "~%To run this test, you must configure a database connection.~%")
17 (ask "Database name" 0)
22 (defmacro with-simple-date-readtable
(&body body
)
23 `(let ((*sql-readtable
* (simple-date-cl-postgres-glue:simple-date-sql-readtable
)))
26 (defmacro with-test-connection
(&body body
)
27 `(let ((connection (apply 'open-database
*test-connection
*)))
28 (with-simple-date-readtable
29 (unwind-protect (progn ,@body
)
30 (close-database connection
)))))
32 (def-suite :cl-postgres-simple-date
)
33 (in-suite :cl-postgres-simple-date
)
35 (test row-timestamp-without-time-zone-binary
37 (with-binary-row-values
38 (is (time= (caaar (exec-query connection
"select row('2010-04-05 14:42:21.500'::timestamp without time zone)"
40 (encode-timestamp 2010 4 5 14 42 21 500))))))
42 (test row-timestamp-with-time-zone-binary
44 (exec-query connection
"set time zone 'GMT'")
45 (with-binary-row-values
46 (destructuring-bind (gmt pdt
)
51 "select row('2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'GMT', "
52 " '2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'PST')")
54 (is (time= gmt
(encode-timestamp 2010 4 5 14 42 21 500)))
55 (is (time= pdt
(encode-timestamp 2010 4 5 6 42 21 500)))))))
57 (test row-timestamp-without-time-zone-array-binary
59 (with-binary-row-values
60 (is (time= (elt (caaar (exec-query connection
"select row(ARRAY['2010-04-05 14:42:21.500'::timestamp without time zone])"
62 (encode-timestamp 2010 4 5 14 42 21 500))))))
66 (with-binary-row-values
67 (is (time= (caaar (exec-query connection
"select row('05:00'::time)"
69 (encode-time-of-day 5 0))))))
71 (test row-timestamp-binary
73 (with-binary-row-values
74 (is (time= (caaar (exec-query connection
"select row('2010-04-05 14:42:21.500'::timestamp)"
76 (encode-timestamp 2010 4 5 14 42 21 500))))))