r4887: Auto commit for Debian build
[kmrcl.git] / tests.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          kmrcl-tests.lisp
6 ;;;; Purpose:       kmrcl tests file
7 ;;;; Author:        Kevin M. Rosenberg
8 ;;;; Date Started:  Apr 2003
9 ;;;;
10 ;;;; $Id: tests.lisp,v 1.13 2003/05/08 19:19:08 kevin Exp $
11 ;;;;
12 ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; *************************************************************************
15
16 (defpackage #:kmrcl-tests
17   (:use #:kmrcl #:cl #:rtest))
18 (in-package #:kmrcl-tests)
19
20 (rem-all-tests)
21
22
23
24 (deftest str.0 (substitute-chars-strings "" nil) "")
25 (deftest str.1 (substitute-chars-strings "abcd" nil) "abcd")
26 (deftest str.2 (substitute-chars-strings "abcd" nil) "abcd")
27 (deftest str.3 (substitute-chars-strings "abcd" '((#\j . "ef"))) "abcd")
28 (deftest str.4 (substitute-chars-strings "abcd" '((#\a . "ef"))) "efbcd")
29 (deftest str.5
30     (substitute-chars-strings "abcd" '((#\a . "ef") (#\j . "ghi")))
31   "efbcd")
32 (deftest str.6
33     (substitute-chars-strings "abcd" '((#\a . "ef") (#\d . "ghi")))
34   "efbcghi")
35
36 (deftest str.7 (escape-xml-string "") "")
37 (deftest str.8 (escape-xml-string "abcd") "abcd")
38 (deftest str.9 (escape-xml-string "ab&cd") "ab&cd")
39 (deftest str.10 (escape-xml-string "ab&cd<") "ab&amp;cd&lt;")
40 (deftest str.11 (escape-xml-string "ab&c><") "ab&amp;c&gt;&lt;")
41 (deftest str.12 (string-trim-last-character "") "")
42 (deftest str.13 (string-trim-last-character "a") "")
43 (deftest str.14 (string-trim-last-character "ab") "a")
44 (deftest str.15 (nstring-trim-last-character "") "")
45 (deftest str.16 (nstring-trim-last-character "a") "")
46 (deftest str.17 (nstring-trim-last-character "ab") "a")
47
48 (deftest str.18 (delimited-string-to-list "ab|cd|ef" #\|)
49                                           ("ab" "cd" "ef"))
50 (deftest str.19 (delimited-string-to-list "ab|cd|ef" #\| t)
51                                           ("ab" "cd" "ef"))
52 (deftest str.20 (delimited-string-to-list "") (""))
53 (deftest str.21 (delimited-string-to-list "" #\space t) (""))
54 (deftest str.22 (delimited-string-to-list "ab") ("ab"))
55 (deftest str.23 (delimited-string-to-list "ab" #\space t) ("ab"))
56 (deftest str.24 (delimited-string-to-list "ab|" #\|) ("ab" ""))
57 (deftest str.25 (delimited-string-to-list "ab|" #\| t) ("ab"))
58
59 (deftest apsl.1 (append-sublists '((a b) (c d))) (a b c d))
60 (deftest apsl.2 (append-sublists nil) nil)
61 (deftest apsl.3 (append-sublists '((a b))) (a b))
62 (deftest apsl.4 (append-sublists '((a))) (a))
63 (deftest apsl.5 (append-sublists '((a) (b) (c d (e f g)))) (a b c d (e f g)))
64
65 (deftest pss.0 (with-output-to-string (s) (print-separated-strings s "|" nil)) 
66   "")
67
68 (deftest pss.1
69     (with-output-to-string (s) (print-separated-strings s "|" '("ab")) )
70   "ab")
71
72 (deftest pss.2
73     (with-output-to-string (s) (print-separated-strings s "|" '("ab" "cd")))
74     "ab|cd")
75
76 (deftest pss.3
77     (with-output-to-string (s) (print-separated-strings s "|" '("ab" "cd") nil))
78     "ab|cd")
79
80 (deftest pss.4
81     (with-output-to-string (s)
82       (print-separated-strings s "|" '("ab" "cd") nil nil))
83     "ab|cd")
84
85 (deftest pss.5
86     (with-output-to-string (s)
87       (print-separated-strings s "|" '("ab" "cd") nil '("ef") nil))
88     "ab|cd|ef")
89
90 (deftest css.0 (concat-separated-strings "|" nil) "")
91 (deftest css.1 (concat-separated-strings "|" nil nil) "")
92 (deftest css.2 (concat-separated-strings "|" '("ab")) "ab")
93 (deftest css.3 (concat-separated-strings "|" '("ab" "cd")) "ab|cd")
94 (deftest css.4 (concat-separated-strings "|" '("ab" "cd") nil) "ab|cd")
95 (deftest css.5 (concat-separated-strings "|" '("ab" "cd") nil '("ef")) "ab|cd|ef")
96
97 (eval-when (:compile-toplevel :load-toplevel :execute)
98   (when (find-package '#:kmr-mop)
99     (pushnew :kmrtest-mop cl:*features*)))
100
101 #+kmrtest-mop
102 (progn
103   (defclass credit-rating ()
104     ((level :attributes (date-set time-set))
105      (id :attributes (person-setting)))
106     (:metaclass attributes-class))
107   (defparameter cr nil)
108   
109   (defclass monitored-credit-rating (credit-rating)
110     ((level :attributes (last-checked interval date-set))
111      (cc :initarg :cc)
112      (id :attributes (verified)))
113     (:metaclass attributes-class))
114   (defparameter mcr (make-instance 'monitored-credit-rating))
115
116   (deftest attrib.mop.1
117       (progn
118         (setq cr (make-instance 'credit-rating))
119         (slot-attribute cr 'level 'date-set))
120       nil)
121
122   (deftest attrib.mop.2
123       (progn
124         (setq cr (make-instance 'credit-rating))
125         (setf (slot-attribute cr 'level 'date-set) "12/15/1990")
126         (slot-attribute cr 'level 'date-set))
127     "12/15/1990")
128
129   (deftest attrib.mop.3
130       (progn
131         (setq mcr (make-instance 'monitored-credit-rating))
132         (setf (slot-attribute mcr 'level 'date-set) "01/05/2002")
133         (slot-attribute mcr 'level 'date-set))
134     "01/05/2002")
135   
136   )   ;; kmrcl-mop
137
138 #+kmrtest-mop
139 (eval-when (:compile-toplevel :load-toplevel :execute)
140   (setq cl:*features* (delete :kmrtest-mop cl:*features*)))