test-prompts.scm 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ;;; Copyright (C) 2023, 2025, 2025 Igalia, S.L.
  2. ;;;
  3. ;;; Licensed under the Apache License, Version 2.0 (the "License");
  4. ;;; you may not use this file except in compliance with the License.
  5. ;;; You may obtain a copy of the License at
  6. ;;;
  7. ;;; http://www.apache.org/licenses/LICENSE-2.0
  8. ;;;
  9. ;;; Unless required by applicable law or agreed to in writing, software
  10. ;;; distributed under the License is distributed on an "AS IS" BASIS,
  11. ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ;;; See the License for the specific language governing permissions and
  13. ;;; limitations under the License.
  14. ;;; Commentary:
  15. ;;;
  16. ;;; Prompt tests.
  17. ;;;
  18. ;;; Code:
  19. (use-modules (srfi srfi-64)
  20. (test utils))
  21. (test-begin "test-prompts")
  22. (with-additional-imports ((except (hoot control)
  23. call-with-current-continuation
  24. call/cc)
  25. (only (hoot numbers) 1+))
  26. (test-call "42" (lambda (f tag)
  27. (call-with-prompt tag
  28. (lambda () (f))
  29. (lambda (k) #f)))
  30. (lambda () 42)
  31. "hey")
  32. (test-call "69" (lambda (f tag)
  33. (call-with-prompt tag
  34. (lambda () (1+ (f tag)))
  35. (lambda (k v) v)))
  36. (lambda (tag) (abort-to-prompt tag 69))
  37. "hey")
  38. (test-call "69"
  39. (lambda (abort-to-prompt tag)
  40. (call-with-prompt tag
  41. (lambda ()
  42. (dynamic-wind values
  43. (lambda () 42)
  44. (lambda () (abort-to-prompt tag 69))))
  45. (lambda (k v) v)))
  46. abort-to-prompt "hey")
  47. (test-call "69"
  48. (lambda (abort-to-prompt tag)
  49. (call-with-prompt tag
  50. (lambda ()
  51. (dynamic-wind values
  52. (lambda () (abort-to-prompt tag 42))
  53. (lambda () (abort-to-prompt tag 69))))
  54. (lambda (k v) v)))
  55. abort-to-prompt "hey")
  56. (test-call "69" (lambda (f tag)
  57. (call-with-prompt tag
  58. (lambda () (- (f tag)))
  59. (lambda (k v) (k (- -2 v)))))
  60. (lambda (tag) (abort-to-prompt tag 67))
  61. "hey")
  62. (test-call "4"
  63. (lambda ()
  64. (+ 1 (call/cc (lambda (k) (+ 2 (k 3)))))))
  65. (test-call "5"
  66. (lambda ()
  67. (+ 1 (% (+ 1 (call/cc (lambda (k) (+ 2 (k 3))))))))))
  68. (test-end* "test-prompts")