source: trunk/source/tests/ansi-tests/gensym.lsp @ 8991

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

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

File size: 2.9 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat Jun 14 05:43:47 2003
4;;;; Contains: Tests of GENSYM
5
6(in-package :cl-test)
7
8;;; Gensym returns unique symbols
9(deftest gensym.1
10  (equal (gensym) (gensym))
11  nil)
12
13;;; Gensym returns symbols with distinct print names
14(deftest gensym.2
15  (string= (symbol-name (gensym))
16           (symbol-name (gensym)))
17  nil)
18
19;;; Gensym uses the *gensym-counter* special variable,
20;;; but does not increment it until after the symbol
21;;; has been created.
22(deftest gensym.3
23  (let ((*gensym-counter* 1))
24     (symbol-name (gensym)))
25  #.(string '#:g1))
26
27;;; Gensym uses the string argument instead of the default
28(deftest gensym.4
29  (let ((*gensym-counter* 1327))
30    (symbol-name (gensym "FOO")))
31  "FOO1327")
32
33;;; The symbol returned by gensym should be unbound
34(deftest gensym.5
35  (boundp (gensym))
36  nil)
37
38;;; The symbol returned by gensym should have no function binding
39(deftest gensym.6
40  (fboundp (gensym))
41  nil)
42
43;;; The symbol returned by gensym should have no property list
44(deftest gensym.7
45  (symbol-plist (gensym))
46  nil)
47
48;;; The symbol returned by gensym should be uninterned
49(deftest gensym.8
50  (symbol-package (gensym))
51  nil)
52
53;;; *gensym-counter* is incremented by gensym
54(deftest gensym.9
55  (let ((*gensym-counter* 12345))
56    (gensym)
57    *gensym-counter*)
58  12346)
59
60;;; Gensym works when *gensym-counter* is Really Big
61;;; (and does not increment the counter until after creating
62;;; the symbol.)
63(deftest gensym.10
64  (let ((*gensym-counter* 1234567890123456789012345678901234567890))
65    (symbol-name (gensym)))
66  #.(string '#:g1234567890123456789012345678901234567890))
67
68;;; gensym increments Really Big values of *gensym-counter*
69(deftest gensym.11
70  (let ((*gensym-counter* 12345678901234567890123456789012345678901234567890))
71    (gensym)
72    *gensym-counter*)
73  12345678901234567890123456789012345678901234567891)
74
75;;; Gensym uses an integer argument instead of the counter
76(deftest gensym.12
77  (let ((*gensym-counter* 10))
78    (symbol-name (gensym 123)))
79  #.(string '#:g123))
80
81;;; When given an integer argument, gensym does not increment the
82;;; *gensym-counter*
83(deftest gensym.13
84  (let ((*gensym-counter* 10))
85    (gensym 123)
86    *gensym-counter*)
87  10)
88
89;;; GENSYM counter is a non-negative integer
90(deftest gensym-counter.1
91  (and (integerp *gensym-counter*)
92       (>= *gensym-counter* 0)
93       t)
94  t)
95
96;;; Check response to erroneous arguments
97;;; Note! NIL is not the same as no argument
98;;; gensym should be implemented so that its only
99;;; argument defaults to "G", with NIL causing an error.
100
101(deftest gensym.error.1
102  (check-type-error #'gensym #'(lambda (x) (typep x '(or string unsigned-byte))))
103  nil)
104
105(deftest gensym.error.7
106  (signals-error (gensym 10 'foo) program-error)
107  t)
108
109(deftest gensym.error.8
110  (signals-error (locally (gensym t) t) type-error)
111  t)
112
113(deftest gensym.error.9
114  (signals-error (gensym "FOO" nil) program-error)
115  t)
116
Note: See TracBrowser for help on using the repository browser.