#lang racket (require "cas-cad-e.rkt") ;;; TEST Syntax Errors ;; The syntax errors should signal errors in terms of cas-cad-e. ; (cas-cad-e) ; neither value expression nor case-clauses present ; (cas-cad-e 1) ; no case-clauses present ; (cas-cad-e 1 (a-datum)) ; no list of datums ; (cas-cad-e 1 ((a-datum))) ; missing then expression ;;; TEST Semantics ; Test 1 (define (cas1 v) (cas-cad-e v ((1) (display "1") ) ((2) (display "2") (break 2)) ((3) 3))) (cas1 1) ; ==> 2 (and prints "12") (cas1 2) ; ==> 2 (and prints "2") (cas1 3) ; ==> 3 (and prints nothing) (cas1 4) ; ==> (and prints nothing) ; Test 2 tests whether break works, in a context where break is unbound. ; This tests how break works when break is bound. ; If cas-cad-e shadows the binding, then it prints 5 and evaluates to 5, ; otherwise it prints 553 and evaluates to 3. (let ([break display]) (cas-cad-e 5 ((1) (display "1") ) ((5) (display "5") (break 5)) ((3) (display "3") 3))) ;=> ; Test 3 ; Test whether it is possible to bind break inside a cas-cad-e expression. ; Prints 63 evaluates to 3 (let ([break 1]) (cas-cad-e 6 ((1) (display "1") ) ((6) (display "6") (let ((break values)) (break 6))) ((3) (display "3") 3))) ; Test whether it possible to use cas-cad-e in syntax generated from a macro. (require (for-syntax "cas-cad-e.rkt")) (define-syntax (let1 stx) (syntax-case stx () [(_ id value-expr body) #'(let ((id value-expr)) (cas-cad-e 1 ((1) (break body))))])) (let1 x 41 (+ x 1)) ; evaluates to 42 (let1 break 42 (+ break 1)) ; evaluates to 43