www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

test-foo-mixin-expander-predicate.rkt (2203B)


      1 #lang racket
      2 
      3 (require generic-syntax-expanders
      4          (for-syntax syntax/parse
      5                      rackunit))
      6 (require (for-syntax generic-syntax-expanders))
      7 (define-expander-type foo)
      8 (define-expander-type other)
      9 (define-foo-expander foo-exp (λ (stx) #''foo-exp-is-a-foo-expander))
     10 (define-other-expander other-exp (λ (stx) #''other-exp-is-not-a-foo-expander))
     11 (define-syntax not-an-expander 'syntax-local-value-is-not-an-expander)
     12 (begin-for-syntax
     13   (test-not-exn
     14    "Check that foo-expander? can be passed any value, not just an expander?"
     15    (λ ()
     16      (foo-expander? 123)
     17      (void)))
     18   
     19   (test-false
     20    "Check that (static foo-expander?) rejects syntax that is not an identifier?"
     21    (syntax-parse #'(definitely not-a-foo-expander)
     22      [(~var exp (static foo-expander? "a foo expander")) #t]
     23      [_ #f]))
     24   
     25   (test-false
     26    "Check that (static foo-expander?) rejects an id without syntax-local-value"
     27    (syntax-parse #'no-syntax-local-value
     28      [(~var exp (static foo-expander? "a foo expander")) #t]
     29      [_ #f]))
     30 
     31   (test-begin
     32    (test-false
     33     "Check that foo-expander? rejects an id which is not an expander?"
     34     (foo-expander? (syntax-local-value #'not-an-expander)))
     35    (test-false
     36     "Check that foo-expander? rejects an id which is not an expander?"
     37     (syntax-parse #'not-an-expander
     38       [(~var exp (static foo-expander? "a foo expander")) #t]
     39       [_ #f])))
     40 
     41   (test-begin
     42    (test-false
     43     (string-append "Check that foo-expander? rejects an id which is an"
     44                    " expander? but not a foo-expander?")
     45     (foo-expander? (syntax-local-value #'other-exp)))
     46    (test-false
     47     (string-append "Check that foo-expander? rejects an id which is an"
     48                    " expander? but not a foo-expander?")
     49     (syntax-parse #'other-exp
     50       [(~var exp (static foo-expander? "a foo expander")) #t]
     51       [_ #f])))
     52 
     53   (test-begin
     54    (test-true
     55     "Check that foo-expander? accepts an id which is a foo-expander?"
     56     (foo-expander? (syntax-local-value #'foo-exp)))
     57    (test-true
     58     "Check that foo-expander? accepts an id which is a foo-expander?"
     59     (syntax-parse #'foo-exp
     60       [(~var exp (static foo-expander? "a foo expander")) #t]
     61       [_ #f]))))