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 (get-test-file)
(define name "NormalizationTest.txt") (define name "NormalizationTest.txt")
(define base "http://www.unicode.org/Public/5.0.0/ucd/") (define base "http://www.unicode.org/Public/5.0.0/ucd/")
(define (existing) (define here (current-load-relative-directory))
(let loop ([dirs (list (current-load-relative-directory) (or (for/or ([dir (list here (current-directory))])
(current-directory))]) (define path (build-path dir name))
(and (pair? dirs) (and (file-exists? path) path))
(let ([path (build-path (car dirs) name)]) (let ([path (build-path here name)])
(if (file-exists? path) path (loop (cdr dirs))))))) (with-output-to-file path
(define (get-it) (lambda ()
(parameterize ([current-input-port (copy-port (get-pure-port (string->url (string-append base name)))
(get-pure-port (string->url (string-append base name)))]) (current-output-port))))
(with-output-to-file name path)))
(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))))
(printf "Reading tests...\n") (printf "Reading tests...\n")
(define test-strings (define test-strings