| 1 | ;;;; symbols.test --- test suite for Guile's symbols -*- scheme -*- |
| 2 | ;;;; |
| 3 | ;;;; Copyright (C) 2001, 2006, 2008 Free Software Foundation, Inc. |
| 4 | ;;;; |
| 5 | ;;;; This library is free software; you can redistribute it and/or |
| 6 | ;;;; modify it under the terms of the GNU Lesser General Public |
| 7 | ;;;; License as published by the Free Software Foundation; either |
| 8 | ;;;; version 3 of the License, or (at your option) any later version. |
| 9 | ;;;; |
| 10 | ;;;; This library 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 GNU |
| 13 | ;;;; Lesser General Public License for more details. |
| 14 | ;;;; |
| 15 | ;;;; You should have received a copy of the GNU Lesser General Public |
| 16 | ;;;; License along with this library; if not, write to the Free Software |
| 17 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | |
| 19 | (define-module (test-suite test-symbols) |
| 20 | #:use-module (test-suite lib) |
| 21 | #:use-module (ice-9 documentation)) |
| 22 | |
| 23 | |
| 24 | ;;; |
| 25 | ;;; miscellaneous |
| 26 | ;;; |
| 27 | |
| 28 | (define exception:immutable-string |
| 29 | (cons 'misc-error "^string is read-only")) |
| 30 | |
| 31 | (define (documented? object) |
| 32 | (not (not (object-documentation object)))) |
| 33 | |
| 34 | |
| 35 | ;;; |
| 36 | ;;; symbol? |
| 37 | ;;; |
| 38 | |
| 39 | (with-test-prefix "symbol?" |
| 40 | |
| 41 | (pass-if "documented?" |
| 42 | (documented? symbol?)) |
| 43 | |
| 44 | (pass-if "string" |
| 45 | (not (symbol? "foo"))) |
| 46 | |
| 47 | (pass-if "symbol" |
| 48 | (symbol? 'foo))) |
| 49 | |
| 50 | |
| 51 | ;;; |
| 52 | ;;; symbol->string |
| 53 | ;;; |
| 54 | |
| 55 | (with-test-prefix "symbol->string" |
| 56 | |
| 57 | (pass-if-exception "result is an immutable string" |
| 58 | exception:immutable-string |
| 59 | (string-set! (symbol->string 'abc) 1 #\space))) |
| 60 | |
| 61 | |
| 62 | ;;; |
| 63 | ;;; gensym |
| 64 | ;;; |
| 65 | |
| 66 | (with-test-prefix "gensym" |
| 67 | |
| 68 | (pass-if "documented?" |
| 69 | (documented? gensym)) |
| 70 | |
| 71 | (pass-if "produces a symbol" |
| 72 | (symbol? (gensym))) |
| 73 | |
| 74 | (pass-if "produces a fresh symbol" |
| 75 | (not (eq? (gensym) (gensym)))) |
| 76 | |
| 77 | (pass-if "accepts a string prefix" |
| 78 | (symbol? (gensym "foo"))) |
| 79 | |
| 80 | (pass-if-exception "does not accept a symbol prefix" |
| 81 | exception:wrong-type-arg |
| 82 | (gensym 'foo)) |
| 83 | |
| 84 | (pass-if "accepts long prefices" |
| 85 | (symbol? (gensym (make-string 4000 #\!)))) |
| 86 | |
| 87 | (pass-if "accepts embedded NULs" |
| 88 | (> (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))) |
| 89 | |