srfi-9.test 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ;;;; srfi-9.test --- Test suite for Guile's SRFI-9 functions. -*- scheme -*-
  2. ;;;; Martin Grabmueller, 2001-05-10
  3. ;;;;
  4. ;;;; Copyright (C) 2001, 2006, 2007 Free Software Foundation, Inc.
  5. ;;;;
  6. ;;;; This program is free software; you can redistribute it and/or modify
  7. ;;;; it under the terms of the GNU General Public License as published by
  8. ;;;; the Free Software Foundation; either version 2, or (at your option)
  9. ;;;; any later version.
  10. ;;;;
  11. ;;;; This program is distributed in the hope that it will be useful,
  12. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;;; GNU General Public License for more details.
  15. ;;;;
  16. ;;;; You should have received a copy of the GNU General Public License
  17. ;;;; along with this software; see the file COPYING. If not, write to
  18. ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. ;;;; Boston, MA 02110-1301 USA
  20. (define-module (test-suite test-numbers)
  21. #:use-module (test-suite lib)
  22. #:use-module (srfi srfi-9))
  23. (define-record-type :foo (make-foo x) foo?
  24. (x get-x) (y get-y set-y!))
  25. (define-record-type :bar (make-bar i j) bar?
  26. (i get-i) (i get-j set-j!))
  27. (define f (make-foo 1))
  28. (set-y! f 2)
  29. (define b (make-bar 123 456))
  30. (with-test-prefix "constructor"
  31. (pass-if-exception "foo 0 args" exception:wrong-num-args
  32. (make-foo))
  33. (pass-if-exception "foo 2 args" exception:wrong-num-args
  34. (make-foo 1 2)))
  35. (with-test-prefix "predicate"
  36. (pass-if "pass"
  37. (foo? f))
  38. (pass-if "fail wrong record type"
  39. (eq? #f (foo? b)))
  40. (pass-if "fail number"
  41. (eq? #f (foo? 123))))
  42. (with-test-prefix "accessor"
  43. (pass-if "get-x"
  44. (= 1 (get-x f)))
  45. (pass-if "get-y"
  46. (= 2 (get-y f)))
  47. (pass-if-exception "get-x on number" exception:wrong-type-arg
  48. (get-x 999))
  49. (pass-if-exception "get-y on number" exception:wrong-type-arg
  50. (get-y 999))
  51. ;; prior to guile 1.6.9 and 1.8.1 this wan't enforced
  52. (pass-if-exception "get-x on bar" exception:wrong-type-arg
  53. (get-x b))
  54. (pass-if-exception "get-y on bar" exception:wrong-type-arg
  55. (get-y b)))
  56. (with-test-prefix "modifier"
  57. (pass-if "set-y!"
  58. (set-y! f #t)
  59. (eq? #t (get-y f)))
  60. (pass-if-exception "set-y! on number" exception:wrong-type-arg
  61. (set-y! 999 #t))
  62. ;; prior to guile 1.6.9 and 1.8.1 this wan't enforced
  63. (pass-if-exception "set-y! on bar" exception:wrong-type-arg
  64. (set-y! b 99)))