srfi-17.test 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ;;;; srfi-17.test --- test suite for Guile's SRFI-17 functions. -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2001, 2003, 2005, 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. (define-module (test-suite test-srfi-17)
  20. :use-module (test-suite lib)
  21. :use-module (srfi srfi-17))
  22. (pass-if "cond-expand srfi-17"
  23. (cond-expand (srfi-17 #t)
  24. (else #f)))
  25. ;;
  26. ;; car
  27. ;;
  28. (with-test-prefix "car"
  29. ;; this test failed in guile 1.8.1 and 1.6.8 and earlier, since `define'
  30. ;; didn't set a name on a procedure-with-setter
  31. (pass-if "procedure-name"
  32. (if (memq 'procnames (debug-options)) ;; enabled by default
  33. (eq? 'car (procedure-name car))
  34. (throw 'unsupported)))
  35. (pass-if "set! (car x)"
  36. (let ((lst (list 1)))
  37. (set! (car lst) 2)
  38. (eqv? 2 (car lst)))))
  39. ;;
  40. ;; set!
  41. ;;
  42. (define %some-variable #f)
  43. (with-test-prefix "set!"
  44. (with-test-prefix "target is not procedure with setter"
  45. (pass-if-exception "(set! (symbol->string 'x) 1)"
  46. exception:wrong-type-arg
  47. (set! (symbol->string 'x) 1))
  48. (pass-if-exception "(set! '#f 1)"
  49. exception:bad-variable
  50. (eval '(set! '#f 1) (interaction-environment))))
  51. (with-test-prefix "target uses macro"
  52. (pass-if "(set! (@@ ...) 1)"
  53. (eval '(set! (@@ (test-suite test-srfi-17) %some-variable) 1)
  54. (interaction-environment))
  55. (equal? %some-variable 1))
  56. ;; The `(quote x)' below used to be memoized as an infinite list before
  57. ;; Guile 1.8.3.
  58. (pass-if-exception "(set! 'x 1)"
  59. exception:bad-variable
  60. (eval '(set! 'x 1) (interaction-environment)))))
  61. ;;
  62. ;; setter
  63. ;;
  64. (with-test-prefix "setter"
  65. (pass-if-exception "set! (setter x)" (cons 'misc-error ".*")
  66. (set! (setter car) noop))
  67. (pass-if "car"
  68. (eq? set-car! (setter car))))