test-prompts.scm 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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-call "5"
  64. (lambda ()
  65. (+ 1 (% (+ 1 (call/cc (lambda (k) (+ 2 (k 3))))))))))
  66. (test-end* "test-prompts")