test-prompts.scm 2.3 KB

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