Commits

Kirill Simonov  committed 1352982

Added tests for date functions.

  • Participants
  • Parent commits 6d65436

Comments (0)

Files changed (3)

File test/input/library.yaml

     ifdef: sqlite
   - uri: /{integer(string('cinq'))}
     expect: 409
+    ignore: true
     ifdef: pgsql
   # Integer overflow
   - uri: /{integer(4294967296.0)}
     expect: 409
+    ignore: true
     ifdef: pgsql
   - uri: /{integer(1.8446744073709552e+19)}
     expect: 409
+    ignore: true
     ifdef: pgsql
   - uri: /{integer(4294967296.0),
            integer(1.8446744073709552e+19)}
   # Integer overflow
   - uri: /{7*2147483647}
     expect: 409
+    ignore: true
     ifdef: pgsql
   - uri: /{9223372036854775807+1}
     expect: 409
+    ignore: true
     ifdef: pgsql
   - uri: /{7*2147483647, 9223372036854775807+1}
     ifdef: sqlite
   # Division by zero
   - uri: /{7/0}
     expect: 409
+    ignore: true
     ifdef: pgsql
   - uri: /{7/0.0}
     expect: 409
+    ignore: true
     ifdef: pgsql
   - uri: /{7/0e0}
     expect: 409
+    ignore: true
     ifdef: pgsql
   - uri: /{7/0, 7/0.0, 7/0e0}
     ifdef: sqlite
   - uri: /{string(true()), string(false())}
     skip: true
   - uri: /{string(60), string(2.125), string(-57721e-5)}
-  - uri: /{string(date(2010-04-15))}
+  - uri: /{string(date('2010-04-15'))}
     skip: true
 
   # Length
            replace('OMGWTFBBQ','WTF',null())
     skip: true
 
+########################################################################
+
+- title: Date Functions and Operators
+  tests:
+
+  # Conversion
+  - uri: /{date(null()), date('2010-04-15')}
+  # Incompatible operand
+  - uri: /{date('2010-13-07')}
+    expect: 400
+  - uri: /{date(true())}
+    expect: 400
+  - uri: /{date(7)}
+    expect: 400
+  # Not a date
+  - uri: /{date(string('birthday'))}
+    expect: 409
+    ignore: true
+    ifdef: pgsql
+  - uri: /{date(string('2010-13-07'))}
+    expect: 409
+    ignore: true
+    ifdef: pgsql
+  - uri: /{date(string('birthday')),
+           date(string('2010-13-07'))}
+    ifdef: sqlite
+
+  # Construction
+  - uri: /{today()}
+    ignore: true
+    skip: true
+  - uri: /{date(2010,4,15), date(2010,3,45), date(2011,-8,15)}
+    skip: true
+
+  # Components
+  - uri: /{year(date('2010-04-15')),
+           month(date('2010-04-15')),
+           day(date('2010-04-15'))}
+    skip: true
+
+  # Arithmetics
+  - uri: /{date('1991-08-20')+6813,
+           date('2010-04-15')-6813,
+           date('2010-04-15')-date('1991-08-20')}
+    skip: true
+
 
 
 # FIXME: update and refurbish!

File test/output/pgsql.yaml

             bind error: incompatible arguments:
                 /{string('LOL')+7}
                   ^^^^^^^^^^^^^^^
+      - id: date-functions-and-operators
+        tests:
+        - uri: /{date(null()), date('2010-04-15')}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                                   |
+            -+-----------------------------------+-
+             | date(null()) | date('2010-04-15') |
+            -+--------------+--------------------+-
+             |              | 2010-04-15         |
+                                           (1 row)
+
+             ----
+             /{date(null()),date('2010-04-15')}
+             SELECT NULL,
+                    '2010-04-15'::DATE
+        - uri: /{date('2010-13-07')}
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            encode error: invalid date literal: month must be in 1..12:
+                /{date('2010-13-07')}
+                  ^^^^^^^^^^^^^^^^^^
+        - uri: /{date(true())}
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            encode error: inadmissible conversion:
+                /{date(true())}
+                  ^^^^^^^^^^^^
+        - uri: /{date(7)}
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            encode error: inadmissible conversion:
+                /{date(7)}
+                  ^^^^^^^
+        - uri: /{date(string('birthday'))}
+          status: 409 Conflict
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            engine failure: error while executing "SELECT CAST('birthday' AS DATE)\n": invalid input syntax for type date: "birthday"
+            LINE 1: SELECT CAST('birthday' AS DATE)
+                                ^
+            :
+                /{date(string('birthday'))}
+                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+        - uri: /{date(string('2010-13-07'))}
+          status: 409 Conflict
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            engine failure: error while executing "SELECT CAST('2010-13-07' AS DATE)\n": date/time field value out of range: "2010-13-07"
+            LINE 1: SELECT CAST('2010-13-07' AS DATE)
+                                ^
+            HINT:  Perhaps you need a different "datestyle" setting.
+            :
+                /{date(string('2010-13-07'))}
+                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       - id: scalar-functions
         tests:
         - id: boolean-constants-and-logical-operators

File test/output/sqlite.yaml

             bind error: incompatible arguments:
                 /{string('LOL')+7}
                   ^^^^^^^^^^^^^^^
+      - id: date-functions-and-operators
+        tests:
+        - uri: /{date(null()), date('2010-04-15')}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                                   |
+            -+-----------------------------------+-
+             | date(null()) | date('2010-04-15') |
+            -+--------------+--------------------+-
+             |              | 2010-04-15         |
+                                           (1 row)
+
+             ----
+             /{date(null()),date('2010-04-15')}
+             SELECT NULL,
+                    '2010-04-15'
+        - uri: /{date('2010-13-07')}
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            encode error: invalid date literal: month must be in 1..12:
+                /{date('2010-13-07')}
+                  ^^^^^^^^^^^^^^^^^^
+        - uri: /{date(true())}
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            encode error: inadmissible conversion:
+                /{date(true())}
+                  ^^^^^^^^^^^^
+        - uri: /{date(7)}
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            encode error: inadmissible conversion:
+                /{date(7)}
+                  ^^^^^^^
+        - uri: /{date(string('birthday')), date(string('2010-13-07'))}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                                                       |
+            -+-------------------------------------------------------+-
+             | date(string('birthday')) | date(string('2010-13-07')) |
+            -+--------------------------+----------------------------+-
+             |                          |                            |
+                                                               (1 row)
+
+             ----
+             /{date(string('birthday')),date(string('2010-13-07'))}
+             SELECT DATE('birthday'),
+                    DATE('2010-13-07')
   - include: test/input/translation.yaml
     output:
       id: translation