Commits

Kirill Simonov committed 6d65436

Added tests for string functions.

  • Participants
  • Parent commits 6a46eb2

Comments (0)

Files changed (3)

test/input/library.yaml

 
 ########################################################################
 
+- title: String Functions and Operators
+  tests:
+
+  # Conversion
+  - uri: /{string(null()), string('OMGWTFBBQ')}
+  - uri: /{string(true()), string(false())}
+    skip: true
+  - uri: /{string(60), string(2.125), string(-57721e-5)}
+  - uri: /{string(date(2010-04-15))}
+    skip: true
+
+  # Length
+  - uri: /{length(''), length('OMGWTFBBQ')}
+    skip: true
+  - uri: /{length(null())}
+    skip: true
+  # Incompatible operand
+  - uri: /{length(date(2010-04-15))}
+    expect: 400
+
+  # Concatenation
+  - uri: /{'OMG'+'WTF'+'BBQ'}
+  - uri: /{null()+'LOL', 'LOL'+null(),
+           string(null())+string(null())}
+  # Incompatible operands
+  - uri: /{string('LOL')+7}
+    expect: 400
+
+  # Contains
+  - uri: /{'OMGWTFBBQ'~'wtf', 'OMGWTFBBQ'!~'LOL'}
+    skip: true
+  - uri: /{'OMGWTFBBQ'!~'wtf', 'OMGWTFBBQ'~'LOL'}
+    skip: true
+  - uri: /{null()~'LOL', 'LOL'~null(), null()~null()}
+    skip: true
+
+  # Slicing
+  - uri: /{head('OMGWTFBBQ'), head('OMGWTFBBQ',3), head('OMGWTFBBQ',-3)}
+    skip: true
+  - uri: /{tail('OMGWTFBBQ'), tail('OMGWTFBBQ',3), tail('OMGWTFBBQ',-3)}
+    skip: true
+  - uri: /{head('OMGWTFBBQ',0), tail('OMGWTFBBQ',0)}
+    skip: true
+  - uri: /{head(null()), tail(null())}
+    skip: true
+  - uri: /{slice('OMGWTFBBQ',3,6), slice('OMGWTFBBQ',3,-3),
+           slice('OMGWTFBBQ',-6,6), slice('OMGWTFBBQ',-6,-3)}
+    skip: true
+  - uri: /{slice('OMGWTFBBQ',0,0), slice('OMGWTFBBQ',6,3),
+           slice('OMGWTFBBQ',10,13), slice('OMGWTFBBQ',-3,-6)}
+    skip: true
+  - uri: /{slice(null(),3,-3), slice('OMGWTGBBQ',null(),null())}
+    skip: true
+  - uri: /{at('OMGWTFBBQ',0), at('OMGWTFBBQ',3), at('OMGWTFBBQ',-3)}
+    skip: true
+  - uri: /{at('OMGWTFBBQ',3,3), at('OMGWTFBBQ',3,0), at('OMGWTFBBQ',3,-3)}
+    skip: true
+  - uri: /{at('OMGWTFBBQ',10), at('OMGWTFBBQ',0,-3)}
+    skip: true
+  - uri: /{at(null(),3), at('OMGWTFBBQ',null(),3), at('OMGWTFBBQ',3,null())}
+    skip: true
+
+  # Transformations
+  - uri: /{upper('lol'), lower('LOL')}
+    skip: true
+  - uri: /{trim('  LOL  '), ltrim('  LOL  '), rtrim('  LOL  ')}
+    skip: true
+  - uri: /{replace('OMGWTFBBQ','WTF','LOL')}
+    skip: true
+  - uri: /{replace('OMGWTFBBQ','wtf','LOL'),
+           replace('OMGWTFBBQ','WTF','lol')}
+    skip: true
+  - uri: /{replace('floccinaucinihilipilification','ili','LOL')}
+    skip: true
+  - uri: /{replace('OMGWTFBBQ','','LOL'),
+           replace('OMGWTFBBQ','WTF','')}
+    skip: true
+  - uri: /{replace(null(),'WTF','LOL'),
+           replace('OMGWTFBBQ',null(),'LOL'),
+           replace('OMGWTFBBQ','WTF',null())
+    skip: true
+
 
 
 # FIXME: update and refurbish!

test/output/pgsql.yaml

             bind error: incompatible arguments:
                 /{round(271828e-5,2)}
                   ^^^^^^^^^^^^^^^^^^
+      - id: string-functions-and-operators
+        tests:
+        - uri: /{string(null()), string('OMGWTFBBQ')}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                                      |
+            -+--------------------------------------+-
+             | string(null()) | string('OMGWTFBBQ') |
+            -+----------------+---------------------+-
+             |                | OMGWTFBBQ           |
+                                              (1 row)
+
+             ----
+             /{string(null()),string('OMGWTFBBQ')}
+             SELECT NULL,
+                    'OMGWTFBBQ'
+        - uri: /{string(60), string(2.125), string(-57721e-5)}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                                                |
+            -+------------------------------------------------+-
+             | string(60) | string(2.125) | string(-57721e-5) |
+            -+------------+---------------+-------------------+-
+             | 60         | 2.125         | -0.57721          |
+                                                        (1 row)
+
+             ----
+             /{string(60),string(2.125),string(-57721e-5)}
+             SELECT CAST(60 AS TEXT),
+                    CAST(2.125::NUMERIC AS TEXT),
+                    CAST((- 0.57721::FLOAT8) AS TEXT)
+        - uri: /{length(''), length('OMGWTFBBQ')}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                                  |
+            -+----------------------------------+-
+             | length('') | length('OMGWTFBBQ') |
+            -+------------+---------------------+-
+             |          0 |                   9 |
+                                          (1 row)
+
+             ----
+             /{length(''),length('OMGWTFBBQ')}
+             SELECT CHARACTER_LENGTH(''),
+                    CHARACTER_LENGTH('OMGWTFBBQ')
+        - uri: /{length(null())}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                |
+            -+----------------+-
+             | length(null()) |
+            -+----------------+-
+             |                |
+                        (1 row)
+
+             ----
+             /{length(null())}
+             SELECT CHARACTER_LENGTH(NULL)
+        - uri: /{length(date(2010-04-15))}
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            bind error: incompatible arguments:
+                /{length(date(2010-04-15))}
+                  ^^^^^^^^^^^^^^^^^^^^^^^^
+        - uri: /{'OMG'+'WTF'+'BBQ'}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                   |
+            -+-------------------+-
+             | 'OMG'+'WTF'+'BBQ' |
+            -+-------------------+-
+             | OMGWTFBBQ         |
+                           (1 row)
+
+             ----
+             /{'OMG'+'WTF'+'BBQ'}
+             SELECT (('OMG' || 'WTF') || 'BBQ')
+        - uri: /{null()+'LOL', 'LOL'+null(), string(null())+string(null())}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                                                             |
+            -+-------------------------------------------------------------+-
+             | null()+'LOL' | 'LOL'+null() | string(null())+string(null()) |
+            -+--------------+--------------+-------------------------------+-
+             | LOL          | LOL          | ""                            |
+                                                                     (1 row)
+
+             ----
+             /{null()+'LOL','LOL'+null(),string(null())+string(null())}
+             SELECT ('' || 'LOL'),
+                    ('LOL' || ''),
+                    ('' || '')
+        - uri: /{string('LOL')+7}
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            bind error: incompatible arguments:
+                /{string('LOL')+7}
+                  ^^^^^^^^^^^^^^^
       - id: scalar-functions
         tests:
         - id: boolean-constants-and-logical-operators

test/output/sqlite.yaml

              ----
              /{round(9973)}
              SELECT ROUND(9973.0)
+      - id: string-functions-and-operators
+        tests:
+        - uri: /{string(null()), string('OMGWTFBBQ')}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                                      |
+            -+--------------------------------------+-
+             | string(null()) | string('OMGWTFBBQ') |
+            -+----------------+---------------------+-
+             |                | OMGWTFBBQ           |
+                                              (1 row)
+
+             ----
+             /{string(null()),string('OMGWTFBBQ')}
+             SELECT NULL,
+                    'OMGWTFBBQ'
+        - uri: /{string(60), string(2.125), string(-57721e-5)}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                                                |
+            -+------------------------------------------------+-
+             | string(60) | string(2.125) | string(-57721e-5) |
+            -+------------+---------------+-------------------+-
+             | 60         | 2.125         | -0.57721          |
+                                                        (1 row)
+
+             ----
+             /{string(60),string(2.125),string(-57721e-5)}
+             SELECT CAST(60 AS TEXT),
+                    CAST(2.125 AS TEXT),
+                    CAST((- 0.57721) AS TEXT)
+        - uri: /{length(date(2010-04-15))}
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            bind error: incompatible arguments:
+                /{length(date(2010-04-15))}
+                  ^^^^^^^^^^^^^^^^^^^^^^^^
+        - uri: /{'OMG'+'WTF'+'BBQ'}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                   |
+            -+-------------------+-
+             | 'OMG'+'WTF'+'BBQ' |
+            -+-------------------+-
+             | OMGWTFBBQ         |
+                           (1 row)
+
+             ----
+             /{'OMG'+'WTF'+'BBQ'}
+             SELECT (('OMG' || 'WTF') || 'BBQ')
+        - uri: /{null()+'LOL', 'LOL'+null(), string(null())+string(null())}
+          status: 200 OK
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |2
+             |                                                             |
+            -+-------------------------------------------------------------+-
+             | null()+'LOL' | 'LOL'+null() | string(null())+string(null()) |
+            -+--------------+--------------+-------------------------------+-
+             | LOL          | LOL          | ""                            |
+                                                                     (1 row)
+
+             ----
+             /{null()+'LOL','LOL'+null(),string(null())+string(null())}
+             SELECT ('' || 'LOL'),
+                    ('LOL' || ''),
+                    ('' || '')
+        - uri: /{string('LOL')+7}
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            bind error: incompatible arguments:
+                /{string('LOL')+7}
+                  ^^^^^^^^^^^^^^^
   - include: test/input/translation.yaml
     output:
       id: translation