Added IO tests.

This commit is contained in:
Abdulaziz Ghuloum 2007-12-10 10:42:43 -05:00
parent 8a375a3cf7
commit 3575b0c8d8
3 changed files with 1772 additions and 139 deletions

View File

@ -32,6 +32,7 @@
(tests input-ports)
(tests fldiv-and-mod)
(tests parse-flonums)
(tests io)
)
(define (test-exact-integer-sqrt)
@ -69,4 +70,5 @@
(test-fxdiv0-and-mod0)
(test-fxlength)
(test-bitwise-bit-count)
(test-io)
(printf "Happy Happy Joy Joy\n")

1640
scheme/tests/SRFI-1.ss Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +1,8 @@
#!/usr/bin/env scheme-script
(import
(library (tests io)
(export test-io)
(import (ikarus))
(except (ikarus) get-char peek-char read-char
get-u8 lookahead-u8 close-port
input-port? open-string-input-port output-port?
standard-input-port current-input-port
get-bytevector-n get-bytevector-n!
get-string-n get-string-n! get-line port?
close-input-port close-output-port flush-output-port
open-input-file call-with-input-file with-input-from-file
put-char put-u8 open-bytevector-output-port
call-with-bytevector-output-port open-string-output-port
write-char current-output-port current-error-port
standard-output-port standard-error-port put-string)
(io-spec))
(define-syntax test
(syntax-rules ()
@ -139,6 +126,7 @@
[else
(error #f "incorrect value returned" i)])))
(define (test-custom-binary-input-ports)
(test "reading 256 bytes in ascending order"
(test-get-u8-1 (make-n-byte-custom-binary-input-port 256) 256))
@ -212,7 +200,7 @@
(test-textual-port-eof?-1
(open-bytevector-input-port (make-ascii-range-bytevector)
(make-transcoder (utf-8-codec) 'none 'raise))
128))
128)))
(define (make-utf8-bytevector-range2)
(u8-list->bytevector
@ -405,7 +393,6 @@
i
(f (+ i 1))))))))
(assert (= (file-size "SRFI-1.ss") 56573))
(define (file->bytevector filename)
(let ([p (open-file-input-port filename (file-options) 'block #f)])
@ -428,14 +415,16 @@
(put-char p (integer->char (bytevector-u8-ref bv i)))
(f (fx+ i 1)))))
(let ([bv (file->bytevector "SRFI-1.ss")])
(define (test-input-files)
(assert (= (file-size "tests/SRFI-1.ss") 56573))
(let ([bv (file->bytevector "tests/SRFI-1.ss")])
(let-values ([(p extract) (open-bytevector-output-port #f)])
(bytevector->binary-port bv p)
(let ([bv2 (extract)])
(assert (bytevector=? bv bv2))
(assert (bytevector=? #vu8() (extract))))))
(let ([bv (file->bytevector "SRFI-1.ss")])
(let ([bv (file->bytevector "tests/SRFI-1.ss")])
(let-values ([(p extract) (open-bytevector-output-port
(native-transcoder))])
(bytevector->textual-port bv p)
@ -443,7 +432,7 @@
(assert (bytevector=? bv bv2))
(assert (bytevector=? #vu8() (extract))))))
(let ([bv (file->bytevector "SRFI-1.ss")])
(let ([bv (file->bytevector "tests/SRFI-1.ss")])
(let-values ([(p extract) (open-bytevector-output-port
(make-transcoder (latin-1-codec)))])
(bytevector->textual-port bv p)
@ -451,7 +440,7 @@
(assert (bytevector=? bv bv2))
(assert (bytevector=? #vu8() (extract))))))
(let ([bv (file->bytevector "SRFI-1.ss")])
(let ([bv (file->bytevector "tests/SRFI-1.ss")])
(let-values ([(p extract) (open-string-output-port)])
(bytevector->textual-port bv p)
(let ([str (extract)])
@ -472,10 +461,12 @@
(let ([p (current-output-port)])
(put-string p "HELLO THERE\n")
(flush-output-port p))
(flush-output-port p)))
(open-file-output-port "bar" (file-options no-truncate))
;(run-exhaustive-tests)
(define (test-io)
(test-custom-binary-input-ports)
(run-exhaustive-tests)
(test-input-files))
)
;(run-interactive-tests)