optargs.test 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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, 2006 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. (pass-if "local defines work with optional arguments"
  25. (eval '(begin
  26. (define* (test-1 #:optional (x 0))
  27. (define d 1) ; local define
  28. #t)
  29. (false-if-exception (test-1)))
  30. (interaction-environment))))
  31. ;;;
  32. ;;; let-keywords
  33. ;;;
  34. (with-test-prefix "let-keywords"
  35. ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
  36. ;; which caused apparently internal defines to "leak" out into the
  37. ;; encompasing environment
  38. (pass-if-exception "empty bindings internal defines leaking out"
  39. exception:unbound-var
  40. (let ((rest '()))
  41. (let-keywords rest #f ()
  42. (define localvar #f)
  43. #f)
  44. localvar))
  45. (pass-if "one key"
  46. (let-keywords '(#:foo 123) #f (foo)
  47. (= foo 123))))
  48. ;;;
  49. ;;; let-keywords*
  50. ;;;
  51. (with-test-prefix "let-keywords*"
  52. ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
  53. ;; which caused apparently internal defines to "leak" out into the
  54. ;; encompasing environment
  55. (pass-if-exception "empty bindings internal defines leaking out"
  56. exception:unbound-var
  57. (let ((rest '()))
  58. (let-keywords* rest #f ()
  59. (define localvar #f)
  60. #f)
  61. localvar))
  62. (pass-if "one key"
  63. (let-keywords* '(#:foo 123) #f (foo)
  64. (= foo 123))))
  65. ;;;
  66. ;;; let-optional
  67. ;;;
  68. (with-test-prefix "let-optional"
  69. ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
  70. ;; which caused apparently internal defines to "leak" out into the
  71. ;; encompasing environment
  72. (pass-if-exception "empty bindings internal defines leaking out"
  73. exception:unbound-var
  74. (let ((rest '()))
  75. (let-optional rest ()
  76. (define localvar #f)
  77. #f)
  78. localvar))
  79. (pass-if "one var"
  80. (let ((rest '(123)))
  81. (let-optional rest ((foo 999))
  82. (= foo 123)))))
  83. ;;;
  84. ;;; let-optional*
  85. ;;;
  86. (with-test-prefix "let-optional*"
  87. ;; in guile 1.6.4 and earlier, an empty binding list only used `begin',
  88. ;; which caused apparently internal defines to "leak" out into the
  89. ;; encompasing environment
  90. (pass-if-exception "empty bindings internal defines leaking out"
  91. exception:unbound-var
  92. (let ((rest '()))
  93. (let-optional* rest ()
  94. (define localvar #f)
  95. #f)
  96. localvar))
  97. (pass-if "one var"
  98. (let ((rest '(123)))
  99. (let-optional* rest ((foo 999))
  100. (= foo 123)))))