summaryrefslogtreecommitdiff
path: root/tests/test-internal.lisp
blob: 61076c6e716dcc5a65354668fc8d494508bffe9c (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
;;;; *************************************************************************
;;;; FILE IDENTIFICATION
;;;;
;;;; Name:    test-internal.lisp
;;;; Purpose: Tests for internal clsql functions
;;;; Author:  Kevin M. Rosenberg
;;;; Created: May 2004
;;;;
;;;; This file, part of CLSQL, is Copyright (c) 2004-2010 by Kevin M. Rosenberg
;;;;
;;;; 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-sys:file-enable-sql-reader-syntax)

(setq *rt-internal*
  '(
    (deftest :int/convert/1
        (clsql-sys::prepared-sql-to-postgresql-sql "SELECT FOO FROM BAR")
      "SELECT FOO FROM BAR")

    (deftest :int/convert/2
        (clsql-sys::prepared-sql-to-postgresql-sql "SELECT FOO FROM BAR WHERE ID=?")
      "SELECT FOO FROM BAR WHERE ID=$1")

    (deftest :int/convert/3
        (clsql-sys::prepared-sql-to-postgresql-sql "SELECT FOO FROM \"BAR\" WHERE ID=? AND CODE=?")
      "SELECT FOO FROM \"BAR\" WHERE ID=$1 AND CODE=$2")

    (deftest :int/convert/4
        (clsql-sys::prepared-sql-to-postgresql-sql "SELECT FOO FROM BAR WHERE ID=\"Match?\" AND CODE=?")
      "SELECT FOO FROM BAR WHERE ID=\"Match?\" AND CODE=$1")

    (deftest :int/convert/5
        (clsql-sys::prepared-sql-to-postgresql-sql "SELECT 'FOO' FROM BAR WHERE ID='Match?''?' AND CODE=?")
      "SELECT 'FOO' FROM BAR WHERE ID='Match?''?' AND CODE=$1")

    (deftest :int/output-caching/1
     ;; ensure that key generation and matching is working
     ;; so that this table doesnt balloon (more than designed)
     (list
      (progn (clsql:sql [foo])
             (clsql:sql [foo])
             (hash-table-count clsql-sys::*output-hash*))

      (progn (clsql:sql [foo.bar])
             (clsql:sql [foo bar])
             (hash-table-count clsql-sys::*output-hash*))
      (progn (clsql:sql (clsql-sys:sql-expression
                         :table (clsql-sys::database-identifier 'foo)
                         :attribute (clsql-sys::database-identifier 'bar)))
             (clsql:sql (clsql-sys:sql-expression
                         :table (clsql-sys::database-identifier 'foo)
                         :attribute (clsql-sys::database-identifier 'bar)))
             (hash-table-count clsql-sys::*output-hash*)))
     (1 2 2))

    (deftest :int/output-caching/2
     ;; ensure that we can disable the output cache and
     ;; still have everything work
     (let ((clsql-sys::*output-hash*))
       (list (clsql:sql [foo]) (clsql:sql [foo]) (clsql:sql [foo.bar])))
     ("FOO" "FOO" "FOO.BAR"))

    (deftest :currency/read-value/1
      (list
       (clsql-sys::read-decimal-value "$ 10,500.30")
       (clsql-sys::read-decimal-value "$ 10.500,30")
       (clsql-sys::read-decimal-value "-10 500,30")
       (clsql-sys::read-decimal-value "$ 10.500,30"))
      (1050030/100 1050030/100 -1050030/100 1050030/100))

    ))