~ chicken-core (master) /tests/invalid-utf-test.scm
Trap1;;; ensure invalid UTF-8 sequences are reproducibly read and written
2
3(import (chicken io) (chicken irregex) (chicken file))
4(import (chicken bytevector) (chicken file posix))
5
6(define in "UTF-8-test.txt")
7(define out "UTF-8-test.out")
8
9(when (file-exists? out) (delete-file out))
10
11(with-input-from-file in
12 (lambda ()
13 (call-with-output-file out
14 (lambda (o)
15 (let loop ()
16 (let ((line (read-line)))
17 (unless (eof-object? line)
18 (display line o)
19 (newline o)
20 (loop)))))
21 #:unix))
22 #:unix)
23
24(define sz (file-size in))
25
26;(assert (= sz (file-size out)))
27(let ((old (with-input-from-file in (cut read-bytevector sz) #:binary))
28 (new (with-input-from-file out (cut read-bytevector sz) #:binary)))
29 (assert (bytevector=? old new)))