Created
January 11, 2013 21:31
-
-
Save dyoo/4514112 to your computer and use it in GitHub Desktop.
examples for ozzloy of syntax-parse and more tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(require (for-syntax racket/base | |
syntax/parse)) | |
(provide swap) | |
(define-syntax (swap stx) | |
(syntax-parse stx | |
[(_ x:identifier y:identifier) | |
#'(let ([tmp x]) | |
(set! x y) | |
(set! y tmp))])) | |
(module* test racket/base | |
(require (submod "..") | |
rackunit) | |
;; A little setup for running the compiler and evaluator | |
;; for the run-time tests | |
(define-namespace-anchor anchor) | |
(define ns (namespace-anchor->namespace anchor)) | |
(define-syntax-rule (try expr) | |
(parameterize ([current-namespace ns]) | |
(eval 'expr))) | |
;;;;;;;;;;;;;;;;;;;;;;; | |
(check-exn exn:fail:syntax? | |
(lambda () (try (begin (define x 'x) | |
(swap x 2))))) | |
(check-equal? (try (begin (define x 'foo) | |
(define y 'bar) | |
(swap x y) | |
(list x y))) | |
'(bar foo))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment