1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: kmrcl-tests.lisp
6 ;;;; Purpose: kmrcl tests file
7 ;;;; Author: Kevin M. Rosenberg
8 ;;;; Date Started: Apr 2003
10 ;;;; $Id: tests.lisp,v 1.16 2003/06/07 03:51:42 kevin Exp $
12 ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
14 ;;;; *************************************************************************
17 (defpackage #:kmrcl-tests
18 (:use #:kmrcl #:cl #:rtest))
19 (in-package #:kmrcl-tests)
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")
30 (substitute-chars-strings "abcd" '((#\a . "ef") (#\j . "ghi")))
33 (substitute-chars-strings "abcd" '((#\a . "ef") (#\d . "ghi")))
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&cd<")
40 (deftest str.12 (string-trim-last-character "") "")
41 (deftest str.13 (string-trim-last-character "a") "")
42 (deftest str.14 (string-trim-last-character "ab") "a")
43 (deftest str.15 (nstring-trim-last-character "") "")
44 (deftest str.16 (nstring-trim-last-character "a") "")
45 (deftest str.17 (nstring-trim-last-character "ab") "a")
47 (deftest str.18 (delimited-string-to-list "ab|cd|ef" #\|)
49 (deftest str.19 (delimited-string-to-list "ab|cd|ef" #\| t)
51 (deftest str.20 (delimited-string-to-list "") (""))
52 (deftest str.21 (delimited-string-to-list "" #\space t) (""))
53 (deftest str.22 (delimited-string-to-list "ab") ("ab"))
54 (deftest str.23 (delimited-string-to-list "ab" #\space t) ("ab"))
55 (deftest str.24 (delimited-string-to-list "ab|" #\|) ("ab" ""))
56 (deftest str.25 (delimited-string-to-list "ab|" #\| t) ("ab"))
58 (deftest apsl.1 (append-sublists '((a b) (c d))) (a b c d))
59 (deftest apsl.2 (append-sublists nil) nil)
60 (deftest apsl.3 (append-sublists '((a b))) (a b))
61 (deftest apsl.4 (append-sublists '((a))) (a))
62 (deftest apsl.5 (append-sublists '((a) (b) (c d (e f g)))) (a b c d (e f g)))
64 (deftest pss.0 (with-output-to-string (s) (print-separated-strings s "|" nil))
68 (with-output-to-string (s) (print-separated-strings s "|" '("ab")) )
72 (with-output-to-string (s) (print-separated-strings s "|" '("ab" "cd")))
76 (with-output-to-string (s) (print-separated-strings s "|" '("ab" "cd") nil))
80 (with-output-to-string (s)
81 (print-separated-strings s "|" '("ab" "cd") nil nil))
85 (with-output-to-string (s)
86 (print-separated-strings s "|" '("ab" "cd") nil '("ef") nil))
89 (deftest css.0 (concat-separated-strings "|" nil) "")
90 (deftest css.1 (concat-separated-strings "|" nil nil) "")
91 (deftest css.2 (concat-separated-strings "|" '("ab")) "ab")
92 (deftest css.3 (concat-separated-strings "|" '("ab" "cd")) "ab|cd")
93 (deftest css.4 (concat-separated-strings "|" '("ab" "cd") nil) "ab|cd")
94 (deftest css.5 (concat-separated-strings "|" '("ab" "cd") nil '("ef")) "ab|cd|ef")
96 (deftest f.1 (filter #'(lambda (x) (when (oddp x) (* x x)))
97 '(0 1 2 3 4 5 6 7 8 9)) (1 9 25 49 81))
98 (deftest an.1 (appendnew '(a b c d) '(c c e f)) (a b c d e f))
102 (xml-tag-contents "tag1" "<tag>Test</tag>")
106 (kmrcl::xml-tag-contents-old "tag1" "<tag>Test</tag>")
110 (kmrcl::fast-string-search "" "" 0 0 0) 0)
113 (kmrcl::fast-string-search "" "abc" 0 0 2) 0)
116 (kmrcl::fast-string-search "abc" "" 3 0 0) nil)
119 (kmrcl::fast-string-search "abc" "abcde" 3 0 4) 0)
122 (kmrcl::fast-string-search "abc" "012abcde" 3 0 7) 3)
125 (kmrcl::fast-string-search "abc" "012abcde" 3 0 7) 3)
128 (kmrcl::fast-string-search "abc" "012abcde" 3 3 7) 3)
131 (kmrcl::fast-string-search "abc" "012abcde" 3 4 7) nil)
134 (kmrcl::fast-string-search "abcde" "012abcde" 5 3 8) 3)
137 (kmrcl::fast-string-search "abcde" "012abcde" 5 3 7) nil)
141 (eval-when (:compile-toplevel :load-toplevel :execute)
142 (when (find-package '#:kmr-mop)
143 (pushnew :kmrtest-mop cl:*features*)))
147 (defclass credit-rating ()
148 ((level :attributes (date-set time-set))
149 (id :attributes (person-setting)))
150 (:metaclass attributes-class))
151 (defparameter cr nil)
153 (defclass monitored-credit-rating (credit-rating)
154 ((level :attributes (last-checked interval date-set))
156 (id :attributes (verified)))
157 (:metaclass attributes-class))
158 (defparameter mcr (make-instance 'monitored-credit-rating))
160 (deftest attrib.mop.1
162 (setq cr (make-instance 'credit-rating))
163 (slot-attribute cr 'level 'date-set))
166 (deftest attrib.mop.2
168 (setq cr (make-instance 'credit-rating))
169 (setf (slot-attribute cr 'level 'date-set) "12/15/1990")
170 (slot-attribute cr 'level 'date-set))
173 (deftest attrib.mop.3
175 (setq mcr (make-instance 'monitored-credit-rating))
176 (setf (slot-attribute mcr 'level 'date-set) "01/05/2002")
177 (slot-attribute mcr 'level 'date-set))
183 (eval-when (:compile-toplevel :load-toplevel :execute)
184 (setq cl:*features* (delete :kmrtest-mop cl:*features*)))