r9289: Added new operations for the sql syntax.
[clsql.git] / tests / test-syntax.lisp
index 9de62fe762a9b27adec21395b23091589d2fc73f..ac8247ef45d903e4aa90938d310d94ae1a21a0cf 100644 (file)
     (clsql:sql ["foo" bar :integer])
   "FOO.BAR")
 
-(deftest :syntax/value/1
+
+(deftest :syntax/subquery/1
     (clsql:sql [any '(3 4)])
   "(ANY ((3,4)))")
 
-(deftest :syntax/value/2
-    (clsql:sql [* 2 3])
-  "(2 * 3)")
+(deftest :syntax/subquery/2
+    (clsql:sql [in [foo] '(foo bar baz)])
+  "(FOO IN (FOO,BAR,BAZ))")
+
+(deftest :syntax/subquery/3
+    (clsql:sql [all '(foo bar baz)])
+  "(ALL ((FOO,BAR,BAZ)))")
+
+(deftest :syntax/subquery/4
+    (clsql:sql [exists '(foo bar baz)])
+  "(EXISTS ((FOO,BAR,BAZ)))")
+
+(deftest :syntax/subquery/5
+    (clsql:sql [some '(foo bar baz)])
+  "(SOME ((FOO,BAR,BAZ)))")
+
+
+(deftest :syntax/aggregate/1 
+    (clsql:sql [max [+ [foo] [* 1000 [bar]]]])
+ "MAX((FOO + (1000 * BAR)))")
+
+(deftest :syntax/aggregate/2
+    (clsql:sql [avg [+ [foo] [* 1000 [bar]]]])
+ "AVG((FOO + (1000 * BAR)))")
+
+(deftest :syntax/aggregate/3
+    (clsql:sql [min [+ [foo] [* 1000 [bar]]]])
+ "MIN((FOO + (1000 * BAR)))")
+
+(deftest :syntax/aggregate/4
+    (clsql:sql [sum [foo] [bar]])
+ "SUM(FOO,BAR)")
+
+(deftest :syntax/aggregate/5
+    (clsql:sql [count [foo]])
+ "COUNT(FOO)")
+
+
+(deftest :syntax/logical/1 
+    (clsql:sql [and [foo] [bar]])
+  "(FOO AND BAR)")
+
+(deftest :syntax/logical/2
+    (clsql:sql [or [foo] [bar]])
+  "(FOO OR BAR)")
+
+(deftest :syntax/logical/3 
+    (clsql:sql [not [foo]])
+  "(NOT (FOO))")
+
+
+(deftest :syntax/null/1 
+    (clsql:sql [null [foo]])
+  "(FOO IS NULL)")
+
+(deftest :syntax/null/2
+    (clsql:sql [not [null [foo]]])
+  "(NOT ((FOO IS NULL)))")
+(deftest :syntax/null/3
+    (clsql:sql [null])
+  "NULL")
+
+(deftest :syntax/null/4
+    (clsql:sql [not [null]])
+  "(NOT (NULL))")
+
 
 
 (deftest :syntax/relational/1
       (clsql:sql [> [foo] x]))
   "(FOO > 10)")
 
+(deftest :syntax/relational/3
+    (clsql:sql [>= [baz] [beep]])
+  "(BAZ >= BEEP)")
+
+(deftest :syntax/relational/4
+    (clsql:sql [< [baz] [beep]])
+  "(BAZ < BEEP)")
+
+(deftest :syntax/relational/5
+    (clsql:sql [= [baz] [beep]])
+  "(BAZ = BEEP)")
+
+(deftest :syntax/relational/6
+    (clsql:sql [<> [baz] [beep]])
+  "(BAZ <> BEEP)")
+
+
+(deftest :syntax/between/1 
+    (clsql:sql [between [- [foo] 1] [* [bar] 5] [/ [baz] 9]])
+  "(FOO - 1) BETWEEN (BAR * 5) AND (BAZ / 9)")
+
+(deftest :syntax/between/2 
+    (clsql:sql [not [between [- [foo] 1] [* [bar] 5] [/ [baz] 9]]])
+  "(NOT ((FOO - 1) BETWEEN (BAR * 5) AND (BAZ / 9)))")
+
+
+(deftest :syntax/arithmetic/1 
+    (clsql:sql [+ [foo bar] [baz]])
+ "(FOO.BAR + BAZ)")
+
+(deftest :syntax/arithmetic/2
+    (clsql:sql [- [foo bar] [baz]])
+ "(FOO.BAR - BAZ)")
+
+(deftest :syntax/arithmetic/3
+    (clsql:sql [/ [foo bar] [baz]])
+ "(FOO.BAR / BAZ)")
+
+(deftest :syntax/arithmetic/4
+    (clsql:sql [* [foo bar] [baz]])
+ "(FOO.BAR * BAZ)")
+
+(deftest :syntax/arithmetic/5
+    (clsql:sql [- [foo bar]])
+ "(- (FOO.BAR))")
+
+(deftest :syntax/arithmetic/6
+    (clsql:sql [* 2 3])
+  "(2 * 3)")
+
+
+(deftest :syntax/substr/1 
+    (clsql:sql [substr [hello] 1 4])
+ "SUBSTRING(HELLO,1,4)")
+
+
+(deftest :syntax/concat/1 
+    (clsql:sql [\|\| [foo] [bar] [baz]])
+ "(FOO || BAR || BAZ)")
+
+
+(deftest :syntax/pattern/1 
+    (clsql:sql [like [foo] "%v"])
+  "(FOO LIKE '%v')")
+
+(deftest :syntax/pattern/2
+    (clsql:sql [not [like [foo] "%v"]])
+  "(NOT ((FOO LIKE '%v')))")
+
+
+(deftest :syntax/distinct/1 
+    (clsql:sql [distinct [foo bar :string]])
+ "DISTINCT FOO.BAR")
+
+(deftest :syntax/distinct/2
+    (clsql:sql [distinct [foo :string] [bar :integer]])
+ "DISTINCT FOO, BAR")
+
+
+(deftest :syntax/order-by/1 
+    (clsql:sql [order-by [foo]])
+ "ORDER BY FOO")
+
+(deftest :syntax/group-by/1 
+    (clsql:sql [group-by [foo]])
+ "GROUP BY FOO")
+
+
+(deftest :syntax/sets/1 
+    (clsql:sql [union [select [foo] :from [bar]] [select [baz] :from [bar]]])
+ "SELECT FOO FROM BAR UNION SELECT BAZ FROM BAR")
+
+(deftest :syntax/sets/2 
+    (clsql:sql [intersect [select [foo] :from [bar]] [select [baz] :from [bar]]])
+ "SELECT FOO FROM BAR INTERSECT SELECT BAZ FROM BAR")
+
+(deftest :syntax/sets/3
+    (clsql:sql [except [select [foo] :from [bar]] [select [baz] :from [bar]]])
+ "SELECT FOO FROM BAR EXCEPT SELECT BAZ FROM BAR")
+
 
 (deftest :syntax/function/1
     (clsql:sql [function "COS" [age]])
     (clsql:sql [function "TO_DATE" "02/06/99" "mm/DD/RR"])
   "TO_DATE('02/06/99','mm/DD/RR')")
 
+
 (deftest :syntax/query/1
     (clsql:sql [select [person_id] [surname] :from [person]])
   "SELECT PERSON_ID,SURNAME FROM PERSON")