making regexp tests portable

This commit is contained in:
Alex Shinn 2017-01-30 22:57:24 +09:00
parent 812dc59b20
commit 1a86331335

View file

@ -1,7 +1,8 @@
(define-library (chibi regexp-test) (define-library (chibi regexp-test)
(export run-tests) (export run-tests)
(import (chibi) (chibi regexp) (chibi regexp pcre) (import (scheme base) (scheme char) (scheme file) (scheme write)
(chibi string) (chibi io) (chibi match) (chibi test)) (chibi regexp) (chibi regexp pcre)
(chibi string) (chibi match) (chibi test))
(begin (begin
(define (run-tests) (define (run-tests)
(define (maybe-match->sexp rx str . o) (define (maybe-match->sexp rx str . o)
@ -237,6 +238,12 @@
(test " abc d ef " (regexp-replace-all '(+ space) " abc \t\n d ef " " ")) (test " abc d ef " (regexp-replace-all '(+ space) " abc \t\n d ef " " "))
(let () (let ()
(define (call-with-input-string str proc)
(proc (open-input-string str)))
(define (call-with-output-string proc)
(let ((out (open-output-string)))
(proc out)
(get-output-string out)))
(define (subst-matches matches input subst) (define (subst-matches matches input subst)
(define (submatch n) (define (submatch n)
(regexp-match-submatch matches n)) (regexp-match-submatch matches n))
@ -288,10 +295,11 @@
(error "invalid regex test line" line)))) (error "invalid regex test line" line))))
(test-group "pcre" (test-group "pcre"
(call-with-input-file "tests/re-tests.txt" (let ((in (open-input-file "tests/re-tests.txt")))
(lambda (in) (let lp ()
(for-each (let ((line (read-line in)))
(lambda (line) (test-pcre line)) (unless (eof-object? line)
(port->list read-line in)))))) (test-pcre line)
(lp)))))))
(test-end)))) (test-end))))