symbols.test 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ;;;; symbols.test --- test suite for Guile's symbols -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2001, 2006, 2008 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. (define-module (test-suite test-symbols)
  20. #:use-module (test-suite lib)
  21. #:use-module (ice-9 documentation))
  22. ;;;
  23. ;;; miscellaneous
  24. ;;;
  25. (define exception:immutable-string
  26. (cons 'misc-error "^string is read-only"))
  27. (define (documented? object)
  28. (not (not (object-documentation object))))
  29. ;;;
  30. ;;; symbol?
  31. ;;;
  32. (with-test-prefix "symbol?"
  33. (pass-if "documented?"
  34. (documented? symbol?))
  35. (pass-if "string"
  36. (not (symbol? "foo")))
  37. (pass-if "symbol"
  38. (symbol? 'foo)))
  39. ;;;
  40. ;;; symbol->string
  41. ;;;
  42. (with-test-prefix "symbol->string"
  43. (pass-if-exception "result is an immutable string"
  44. exception:immutable-string
  45. (string-set! (symbol->string 'abc) 1 #\space)))
  46. ;;;
  47. ;;; gensym
  48. ;;;
  49. (with-test-prefix "gensym"
  50. (pass-if "documented?"
  51. (documented? gensym))
  52. (pass-if "produces a symbol"
  53. (symbol? (gensym)))
  54. (pass-if "produces a fresh symbol"
  55. (not (eq? (gensym) (gensym))))
  56. (pass-if "accepts a string prefix"
  57. (symbol? (gensym "foo")))
  58. (pass-if-exception "does not accept a symbol prefix"
  59. exception:wrong-type-arg
  60. (gensym 'foo))
  61. (pass-if "accepts long prefices"
  62. (symbol? (gensym (make-string 4000 #\!))))
  63. (pass-if "accepts embedded NULs"
  64. (> (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)))