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-test-connection
(&body body
)
23 `(let ((connection (apply 'open-database
*test-connection
*)))
24 (unwind-protect (progn ,@body
)
25 (close-database connection
))))
26 (def-suite :cl-postgres-simple-date
)
27 (in-suite :cl-postgres-simple-date
)
29 (test row-timestamp-without-time-zone-binary
31 (with-binary-row-values
32 (is (time= (caaar (exec-query connection
"select row('2010-04-05 14:42:21.500'::timestamp without time zone)"
34 (encode-timestamp 2010 4 5 14 42 21 500))))))
36 (test row-timestamp-with-time-zone-binary
38 (exec-query connection
"set time zone 'GMT'")
39 (with-binary-row-values
40 (destructuring-bind (gmt pdt
)
45 "select row('2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'GMT', "
46 " '2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'PST')")
48 (is (time= gmt
(encode-timestamp 2010 4 5 14 42 21 500)))
49 (is (time= pdt
(encode-timestamp 2010 4 5 6 42 21 500)))))))
51 (test row-timestamp-without-time-zone-array-binary
53 (with-binary-row-values
54 (is (time= (elt (caaar (exec-query connection
"select row(ARRAY['2010-04-05 14:42:21.500'::timestamp without time zone])"
56 (encode-timestamp 2010 4 5 14 42 21 500))))))
60 (with-binary-row-values
61 (is (time= (caaar (exec-query connection
"select row('05:00'::time)"
63 (encode-time-of-day 5 0))))))
65 (test row-timestamp-binary
67 (with-binary-row-values
68 (is (time= (caaar (exec-query connection
"select row('2010-04-05 14:42:21.500'::timestamp)"
70 (encode-timestamp 2010 4 5 14 42 21 500))))))