File: simple-date-tests.lisp

package info (click to toggle)
cl-postmodern 20211113.git9d4332f-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,528 kB
  • sloc: lisp: 22,909; sql: 76; makefile: 2
file content (63 lines) | stat: -rw-r--r-- 2,676 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;;;; -*- Mode: LISP; Syntax: Ansi-Common-Lisp; Base: 10; Package: CL-POSTGRES-SIMPLE-DATE-TESTS; -*-
(defpackage :cl-postgres-simple-date-tests
  (:use :common-lisp :fiveam :cl-postgres :cl-postgres-error :simple-date)
  (:import-from #:cl-postgres-tests
                #:prompt-connection))

(in-package :cl-postgres-simple-date-tests)

(defmacro with-simple-date-readtable (&body body)
  `(let ((*sql-readtable* (simple-date-cl-postgres-glue:simple-date-sql-readtable)))
    ,@body))

(defmacro with-test-connection (&body body)
  `(let ((connection (apply 'open-database (prompt-connection))))
     (with-simple-date-readtable
       (unwind-protect (progn ,@body)
         (close-database connection)))))

(def-suite :cl-postgres-simple-date)
(in-suite :cl-postgres-simple-date)

(test row-timestamp-without-time-zone-binary
  (with-test-connection
    (with-binary-row-values
      (is (time= (caaar (exec-query connection "select row('2010-04-05 14:42:21.500'::timestamp without time zone)"
                                    'list-row-reader))
                 (encode-timestamp 2010 4 5 14 42 21 500))))))

(test row-timestamp-with-time-zone-binary
  (with-test-connection
    (exec-query connection "set time zone 'GMT'")
    (with-binary-row-values
      (destructuring-bind (gmt pdt)
          (caar
           (exec-query
            connection
            (concatenate 'string
                         "select row('2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'GMT', "
                         " '2010-04-05 14:42:21.500'::timestamp with time zone at time zone 'PST')")
            'list-row-reader))
        (is (time= gmt (encode-timestamp 2010 4 5 14 42 21 500)))
        (is (time= pdt (encode-timestamp 2010 4 5 6 42 21 500)))))))

(test row-timestamp-without-time-zone-array-binary
  (with-test-connection
    (with-binary-row-values
      (is (time= (elt (caaar (exec-query connection "select row(ARRAY['2010-04-05 14:42:21.500'::timestamp without time zone])"
                                         'list-row-reader)) 0)
                 (encode-timestamp 2010 4 5 14 42 21 500))))))

(test row-time-binary
  (with-test-connection
    (with-binary-row-values
      (is (time= (caaar (exec-query connection "select row('05:00'::time)"
                                    'list-row-reader))
                 (encode-time-of-day 5 0))))))

(test row-timestamp-binary
  (with-test-connection
    (with-binary-row-values
      (is (time= (caaar (exec-query connection "select row('2010-04-05 14:42:21.500'::timestamp)"
                                    'list-row-reader))
                 (encode-timestamp 2010 4 5 14 42 21 500))))))