| 1 |
;; -*- coding:utf-8 -*- |
| 2 |
;; Copyright (C) Marc Nieper-Wißkirchen (2017). All Rights Reserved. |
| 3 |
|
| 4 |
;; Permission is hereby granted, free of charge, to any person |
| 5 |
;; obtaining a copy of this software and associated documentation |
| 6 |
;; files (the "Software"), to deal in the Software without |
| 7 |
;; restriction, including without limitation the rights to use, copy, |
| 8 |
;; modify, merge, publish, distribute, sublicense, and/or sell copies |
| 9 |
;; of the Software, and to permit persons to whom the Software is |
| 10 |
;; furnished to do so, subject to the following conditions: |
| 11 |
|
| 12 |
;; The above copyright notice and this permission notice shall be |
| 13 |
;; included in all copies or substantial portions of the Software. |
| 14 |
|
| 15 |
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 |
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 |
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 |
;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 19 |
;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 20 |
;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 |
;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 |
;; SOFTWARE. |
| 23 |
|
| 24 |
(define-library (srfi 154 test) |
| 25 |
(export run-tests) |
| 26 |
(import (scheme base) |
| 27 |
(srfi 64) |
| 28 |
(srfi 154)) |
| 29 |
(begin |
| 30 |
(define (run-tests) |
| 31 |
(test-begin "SRFI 154") |
| 32 |
|
| 33 |
(test-assert "Dynamic extents" |
| 34 |
(dynamic-extent? (current-dynamic-extent))) |
| 35 |
|
| 36 |
(test-equal "Parameter bindings" |
| 37 |
'b |
| 38 |
(let* |
| 39 |
((x (make-parameter 'a)) |
| 40 |
(de (parameterize |
| 41 |
((x 'b)) |
| 42 |
(current-dynamic-extent)))) |
| 43 |
(parameterize |
| 44 |
((x 'c)) |
| 45 |
(with-dynamic-extent |
| 46 |
de |
| 47 |
(lambda () |
| 48 |
(x)))))) |
| 49 |
|
| 50 |
(test-equal "Dynamically closed procedures" |
| 51 |
'a |
| 52 |
(let* ((x (make-parameter 'a)) |
| 53 |
(getter (dynamic-lambda () (x)))) |
| 54 |
(parameterize ((x 'b)) |
| 55 |
(getter)))) |
| 56 |
|
| 57 |
(test-equal "Multiple values" |
| 58 |
'(1 2) |
| 59 |
(call-with-values |
| 60 |
(lambda () |
| 61 |
(with-dynamic-extent (current-dynamic-extent) (lambda () |
| 62 |
(values 1 2)))) |
| 63 |
list)) |
| 64 |
|
| 65 |
(test-equal "Nested with-dynamic-extent" |
| 66 |
1 |
| 67 |
(let* ((x (make-parameter 1)) |
| 68 |
(e1 (current-dynamic-extent)) |
| 69 |
(e2 (parameterize ((x 2)) |
| 70 |
(current-dynamic-extent)))) |
| 71 |
(with-dynamic-extent e2 (lambda () |
| 72 |
(with-dynamic-extent e1 (lambda () |
| 73 |
(x))))))) |
| 74 |
|
| 75 |
(test-end "SRFI 154")))) |