parent
9b6503df48
commit
8b65f4ac26
|
@ -657,19 +657,23 @@
|
|||
(list (make-bytes 200 32)
|
||||
(make-bytes 200 9)
|
||||
(make-bytes 200 (char->integer #\x))
|
||||
(make-bytes 201 (char->integer #\x))
|
||||
(make-bytes 202 (char->integer #\x))
|
||||
(make-bytes 203 (char->integer #\x))
|
||||
(make-bytes 204 (char->integer #\x))
|
||||
(list->bytes
|
||||
(let loop ([i 0])
|
||||
(if (= i 256)
|
||||
null
|
||||
(cons i (loop (add1 i))))))
|
||||
;; Something that doesn't end with a LF:
|
||||
(bytes-append
|
||||
(with-input-from-file (build-path dir "net.ss") (lambda () (read-bytes 500)))
|
||||
(bytes-append (with-input-from-file (build-path dir "net.ss")
|
||||
(lambda () (read-bytes 500)))
|
||||
#"xxx")
|
||||
;; CRLF:
|
||||
(regexp-replace
|
||||
#rx#"\n"
|
||||
(with-input-from-file (build-path dir "net.ss") (lambda () (read-bytes 500)))
|
||||
(regexp-replace #rx#"\r?\n"
|
||||
(with-input-from-file (build-path dir "net.ss")
|
||||
(lambda () (read-bytes 500)))
|
||||
#"\r\n"))))
|
||||
|
||||
(define (check-same encode decode port line-rx max-w)
|
||||
|
@ -685,8 +689,7 @@
|
|||
(unless (<= (bytes-length l) max-w)
|
||||
(test encode "line too long" l))
|
||||
(let ([m (regexp-match-positions line-rx l)])
|
||||
(unless (and m
|
||||
(= (bytes-length l) (cdar m)))
|
||||
(unless (and m (= (bytes-length l) (cdar m)))
|
||||
(test encode 'bad-line l)))
|
||||
(loop))))
|
||||
(let ([q (open-output-bytes)])
|
||||
|
@ -697,12 +700,11 @@
|
|||
(with-output-to-file "/tmp/x2" (lambda () (display bytes)) 'truncate)
|
||||
(error 'decode "failed")))))))
|
||||
|
||||
(define (check-same-file encode decode file line-rx max-w)
|
||||
(define ((check-same-file encode decode line-rx max-w) file)
|
||||
;; This "test" is really just a progress report:
|
||||
(test #t list? (list file encode))
|
||||
(call-with-input-file file
|
||||
(lambda (p)
|
||||
(check-same encode decode p line-rx max-w))))
|
||||
(lambda (p) (check-same encode decode p line-rx max-w))))
|
||||
|
||||
(define (check-same-all encode decode line-rx max-w)
|
||||
(for-each (lambda (tricky-string)
|
||||
|
@ -710,15 +712,18 @@
|
|||
(open-input-bytes tricky-string)
|
||||
line-rx max-w))
|
||||
tricky-strings)
|
||||
(parameterize ([current-pseudo-random-generator (make-pseudo-random-generator)])
|
||||
(random-seed 17)
|
||||
(let ([dir (collection-path "tests" "mzscheme")])
|
||||
(for-each (lambda (p)
|
||||
(when (regexp-match #rx"[.]ss$" (path->string p))
|
||||
(unless (or (positive? (random 10)) ; check random 1/10 of files
|
||||
(equal? (path->string p) "flat.ss"))
|
||||
(check-same-file encode decode (build-path dir p) line-rx max-w))))
|
||||
(directory-list dir)))))
|
||||
(let* ([dir (collection-path "tests" "mzscheme")]
|
||||
[files (filter-map (lambda (f)
|
||||
;; check 1/3 of the files, randomly
|
||||
(let ([p (build-path dir f)])
|
||||
(and (zero? (random 3))
|
||||
(not (regexp-match
|
||||
#rx"^flat.*\\.ss$"
|
||||
(path-element->string f)))
|
||||
(file-exists? p)
|
||||
p)))
|
||||
(directory-list dir))])
|
||||
(for-each (check-same-file encode decode line-rx max-w) files)))
|
||||
|
||||
(check-same-all (lambda (i o) (qp-encode-stream i o))
|
||||
qp-decode-stream
|
||||
|
@ -730,4 +735,32 @@
|
|||
#rx#"^[0-9a-zA-Z+=/]*$"
|
||||
72)
|
||||
|
||||
#|
|
||||
Use this to compare base64 encode/decode against the unix utilities
|
||||
(require net/base64 scheme/system)
|
||||
(define (base64-encode* bstr)
|
||||
(let ([o (open-output-bytes)])
|
||||
(parameterize ([current-output-port o]
|
||||
[current-input-port (open-input-bytes bstr)])
|
||||
(system "base64-encode"))
|
||||
(let* ([o (get-output-bytes o)]
|
||||
[o (regexp-replace #rx#"(.)(?:\r?\n)?$" o #"\\1\r\n")]
|
||||
[o (regexp-replace* #rx#"\r?\n" o #"\r\n")])
|
||||
o)))
|
||||
(define (base64-decode* bstr)
|
||||
(let ([o (open-output-bytes)])
|
||||
(parameterize ([current-output-port o]
|
||||
[current-input-port (open-input-bytes bstr)])
|
||||
(system "base64-decode"))
|
||||
(get-output-bytes o)))
|
||||
(define (check-base64-encode bstr)
|
||||
(equal? (base64-encode bstr) (base64-encode* bstr)))
|
||||
(define (check-base64-decode bstr)
|
||||
(equal? (base64-decode bstr) (base64-decode* bstr)))
|
||||
(define (check-base64-both bstr)
|
||||
(let ([en (base64-encode bstr)])
|
||||
(and (equal? en (base64-encode* bstr))
|
||||
(equal? (base64-decode en) (base64-decode* en)))))
|
||||
|#
|
||||
|
||||
(report-errs)
|
||||
|
|
Loading…
Reference in New Issue
Block a user