split debug-repl + macros tests into a separate file
This commit is contained in:
parent
460c4a781a
commit
113cdf2662
|
@ -2,3 +2,6 @@
|
||||||
|
|
||||||
(define scribblings '(["scribblings/debug.scrbl" ()]))
|
(define scribblings '(["scribblings/debug.scrbl" ()]))
|
||||||
|
|
||||||
|
(define compile-omit-paths
|
||||||
|
'("test/debug-repl-macros.rkt"
|
||||||
|
))
|
||||||
|
|
88
debug/test/debug-repl-macros.rkt
Normal file
88
debug/test/debug-repl-macros.rkt
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
#lang racket/base
|
||||||
|
|
||||||
|
(require "../repl.rkt"
|
||||||
|
"test-util.rkt"
|
||||||
|
rackunit
|
||||||
|
(for-syntax racket/base syntax/parse))
|
||||||
|
|
||||||
|
(define a 3)
|
||||||
|
(define b 4)
|
||||||
|
|
||||||
|
(test-case "local macros that don't refer to other macros"
|
||||||
|
(define (f tmp)
|
||||||
|
(define-syntax ?list
|
||||||
|
(syntax-parser
|
||||||
|
[(?list x:expr ...)
|
||||||
|
(define (?list-helper acc xs)
|
||||||
|
(syntax-parse (list acc xs)
|
||||||
|
[([acc:id ...] []) #'(list acc ...)]
|
||||||
|
[([acc:id ...] [x:expr y:expr ...])
|
||||||
|
#:with [tmp] (generate-temporaries #'[x])
|
||||||
|
#`(let ([tmp x])
|
||||||
|
(if tmp
|
||||||
|
#,(?list-helper #'[acc ... tmp] #'[y ...])
|
||||||
|
#false))]))
|
||||||
|
(?list-helper #'[] #'[x ...])]))
|
||||||
|
(debug-repl)
|
||||||
|
tmp)
|
||||||
|
|
||||||
|
(test-with-io
|
||||||
|
#:i [i (open-input-string "a b tmp (?list a b tmp)")]
|
||||||
|
#:o [o (open-output-string)]
|
||||||
|
(check-equal? (f 1) 1)
|
||||||
|
(check-equal? (get-output-string o)
|
||||||
|
(string-append
|
||||||
|
"-> " #;a "3\n"
|
||||||
|
"-> " #;b "4\n"
|
||||||
|
"-> " #;tmp "1\n"
|
||||||
|
"-> " #;(?list a b tmp) "'(3 4 1)\n"
|
||||||
|
"-> ")))
|
||||||
|
|
||||||
|
(test-with-io
|
||||||
|
#:i [i (open-input-string "(?list . bluh)")]
|
||||||
|
#:o [o (open-output-string)]
|
||||||
|
(check-exn #rx"\\?list: bad syntax"
|
||||||
|
(λ () (f 1)))
|
||||||
|
(check-equal? (get-output-string o)
|
||||||
|
(string-append
|
||||||
|
"-> " #;(?list. bluh)))))
|
||||||
|
|
||||||
|
;; TODO: !!! identifier used out of context !!!
|
||||||
|
#;
|
||||||
|
(test-case "local macros that refer to other macros"
|
||||||
|
(define (f tmp)
|
||||||
|
(define-syntax ?list-helper
|
||||||
|
(syntax-parser
|
||||||
|
[(?list-helper [acc:id ...] []) #'(list acc ...)]
|
||||||
|
[(?list-helper [acc:id ...] [x:expr y:expr ...])
|
||||||
|
#'(let ([tmp x])
|
||||||
|
(if tmp
|
||||||
|
(?list-helper [acc ... tmp] [y ...])
|
||||||
|
#false))]))
|
||||||
|
(define-syntax-rule (?list x ...)
|
||||||
|
(?list-helper [] [x ...]))
|
||||||
|
(debug-repl)
|
||||||
|
tmp)
|
||||||
|
|
||||||
|
(test-with-io
|
||||||
|
#:i [i (open-input-string "a b tmp (?list a b tmp)")]
|
||||||
|
#:o [o (open-output-string)]
|
||||||
|
(check-equal? (f 1) 1)
|
||||||
|
(check-equal? (get-output-string o)
|
||||||
|
(string-append
|
||||||
|
"-> " #;a "3\n"
|
||||||
|
"-> " #;b "4\n"
|
||||||
|
"-> " #;tmp "1\n"
|
||||||
|
"-> " #;(?list a b tmp) "'(3 4 1)\n"
|
||||||
|
"-> ")))
|
||||||
|
|
||||||
|
(test-with-io
|
||||||
|
#:i [i (open-input-string "a b tmp (+ a b tmp)")]
|
||||||
|
#:o [o (open-output-string)]
|
||||||
|
(check-exn #rx"a: undefined;\n cannot use before initialization"
|
||||||
|
(λ () (f 1)))
|
||||||
|
(check-equal? (get-output-string o)
|
||||||
|
(string-append
|
||||||
|
"-> " #;b "4\n"
|
||||||
|
"-> " #;(+ b 13) "17\n"
|
||||||
|
"-> " #;(+ a b 13)))))
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
(require "../repl.rkt"
|
(require "../repl.rkt"
|
||||||
"test-util.rkt"
|
"test-util.rkt"
|
||||||
rackunit
|
rackunit)
|
||||||
(for-syntax racket/base syntax/parse))
|
|
||||||
|
|
||||||
(define a 3)
|
(define a 3)
|
||||||
(define b 4)
|
(define b 4)
|
||||||
|
@ -37,91 +36,6 @@
|
||||||
"-> "))
|
"-> "))
|
||||||
)
|
)
|
||||||
|
|
||||||
(test-case "local macros that refer to other macros"
|
|
||||||
(define (f tmp)
|
|
||||||
(define-syntax ?list
|
|
||||||
(syntax-parser
|
|
||||||
[(?list x:expr ...)
|
|
||||||
(define (?list-helper acc xs)
|
|
||||||
(syntax-parse (list acc xs)
|
|
||||||
[([acc:id ...] []) #'(list acc ...)]
|
|
||||||
[([acc:id ...] [x:expr y:expr ...])
|
|
||||||
#:with [tmp] (generate-temporaries #'[x])
|
|
||||||
#`(let ([tmp x])
|
|
||||||
(if tmp
|
|
||||||
#,(?list-helper #'[acc ... tmp] #'[y ...])
|
|
||||||
#false))]))
|
|
||||||
(?list-helper #'[] #'[x ...])]))
|
|
||||||
(debug-repl)
|
|
||||||
tmp)
|
|
||||||
|
|
||||||
(test-with-io
|
|
||||||
#:i [i (open-input-string "y a b c tmp (?list y a b c tmp)")]
|
|
||||||
#:o [o (open-output-string)]
|
|
||||||
(check-equal? (f 1) 1)
|
|
||||||
(check-equal? (get-output-string o)
|
|
||||||
(string-append
|
|
||||||
"-> " #;y "7\n"
|
|
||||||
"-> " #;a "3\n"
|
|
||||||
"-> " #;b "8\n"
|
|
||||||
"-> " #;c "9\n"
|
|
||||||
"-> " #;tmp "1\n"
|
|
||||||
"-> " #;(?list y a b c tmp) "'(7 3 8 9 1)\n"
|
|
||||||
"-> ")))
|
|
||||||
|
|
||||||
(test-with-io
|
|
||||||
#:i [i (open-input-string "(?list . bluh)")]
|
|
||||||
#:o [o (open-output-string)]
|
|
||||||
(check-exn #rx"\\?list: bad syntax"
|
|
||||||
(λ () (f 1)))
|
|
||||||
(check-equal? (get-output-string o)
|
|
||||||
(string-append
|
|
||||||
"-> " #;(?list. bluh)))))
|
|
||||||
|
|
||||||
;; TODO: !!! identifier used out of context !!!
|
|
||||||
#;
|
|
||||||
(test-case "local macros that refer to other macros"
|
|
||||||
(define (f tmp)
|
|
||||||
(define-syntax ?list-helper
|
|
||||||
(syntax-parser
|
|
||||||
[(?list-helper [acc:id ...] []) #'(list acc ...)]
|
|
||||||
[(?list-helper [acc:id ...] [x:expr y:expr ...])
|
|
||||||
#'(let ([tmp x])
|
|
||||||
(if tmp
|
|
||||||
(?list-helper [acc ... tmp] [y ...])
|
|
||||||
#false))]))
|
|
||||||
(define-syntax-rule (?list x ...)
|
|
||||||
(?list-helper [] [x ...]))
|
|
||||||
(debug-repl)
|
|
||||||
tmp)
|
|
||||||
|
|
||||||
(test-with-io
|
|
||||||
#:i [i (open-input-string "y a b c tmp (?list y a b c tmp)")]
|
|
||||||
#:o [o (open-output-string)]
|
|
||||||
(check-equal? (f 1) 1)
|
|
||||||
(check-equal? (get-output-string o)
|
|
||||||
(string-append
|
|
||||||
"-> " #;y "7\n"
|
|
||||||
"-> " #;a "3\n"
|
|
||||||
"-> " #;b "8\n"
|
|
||||||
"-> " #;c "9\n"
|
|
||||||
"-> " #;tmp "1\n"
|
|
||||||
"-> " #;(?list y a b c tmp) "'(7 3 8 9 1)\n"
|
|
||||||
"-> ")))
|
|
||||||
|
|
||||||
(test-with-io
|
|
||||||
#:i [i (open-input-string "y a b c tmp (+ y a b c tmp)")]
|
|
||||||
#:o [o (open-output-string)]
|
|
||||||
(check-exn #rx"a: undefined;\n cannot use before initialization"
|
|
||||||
(λ () (f 1)))
|
|
||||||
(check-equal? (get-output-string o)
|
|
||||||
(string-append
|
|
||||||
"-> " #;y "7\n"
|
|
||||||
"-> " #;b "8\n"
|
|
||||||
"-> " #;c "9\n"
|
|
||||||
"-> " #;(+ y b c) "24\n"
|
|
||||||
"-> " #;(+ y a b c)))))
|
|
||||||
|
|
||||||
;; test for issue #9
|
;; test for issue #9
|
||||||
(test-case "issue #9"
|
(test-case "issue #9"
|
||||||
(define (f)
|
(define (f)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user