Debian Codegraph @

scheme/tests/tests-4.2-req.scm

raw
1
2 (add-tests-with-string-output "eof-object"
3 [(eof-object? (eof-object)) => "#t\n"]
4
5 [(null? (eof-object)) => "#f\n"]
6 [(boolean? (eof-object)) => "#f\n"]
7 [(string? (eof-object)) => "#f\n"]
8 [(char? (eof-object)) => "#f\n"]
9 [(pair? (eof-object)) => "#f\n"]
10 [(symbol? (eof-object)) => "#f\n"]
11 [(procedure? (eof-object)) => "#f\n"]
12 [(vector? (eof-object)) => "#f\n"]
13 [(not (eof-object)) => "#f\n"]
14
15 [(eof-object? #\a) => "#f\n"]
16 [(eof-object? #t) => "#f\n"]
17 [(eof-object? 12) => "#f\n"]
18 [(eof-object? '(1 2 3)) => "#f\n"]
19 [(eof-object? '()) => "#f\n"]
20 [(eof-object? '#(foo)) => "#f\n"]
21 [(eof-object? (lambda (x) x)) => "#f\n"]
22 [(eof-object? 'baz) => "#f\n"]
23 )
24
25
26
27 (add-tests-with-string-output "read-char"
28 [(begin
29 (let ([p (open-output-file "stst.tmp" 'replace)])
30 (display "Hello World!" p)
31 (close-output-port p))
32 (let ([p (open-input-file "stst.tmp")])
33 (define loop
34 (lambda ()
35 (let ([x (read-char p)])
36 (if (eof-object? x)
37 (begin
38 (close-input-port p)
39 '())
40 (begin
41 (display x)
42 (loop))))))
43 (loop))
44 (exit))
45 => "Hello World!"]
46 [(let ([s (make-string 10000)]
47 [t "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz12344567890<>,./?;:'\"[]{}\\|`~!@#$%^&*()-_=+"])
48 (define fill-string!
49 (lambda (i j)
50 (unless (fx= i (string-length s))
51 (if (fx>= j (string-length t))
52 (fill-string! i (fx- j (string-length t)))
53 (begin
54 (string-set! s i (string-ref t j))
55 (fill-string! (fxadd1 i) (fx+ j 17)))))))
56 (define write-string!
57 (lambda (i p)
58 (cond
59 [(fx= i (string-length s)) (close-output-port p)]
60 [else
61 (write-char (string-ref s i) p)
62 (write-string! (fxadd1 i) p)])))
63 (define verify
64 (lambda (i p)
65 (let ([x (read-char p)])
66 (cond
67 [(eof-object? x)
68 (close-input-port p)
69 (fx= i (string-length s))]
70 [(fx= i (string-length s)) (error 'verify "file too short")]
71 [(char= (string-ref s i) x)
72 (verify (fxadd1 i) p)]
73 [else (error 'verify "mismatch")]))))
74 (fill-string! 0 0)
75 (write-string! 0 (open-output-file "stst.tmp" 'replace))
76 (verify 0 (open-input-file "stst.tmp"))) => "#t\n"]
77 )