language/testing.rkt
#lang racket

(require (prefix-in pysem: "../semantics/beginner-syntax.rkt"))
(require "../utilities.rkt")

(define-syntax (test stx)
  (syntax-case stx (test is within)
    [(_ expr1 is expr2)
     (syntax/loc stx
       (pysem:check-expect expr1 expr2))]
    [(_ expr1 is expr2 within expr3)
     (syntax/loc stx
       (begin
         (when (not (number? expr3))
           (raise-pyret-error/stx
             (msg-unexpected 'test "a number" expr3)
             (syntax expr3)))
         (pysem:check-within expr1 expr2 expr3)))]))
(define-syntax (test_error stx)
  (syntax-case stx (test_error matches)
    [(_ expr1)
     (syntax/loc stx
       (pysem:check-error expr1))]
    [(_ expr1 matches expr2)
     (syntax/loc stx
       (pysem:check-error expr1 expr2))]))
(define-syntax (test_range stx)
  (syntax-case stx (test_range from to)
    [(_ expr1 from expr2 to expr3)
     (syntax/loc stx
       (begin
         (when (not (number? expr1))
           (raise-pyret-error/stx
             (msg-unexpected 'test_range "a number" expr1)
             (syntax expr1)))
         (when (not (number? expr2))
           (raise-pyret-error/stx
             (msg-unexpected 'test_range "a number" expr2)
             (syntax expr2)))
         (when (not (number? expr3))
           (raise-pyret-error/stx
             (msg-unexpected 'test_range "a number" expr3)
             (syntax expr3)))
         (pysem:check-range expr1 expr2 expr3)))]))


(provide test test_error test_range)