test-prompts.scm 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ;;; Copyright (C) 2023 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
  23. ((except (hoot control) call-with-current-continuation call/cc))
  24. (test-call "42" (lambda (f tag)
  25. (call-with-prompt tag
  26. (lambda () (f))
  27. (lambda (k) #f)))
  28. (lambda () 42)
  29. "hey")
  30. (test-call "69" (lambda (f tag)
  31. (call-with-prompt tag
  32. (lambda () (1+ (f tag)))
  33. (lambda (k v) v)))
  34. (lambda (tag) (abort-to-prompt tag 69))
  35. "hey")
  36. (test-call "69"
  37. (lambda (abort-to-prompt tag)
  38. (call-with-prompt tag
  39. (lambda ()
  40. (dynamic-wind values
  41. (lambda () 42)
  42. (lambda () (abort-to-prompt tag 69))))
  43. (lambda (k v) v)))
  44. abort-to-prompt "hey")
  45. (test-call "69"
  46. (lambda (abort-to-prompt tag)
  47. (call-with-prompt tag
  48. (lambda ()
  49. (dynamic-wind values
  50. (lambda () (abort-to-prompt tag 42))
  51. (lambda () (abort-to-prompt tag 69))))
  52. (lambda (k v) v)))
  53. abort-to-prompt "hey")
  54. (test-call "69" (lambda (f tag)
  55. (call-with-prompt tag
  56. (lambda () (- (f tag)))
  57. (lambda (k v) (k (- -2 v)))))
  58. (lambda (tag) (abort-to-prompt tag 67))
  59. "hey")
  60. (test-call "4"
  61. (lambda ()
  62. (% (+ 1 (call/cc (lambda (k) (+ 2 (k 3)))))))))
  63. (test-end* "test-prompts")