www

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

test-order-point.rkt (1415B)


      1 #lang racket
      2 
      3 (require syntax/parse
      4          extensible-parser-specifications
      5          phc-toolkit/untyped
      6          rackunit)
      7 
      8 (define-syntax-class abc-order
      9   (pattern
     10    {~no-order
     11     {~optional {~order-point a-point #:a
     12                  {~post-fail "#:a must appear after #:b"
     13                              #:when (order-point> a-point b-point)}}}
     14     {~optional {~order-point b-point #:b}}
     15     {~optional {~order-point c-point #:c}}}))
     16 
     17 (define-syntax-rule (check-parse-abc stx)
     18   (check-true (syntax-parse stx
     19                 [:abc-order #t]
     20                 [_ #f])))
     21 
     22 (define-syntax-rule (check-fail-abc stx exn)
     23   (check-exn exn
     24              (λ ()
     25                (syntax-parse stx
     26                  [:abc-order 'ok]))))
     27 
     28 (check-parse-abc #'(#:a))
     29 (check-parse-abc #'(#:b))
     30 (check-parse-abc #'(#:c))
     31 (check-parse-abc #'(#:a #:b))
     32 (check-parse-abc #'(#:c #:a))
     33 (check-parse-abc #'(#:a #:c))
     34 (check-parse-abc #'(#:c #:b))
     35 (check-parse-abc #'(#:b #:c))
     36 (check-parse-abc #'(#:c #:a #:b))
     37 (check-parse-abc #'(#:a #:c #:b))
     38 (check-parse-abc #'(#:a #:b #:c))
     39 (check-fail-abc #'(#:b #:a) #px"#:a must appear after #:b")
     40 (check-fail-abc #'(#:c #:b #:a) #px"#:a must appear after #:b")
     41 (check-fail-abc #'(#:b #:c #:a) #px"#:a must appear after #:b")
     42 (check-fail-abc #'(#:b #:a #:c) #px"#:a must appear after #:b")
     43 (check-fail-abc #'(#:a #:a) #px"expected abc-order")
     44 (check-fail-abc #'(#:c #:c) #px"expected abc-order")