From 1a86331335c0a26be2d19c939ba4e7f293793624 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Mon, 30 Jan 2017 22:57:24 +0900 Subject: [PATCH] making regexp tests portable --- lib/chibi/regexp-test.sld | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/chibi/regexp-test.sld b/lib/chibi/regexp-test.sld index deedf48f..6040bdab 100644 --- a/lib/chibi/regexp-test.sld +++ b/lib/chibi/regexp-test.sld @@ -1,7 +1,8 @@ (define-library (chibi regexp-test) (export run-tests) - (import (chibi) (chibi regexp) (chibi regexp pcre) - (chibi string) (chibi io) (chibi match) (chibi test)) + (import (scheme base) (scheme char) (scheme file) (scheme write) + (chibi regexp) (chibi regexp pcre) + (chibi string) (chibi match) (chibi test)) (begin (define (run-tests) (define (maybe-match->sexp rx str . o) @@ -237,6 +238,12 @@ (test " abc d ef " (regexp-replace-all '(+ space) " abc \t\n d ef " " ")) (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 (submatch n) (regexp-match-submatch matches n)) @@ -288,10 +295,11 @@ (error "invalid regex test line" line)))) (test-group "pcre" - (call-with-input-file "tests/re-tests.txt" - (lambda (in) - (for-each - (lambda (line) (test-pcre line)) - (port->list read-line in)))))) + (let ((in (open-input-file "tests/re-tests.txt"))) + (let lp () + (let ((line (read-line in))) + (unless (eof-object? line) + (test-pcre line) + (lp))))))) (test-end))))