compatibility/collects/tests/racket/awk.rkt
Sam Tobin-Hochstadt b40470205b loadtest.ss -> loadtest.rkt
original commit: 85fad33c4ce1a602c6b096d03513bf3e2bb1c2b8
2010-04-30 16:35:48 -04:00

39 lines
850 B
Racket

(load-relative "loadtest.rkt")
(Section 'awk)
(require mzlib/awk)
(define-syntax (test-awk stx)
(syntax-case stx ()
[(_ val body ...)
(with-syntax ([next (datum->syntax-object stx 'next)]
[result (datum->syntax-object stx 'result)])
(syntax
(let* ([p (open-input-string "Hello world.")]
[next (lambda () (let ([o (read p)])
(if (eof-object? o)
o
(symbol->string o))))]
[r null]
[result (lambda (v)
(set! r (append r (list v))))])
body ...
(test val 'awk r))))]))
(test-awk '(hi there)
(awk (next) (str) ()
["ell" (result 'hi)]
["x" (result 'yikes)]
["orl" (result 'there)]))
(test-awk '("l" done)
(awk (next) (str) ()
[/ "el(l)" / (#f a) (result a)]
[(equal? str "world.") (result 'done)]))
(report-errs)