Simplify + improve unicode testing code.

When the file is not found, use (current-load-relative-directory)
instead of having it end up in the working directory.
This commit is contained in:
Eli Barzilay 2013-07-05 18:05:25 -04:00
parent 328956e8b5
commit bc00e29602
2 changed files with 10 additions and 17 deletions

View File

@ -1,2 +0,0 @@
NormalizationTest.txt
NormalizationTest.txt

View File

@ -17,21 +17,16 @@
(define (get-test-file)
(define name "NormalizationTest.txt")
(define base "http://www.unicode.org/Public/5.0.0/ucd/")
(define (existing)
(let loop ([dirs (list (current-load-relative-directory)
(current-directory))])
(and (pair? dirs)
(let ([path (build-path (car dirs) name)])
(if (file-exists? path) path (loop (cdr dirs)))))))
(define (get-it)
(parameterize ([current-input-port
(get-pure-port (string->url (string-append base name)))])
(with-output-to-file name
(lambda () (copy-port (current-input-port) (current-output-port)))
#:exists 'truncate)))
(or (existing)
(begin (get-it) (existing))
(error "file not found: ~s" (string-append base name))))
(define here (current-load-relative-directory))
(or (for/or ([dir (list here (current-directory))])
(define path (build-path dir name))
(and (file-exists? path) path))
(let ([path (build-path here name)])
(with-output-to-file path
(lambda ()
(copy-port (get-pure-port (string->url (string-append base name)))
(current-output-port))))
path)))
(printf "Reading tests...\n")
(define test-strings