www

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

test-auto-syntax-e.rkt (1595B)


      1 #lang racket
      2 
      3 (require auto-syntax-e
      4          rackunit
      5          syntax/parse)
      6 
      7 (check-equal? (match (auto-with-syntax ([x #'123])
      8                        (list (add1 x) #'x))
      9                 [(list a (? syntax? b))
     10                  (list a (syntax-e b))]
     11                 [_ 'error])
     12               '(124 123))
     13 
     14 (check-equal? (match (syntax-parse #'(1 2 3)
     15                        [(x:nat y:nat ...)
     16                         (auto-syntax (x y)
     17                           (list (map add1 (cons x y)) #'(x y ...)))])
     18                 [(list a (? syntax? b))
     19                  (list a (syntax->datum b))]
     20                 [_ 'error])
     21               '((2 3 4) (1 2 3)))
     22 
     23 (check-equal? (match (syntax-parse #'(1 2 3)
     24                        [({~seq x:nat {~optional y:nat}} ...)
     25                         (auto-syntax (x y)
     26                           (list (map cons x y)
     27                                 (attribute x)
     28                                 (attribute y)))])
     29                 [(list a
     30                        (list (? syntax? b₁) (? syntax? b₂))
     31                        (list (? syntax? c₁) (and #f c₂)))
     32                  (list a
     33                        (list (syntax->datum b₁) (syntax->datum b₂))
     34                        (list (syntax->datum c₁) c₂))]
     35                 [_ 'error])
     36               '([(1 . 2) (3 . #f)]
     37                 [1 3]
     38                 [2 #f]))
     39 
     40 (check-equal? (match (auto-syntax-case #'123 ()
     41                        [x (list (add1 x) #'x)])
     42                 [(list a (? syntax? b))
     43                  (list a (syntax-e b))]
     44                 [_ 'error])
     45               '(124 123))