diff --git a/test/format-fail.rkt b/test/format-fail.rkt index 051287b..fdc6395 100644 --- a/test/format-fail.rkt +++ b/test/format-fail.rkt @@ -2,31 +2,27 @@ ;; `format:` expressions that should fail to compile -;; TODO abstract the 'module ...' -(define TEST-CASE* (syntax->list #'( - (module t typed/racket/base (require trivial/format) - (printf: "hello ~a" "john" "doe")) - (module t typed/racket/base (require trivial/format) - (printf: "hello ~a" "john" "doe")) - (module t typed/racket/base (require trivial/format) - (printf: "binary number ~b\n" 3.14)) - (module t typed/racket/base (require trivial/format) - (printf: "character ~c\n" 88)) - (module t typed/racket/base (require trivial/format) - (printf: "octl ~o\n" 1.0+2i)) - (module t typed/racket/base (require trivial/format) - (printf: "hex ~o\n" (exact->inexact 0))) +(define (expr->typed-module expr) + #`(module t typed/racket/base + (require trivial/format) + #,expr)) + +(define TEST-CASE* (map expr->typed-module '( + (printf: "hello ~a" "john" "doe") + (printf: "hello ~a" "john" "doe") + (printf: "binary number ~b\n" 3.14) + (printf: "character ~c\n" 88) + (printf: "octl ~o\n" 1.0+2i) + (printf: "hex ~o\n" (exact->inexact 0)) ))) (module+ test (require rackunit) - (define format-eval - (let ([format-ns (make-base-namespace)]) - (lambda (stx) - (lambda () ;; For `check-exn` - (eval-syntax stx format-ns))))) + (define (format-eval stx) + (lambda () ;; For `check-exn` + (compile-syntax stx))) (for ([rkt (in-list TEST-CASE*)]) (check-exn #rx"format::|Type Checker" diff --git a/test/regexp-fail.rkt b/test/regexp-fail.rkt index 69db9ba..c798136 100644 --- a/test/regexp-fail.rkt +++ b/test/regexp-fail.rkt @@ -2,63 +2,47 @@ ;; TODO why can't I catch errors for (ann ... (List String))? WhydoI need #f? -(define TEST-CASE* (syntax->list #'( - (module t typed/racket/base (require trivial/regexp) - (ann - (regexp-match: "hi" "hi") - (U #f (List String String String)))) - (module t typed/racket/base (require trivial/regexp) - (ann - (regexp-match: #rx"(h)(i)" "hi") - (U #f (List String)))) - (module t typed/racket/base (require trivial/regexp) - (ann - (regexp-match: #px"(?<=h)(?=i)" "hi") - (U #f (List String String String)))) - (module t typed/racket/base (require trivial/regexp) - ;;bg; ill-typed in untyped Racket - (byte-regexp: #rx#"yolo")) - (module t typed/racket/base (require trivial/regexp) - (ann - (regexp-match: #rx#"hi" "hi") - (U #f (List String String)))) - (module t typed/racket/base (require trivial/regexp) - (ann - (regexp-match: #px#"hi" "hi") - (U #f (List Bytes Bytes)))) - (module t typed/racket/base (require trivial/regexp) - (ann - (regexp-match: (regexp "he") "hellooo") - (U #f (List String)))) - (module t typed/racket/base (require trivial/regexp) - (ann - (let () - (define-regexp: rx (regexp "he(l*)(o*)")) - (regexp-match: rx "hellooo")) - (U #f (List String String String)))) - (module t typed/racket/base (require trivial/regexp) - ;; `define` doesn't propagate group information - (ann - (let () - (define rx "he(l*)(o*)") - (regexp-match: rx "helloooooooo")) - (U #f (List String String String)))) +(define (expr->typed-module expr) + #`(module t typed/racket/base + (require trivial/regexp) + #,expr)) + +(define TEST-CASE* (map expr->typed-module '( + (ann (regexp-match: "hi" "hi") + (U #f (List String String String))) + (ann (regexp-match: #rx"(h)(i)" "hi") + (U #f (List String))) + (ann (regexp-match: #px"(?<=h)(?=i)" "hi") + (U #f (List String String String))) + ;;bg; ill-typed in untyped Racket + (byte-regexp: #rx#"yolo") + (ann (regexp-match: #rx#"hi" "hi") + (U #f (List String String))) + (ann (regexp-match: #px#"hi" "hi") + (U #f (List Bytes Bytes))) + (ann (regexp-match: (regexp "he") "hellooo") + (U #f (List String))) + (ann (let () + (define-regexp: rx (regexp "he(l*)(o*)")) + (regexp-match: rx "hellooo")) + (U #f (List String String String))) + ;; `define` doesn't propagate group information + (ann (let () + (define rx "he(l*)(o*)") + (regexp-match: rx "helloooooooo")) + (U #f (List String String String))) ;; --- Can't handle |, yet - (module t typed/racket/base (require trivial/regexp) - (ann - (regexp-match: "this(group)|that" "that") - (U #f (List String String)))) + (ann (regexp-match: "this(group)|that" "that") + (U #f (List String String))) ))) (module+ test (require rackunit) - (define regexp-eval - (let ([regexp-ns (make-base-namespace)]) - (lambda (stx) - (lambda () ;; For `check-exn` - (eval-syntax stx regexp-ns))))) + (define (regexp-eval stx) + (lambda () ;; For `check-exn` + (compile-syntax stx))) (for ([rkt (in-list TEST-CASE*)]) (check-exn #rx"Type Checker"