diff options
Diffstat (limited to 'tests/gexp.scm')
| -rw-r--r-- | tests/gexp.scm | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/gexp.scm b/tests/gexp.scm index cf88a9db807..6bdc2331706 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm | |||
| @@ -984,6 +984,64 @@ | |||
| 984 | '#~(foo #$bar #$baz:out #$(chbouib 42) #$@(list x y z) | 984 | '#~(foo #$bar #$baz:out #$(chbouib 42) #$@(list x y z) |
| 985 | #+foo #+foo:out #+(chbouib 42) #+@(list x y z))) | 985 | #+foo #+foo:out #+(chbouib 42) #+@(list x y z))) |
| 986 | 986 | ||
| 987 | (test-equal "hygiene, eval" | ||
| 988 | 42 | ||
| 989 | ;; Test: (1) that 'x' in one gexp does not shadow 'x' from the other 'gexp', | ||
| 990 | ;; and (2) that 'x' in 'ungexp' is not mistakenly renamed. | ||
| 991 | (let* ((inner (lambda (x) | ||
| 992 | #~(let ((x 40)) (+ x #$x)))) | ||
| 993 | (outer #~(let ((x 2)) | ||
| 994 | #$(inner #~x)))) | ||
| 995 | (primitive-eval (gexp->sexp* outer)))) | ||
| 996 | |||
| 997 | (test-assert "hygiene, define" | ||
| 998 | (match (gexp->sexp* #~(begin | ||
| 999 | ;; Top-level defines aren't renamed. | ||
| 1000 | (define top0 0) | ||
| 1001 | (define (top1 x) x) | ||
| 1002 | (define (top2 x y) | ||
| 1003 | ;; Internal define is renamed. | ||
| 1004 | (define inner1 (* x x)) | ||
| 1005 | (define (inner2 x) (+ x y)) | ||
| 1006 | (+ inner y)))) | ||
| 1007 | (('begin | ||
| 1008 | ('define 'top0 0) | ||
| 1009 | ('define ('top1 x0) x0) | ||
| 1010 | ('define ('top2 x1 y1) | ||
| 1011 | ('begin | ||
| 1012 | ('define inner1 ('* x1 x1)) | ||
| 1013 | ('define (inner2 x2) ('+ x2 y1)) | ||
| 1014 | ('+ inner y1)))) | ||
| 1015 | (and (not (eq? x0 'x)) | ||
| 1016 | (not (eq? x1 'x)) | ||
| 1017 | (not (eq? y1 'y)) | ||
| 1018 | (not (eq? inner1 'inner1)) | ||
| 1019 | (not (eq? inner2 'inner2)) | ||
| 1020 | (not (eq? x2 x1)))))) | ||
| 1021 | |||
| 1022 | (test-assert "hygiene, shadowed syntax" | ||
| 1023 | (match (gexp->sexp* #~(lambda (lambda x) | ||
| 1024 | (lambda (x) x))) | ||
| 1025 | (('lambda (arg x) | ||
| 1026 | (arg (x) x)) | ||
| 1027 | (and (not (eq? arg 'lambda)) | ||
| 1028 | (not (eq? x 'x)))))) | ||
| 1029 | |||
| 1030 | (test-assert "hygiene, quote" | ||
| 1031 | (match (gexp->sexp* #~(lambda (x y z) | ||
| 1032 | (list '(x y z) | ||
| 1033 | `(x ,x (,y ,z) z)))) | ||
| 1034 | (('lambda (x0 y0 z0) | ||
| 1035 | ('list ('quote ('x 'y 'z)) | ||
| 1036 | ('quasiquote | ||
| 1037 | ('x ('unquote x0) | ||
| 1038 | (('unquote y0) | ||
| 1039 | ('unquote z0)) | ||
| 1040 | 'z)))) | ||
| 1041 | (and (not (eq? x0 'x)) | ||
| 1042 | (not (eq? y0 'y)) | ||
| 1043 | (not (eq? z0 'z)))))) | ||
| 1044 | |||
| 987 | (test-end "gexp") | 1045 | (test-end "gexp") |
| 988 | 1046 | ||
| 989 | ;; Local Variables: | 1047 | ;; Local Variables: |
