merge from 1.8 branch
[bpt/guile.git] / test-suite / tests / symbols.test
1 ;;;; symbols.test --- test suite for Guile's symbols -*- scheme -*-
2 ;;;;
3 ;;;; Copyright (C) 2001, 2006 Free Software Foundation, Inc.
4 ;;;;
5 ;;;; This program is free software; you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation; either version 2, or (at your option)
8 ;;;; any later version.
9 ;;;;
10 ;;;; This program is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with this software; see the file COPYING. If not, write to
17 ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 ;;;; Boston, MA 02110-1301 USA
19
20 (use-modules (ice-9 documentation))
21
22
23 ;;;
24 ;;; miscellaneous
25 ;;;
26
27 ;; FIXME: As soon as guile supports immutable strings, this has to be
28 ;; replaced with the appropriate error type and message.
29 (define exception:immutable-string
30 (cons 'some-error-type "^trying to modify an immutable string"))
31
32 (define (documented? object)
33 (not (not (object-documentation object))))
34
35
36 ;;;
37 ;;; symbol?
38 ;;;
39
40 (with-test-prefix "symbol?"
41
42 (pass-if "documented?"
43 (documented? symbol?))
44
45 (pass-if "string"
46 (not (symbol? "foo")))
47
48 (pass-if "symbol"
49 (symbol? 'foo)))
50
51
52 ;;;
53 ;;; symbol->string
54 ;;;
55
56 (with-test-prefix "symbol->string"
57
58 (expect-fail-exception "result is an immutable string"
59 exception:immutable-string
60 (string-set! (symbol->string 'abc) 1 #\space)))
61
62
63 ;;;
64 ;;; gensym
65 ;;;
66
67 (with-test-prefix "gensym"
68
69 (pass-if "documented?"
70 (documented? gensym))
71
72 (pass-if "produces a symbol"
73 (symbol? (gensym)))
74
75 (pass-if "produces a fresh symbol"
76 (not (eq? (gensym) (gensym))))
77
78 (pass-if "accepts a string prefix"
79 (symbol? (gensym "foo")))
80
81 (pass-if-exception "does not accept a symbol prefix"
82 exception:wrong-type-arg
83 (gensym 'foo))
84
85 (pass-if "accepts long prefices"
86 (symbol? (gensym (make-string 4000 #\!))))
87
88 (pass-if "accepts embedded NULs"
89 (> (string-length (symbol->string (gensym "foo\0bar\0braz\0foo\0bar\0braz\0foo\0bar\0braz\0foo\0bar\0braz\0foo\0bar\0braz\0foo\0bar\0braz\0"))) 6)))
90