Has anyone written a nice "expect"-like macro?
Here's a very basic one I just cobbled up after learning r4rs macros;
any suggestions, improvements, or a better macro would be appreciated.
(define-syntax expect
(syntax-rules (default)
((expect string match-binding (default body1 body2 ...))
(begin body1 body2 ...))
((expect string match-binding (regexp body1 body2 ...))
(let ((match-binding (string-match regexp string)))
(if match-binding
(begin body1 body2 ...)
#f)))
((expect string match-binding (regexp body1 body2 ...) clause1
clause2 ...)
(let ((match-binding (string-match regexp string)))
(if match-binding
(begin body1 body2 ...)
(expect string match-binding clause1 clause2 ...))))))
(define (do-test str)
(expect str the-match
("foo(.*)" (match:substring the-match 1))
("^(.*) (.*)$" (list (match:substring the-match 1) (match:substring
the-match 2)))
(default #t)))
(do-test "foobar") -> "bar"
(do-test "hello world") -> '("hello" "world")
(do-test "baz") -> #t
|