Remove CVS $Id$ keyword
[clsql.git] / tests / test-syntax.lisp
index ea2f614a6a1804487cd91564f2e1e14669c8a8ae..65efd9830bf414e2ede51e8290e6c9720a8d0ce7 100644 (file)
@@ -1,22 +1,22 @@
 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
-;;;; ======================================================================
-;;;; File:    test-syntax.lisp
-;;;; Author:  Marcus Pearce <m.t.pearce@city.ac.uk>
-;;;; Created: 30/03/2004
-;;;; Updated: $Id$
-;;;; ======================================================================
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Description ==========================================================
-;;;; ======================================================================
+;;;; Name:     clsql.asd
+;;;; Purpose:  Tests for the CLSQL Symbolic SQL syntax.
+;;;; Authors:  Marcus Pearce and Kevin M. Rosenberg
+;;;; Created:  March 2004
 ;;;;
-;;;; Tests for the CLSQL Symbolic SQL syntax.
-;;;;
-;;;; ======================================================================
+;;;; CLSQL users are granted the rights to distribute and use this software
+;;;; as governed by the terms of the Lisp Lesser GNU Public License
+;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
+;;;; *************************************************************************
 
 (in-package #:clsql-tests)
 
 #.(clsql:locally-enable-sql-reader-syntax)
 
+
 (setq *rt-syntax*
       '(
 
@@ -62,7 +62,7 @@
 
 (deftest :syntax/ident/5
     (clsql:sql [foo "bar"])
-  "FOO \"bar\"")
+    "FOO \"bar\"")
 
 (deftest :syntax/ident/6
     (clsql:sql ["foo" bar])
  "\"foo\".BAR")
 
 
+(deftest :syntax/attribute/1
+    (clsql:sql (clsql:sql-expression :table 'foo :attribute 'bar))
+  "FOO.BAR")
+
+(deftest :syntax/attribute/2
+    (clsql:sql (clsql:sql-expression :table 'foo :attribute "bar"))
+  "FOO.\"bar\"")
+
+(deftest :syntax/attribute/3
+    (clsql:sql (clsql:sql-expression :table "foo" :attribute 'bar))
+  "\"foo\".BAR")
+
+(deftest :syntax/attribute/4
+    (clsql:sql (clsql:sql-expression :table "foo" :attribute "bar"))
+  "\"foo\".\"bar\"")
+
 
 (deftest :syntax/subquery/1
     (clsql:sql [any '(3 4)])
 
 
 (deftest :syntax/logical/1
-    (clsql:sql [and [foo] [bar]])
-  "(FOO AND BAR)")
-
-(deftest :syntax/logical/2
-    (clsql:sql [or [foo] [bar]])
+    (values (clsql:sql [and [foo] [bar]])
+           (clsql:sql [or [foo] [bar]]))
+  "(FOO AND BAR)"
   "(FOO OR BAR)")
 
-(deftest :syntax/logical/3
+(deftest :syntax/logical/2
     (clsql:sql [not [foo]])
   "(NOT (FOO))")
 
+;;; Test how we apply logical operators when we have different numbers of children
+;;; This is useful if we wish to (apply #'sql-and some-list) without having to do
+;;; alot of length checking
+(deftest :syntax/logical/3
+    (values (clsql:sql [and ])
+           (clsql:sql [and [foo]])
+           (clsql:sql [and [not [foo]]])
+           (clsql:sql [and [foo] [bar] [baz]]))
+  ""
+  "FOO"
+  "(NOT (FOO))"
+  "(FOO AND BAR AND BAZ)")
+
+(deftest :syntax/logical/4
+    (clsql:sql [and [= [foo] [bar]]])
+  "(FOO = BAR)")
+
+(deftest :syntax/logical/5
+  (clsql:sql [and [= [foo] [bar]]
+                 [= [bar] [bast]]
+                 [= [block] [blech]]])
+  "((FOO = BAR) AND (BAR = BAST) AND (BLOCK = BLECH))")
+
+(deftest :syntax/logical/6
+    (clsql:sql
+     (apply #'sql-and
+           (list [= [foo] [bar]]
+                 [and ]
+                 [and [= [bar] [bast]]])))
+  "((FOO = BAR) AND (BAR = BAST))")
+
 
 (deftest :syntax/null/1
     (clsql:sql [null [foo]])
 (deftest :syntax/group-by/2
     (clsql:sql
      (clsql-sys::make-query [foo] [bar] [count [foo]]
-                            :from [table]
-                            :group-by '([foo] [bar])
-                            :order-by '([foo] [bar])))
+      :from [table]
+      :group-by '([foo] [bar])
+      :order-by '([foo] [bar])))
   "SELECT FOO,BAR,COUNT(FOO) FROM TABLE GROUP BY FOO,BAR ORDER BY FOO,BAR")
 
 
   "SELECT COUNT(*) FROM EMP")
 
 
-(deftest :syntax/expression1
+(deftest :syntax/expression/1
     (clsql:sql
      (clsql:sql-operation
       'select