~ chicken-core (chicken-5) /tests/environment-tests.scm
Trap1;;;; environment-tests.scm23(import (chicken load) (chicken eval))45(load-relative "test.scm")678(test-begin "evaluation environment tests")910(test-equal (eval 123) 123)11(test-equal (eval 123 (interaction-environment)) 123)12(test-equal (eval 'car (interaction-environment)) car)13(test-error (eval 'foo (interaction-environment)))14(test-equal (eval '(begin (set! foo 99) foo) (interaction-environment)) 99)1516(test-equal (eval 123) 123)17(test-equal (eval 123 (scheme-report-environment 5)) 123)18(test-equal (eval 'car (scheme-report-environment 5)) car)19(test-error (eval 'foo (scheme-report-environment 5)))20(test-error (eval 'values (scheme-report-environment 4)))21(test-equal (eval 'values (scheme-report-environment 5)) values)22(test-error (eval '(set! foo 99) (scheme-report-environment 5)))2324(test-error (eval '(define-syntax foo (syntax-rules () ((_) 1)))25 (scheme-report-environment 5)))2627(test-error (eval 'car (null-environment 5)))28(test-error (eval '(cond-expand (chicken 1) (else 2)) (null-environment 4)))29(test-error (eval '(cond-expand (chicken 1) (else 2)) (null-environment 5)))30(test-error (eval '(cond-expand (chicken 1) (else 2)) (scheme-report-environment 4)))31(test-error (eval '(cond-expand (chicken 1) (else 2)) (scheme-report-environment 5)))32(test-equal 1 (eval '(if #t 1 2) (scheme-report-environment 5)))33(test-equal 1 (eval '(if #t 1 2) (null-environment 4)))34(test-equal 1 (eval '(if #t 1 2) (null-environment 5)))35(test-equal (eval '((lambda (x) x) 123) (null-environment 5)) 123)3637(import (chicken eval))3839(define baz 100)4041(module foo (bar)42 (import r5rs)43 (define (bar) 99))4445(define foo-env (module-environment 'foo))46(define csi-env (module-environment '(chicken csi)))47(define format-env (module-environment 'chicken.format))4849(test-equal (eval '(bar) foo-env) 99)50(test-error (eval 'baz foo-env))51(test-equal (eval '(editor-command) csi-env) #f)52(test-error (eval 'baz csi-env))53(test-equal (eval '(format "~a" 1) format-env) "1")54(test-error (eval 'baz format-env))5556;; #129557(module example *58 (import scheme)59 (define (add a b) (+ a b))60 (define-syntax double61 (syntax-rules ()62 ((_ x) (add x x)))))6364(test-equal (eval '(double 10) (module-environment 'example)) 20)6566(test-end)6768(test-exit)