optargs.test 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ;;;; optargs.test --- test suite for optional arg processing -*- scheme -*-
  2. ;;;; Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> --- June 2001
  3. ;;;;
  4. ;;;; Copyright (C) 2001 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-optargs)
  21. :use-module (test-suite lib)
  22. :use-module (ice-9 optargs))
  23. (with-test-prefix "optional argument processing"
  24. (define* (test-1 #:optional (x 0))
  25. (define d 1) ; local define
  26. #t)
  27. (pass-if "local defines work with optional arguments"
  28. (false-if-exception (test-1))))
  29. ;;;
  30. ;;; let-keywords
  31. ;;;
  32. (with-test-prefix "let-keywords"
  33. ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
  34. ;; which caused apparently internal defines to "leak" out into the
  35. ;; encompasing environment
  36. (pass-if-exception "empty bindings internal defines leaking out"
  37. exception:unbound-var
  38. (let ((rest '()))
  39. (let-keywords rest #f ()
  40. (define localvar #f)
  41. #f)
  42. localvar))
  43. (pass-if "one key"
  44. (let-keywords '(#:foo 123) #f (foo)
  45. (= foo 123))))
  46. ;;;
  47. ;;; let-keywords*
  48. ;;;
  49. (with-test-prefix "let-keywords*"
  50. ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
  51. ;; which caused apparently internal defines to "leak" out into the
  52. ;; encompasing environment
  53. (pass-if-exception "empty bindings internal defines leaking out"
  54. exception:unbound-var
  55. (let ((rest '()))
  56. (let-keywords* rest #f ()
  57. (define localvar #f)
  58. #f)
  59. localvar))
  60. (pass-if "one key"
  61. (let-keywords* '(#:foo 123) #f (foo)
  62. (= foo 123))))
  63. ;;;
  64. ;;; let-optional
  65. ;;;
  66. (with-test-prefix "let-optional"
  67. ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
  68. ;; which caused apparently internal defines to "leak" out into the
  69. ;; encompasing environment
  70. (pass-if-exception "empty bindings internal defines leaking out"
  71. exception:unbound-var
  72. (let ((rest '()))
  73. (let-optional rest ()
  74. (define localvar #f)
  75. #f)
  76. localvar))
  77. (pass-if "one var"
  78. (let ((rest '(123)))
  79. (let-optional rest ((foo 999))
  80. (= foo 123)))))
  81. ;;;
  82. ;;; let-optional*
  83. ;;;
  84. (with-test-prefix "let-optional*"
  85. ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
  86. ;; which caused apparently internal defines to "leak" out into the
  87. ;; encompasing environment
  88. (pass-if-exception "empty bindings internal defines leaking out"
  89. exception:unbound-var
  90. (let ((rest '()))
  91. (let-optional* rest ()
  92. (define localvar #f)
  93. #f)
  94. localvar))
  95. (pass-if "one var"
  96. (let ((rest '(123)))
  97. (let-optional* rest ((foo 999))
  98. (= foo 123)))))