source: trunk/source/tests/ansi-tests/nsubst-if.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 11 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 2.8 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat Apr 19 21:51:41 2003
4;;;; Contains: Tests of NSUBST-IF
5
6(in-package :cl-test)
7
8(compile-and-load "cons-aux.lsp")
9
10(deftest nsubst-if.1
11    (check-nsubst-if 'a #'consp '((100 1) (2 3) (4 3 2 1) (a b c)))
12  a)
13
14(deftest nsubst-if.2
15  (check-nsubst-if 17 (complement #'listp) '(a (a b) (a c d) (a nil e f g)))
16  (17 (17 17) (17 17 17) (17 nil 17 17 17)))
17
18(deftest nsubst-if.3
19  (check-nsubst-if '(z)
20                   (complement #'consp)
21                   '(a (a b) (c d e) (f g h i)))
22  ((z)
23   ((z) (z) z)
24   ((z) (z) (z) z)
25   ((z) (z) (z) (z) z)
26   z))
27
28(deftest nsubst-if.4
29  (check-nsubst-if 'b #'identity '((100 1) (2 3) (4 3 2 1) (a b c))
30                   :key #'listp)
31  b)
32
33(deftest nsubst-if.5
34  (check-nsubst-if 4 #'(lambda (x) (eql x 1))
35                   '((1 3) (1) (1 10 20 30) (1 3 x y))
36                   :key #'(lambda (x)
37                            (and (consp x)
38                                 (car x))))
39  (4 4 4 4))
40
41(deftest nsubst-if.6
42  (check-nsubst-if 'a  #'(lambda (x) (eql x 'b))
43                   '((a) (b) (c) (d))
44                   :key nil)
45  ((a) (a) (c) (d)))
46
47(deftest nsubst-if.7
48  (nsubst-if 'a #'null nil :bad t :allow-other-keys t)
49  a)
50
51(deftest nsubst-if.8
52  (let ((i 0) w x y z)
53    (values
54     (nsubst-if
55      (progn (setf w (incf i)) 'a)
56      (progn (setf x (incf i)) #'(lambda (x) (eql x 'b)))
57      (progn (setf y (incf i)) (copy-list '(1 2 a b c)))
58      :key (progn (setf z (incf i)) #'identity))
59     i w x y z))
60  (1 2 a a c)
61  4 1 2 3 4)
62
63;;; Keyword tests for nsubst-if
64
65(deftest nsubst-if.allow-other-keys.1
66  (nsubst-if 'a #'null nil :bad t :allow-other-keys t)
67  a)
68
69(deftest nsubst-if.allow-other-keys.2
70  (nsubst-if 'a #'null nil :allow-other-keys t)
71  a)
72
73(deftest nsubst-if.allow-other-keys.3
74  (nsubst-if 'a #'null nil :allow-other-keys nil)
75  a)
76
77(deftest nsubst-if.allow-other-keys.4
78  (nsubst-if 'a #'null nil :allow-other-keys t :bad t)
79  a)
80
81(deftest nsubst-if.allow-other-keys.5
82  (nsubst-if 'a #'null nil :allow-other-keys t :allow-other-keys nil :bad t)
83  a)
84
85(deftest nsubst-if.keywords.6
86  (nsubst-if 'a #'null nil :key nil :key (constantly 'b))
87  a)
88
89;;; error cases
90
91(deftest nsubst-if.error.1
92  (signals-error (nsubst-if) program-error)
93  t)
94
95(deftest nsubst-if.error.2
96  (signals-error (nsubst-if 'a) program-error)
97  t)
98
99(deftest nsubst-if.error.3
100  (signals-error (nsubst-if 'a #'null) program-error)
101  t)
102
103(deftest nsubst-if.error.4
104  (signals-error (nsubst-if 'a #'null nil :foo nil) program-error)
105  t)
106
107(deftest nsubst-if.error.5
108  (signals-error (nsubst-if 'a #'null nil :test) program-error)
109  t)
110
111(deftest nsubst-if.error.6
112  (signals-error (nsubst-if 'a #'null nil 1) program-error)
113  t)
114
115(deftest nsubst-if.error.7
116  (signals-error (nsubst-if 'a #'null nil :bad t :allow-other-keys nil)
117                 program-error)
118  t)
119
120(deftest nsubst-if.error.8
121  (signals-error (nsubst-if 'a #'null (list 'a nil 'c) :key #'cons)
122                 program-error)
123  t)
Note: See TracBrowser for help on using the repository browser.