From fe610fa47e06879c72b311acac088f60f1c51114 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 6 Nov 2011 21:46:26 +0900 Subject: [PATCH] Removing warnings in port.c, adding basic io tests. --- Makefile | 3 +++ lib/chibi/io/port.c | 5 ++-- tests/io-tests.scm | 56 +++++++++++++++++++++++++++++++++++++++++++++ tests/lib-tests.scm | 1 + 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 tests/io-tests.scm diff --git a/Makefile b/Makefile index f5bbe8f9..015ee9f3 100644 --- a/Makefile +++ b/Makefile @@ -259,6 +259,9 @@ test-flonums: chibi-scheme$(EXE) test-hash: chibi-scheme$(EXE) lib/srfi/69/hash$(SO) $(CHIBI) tests/hash-tests.scm +test-io: chibi-scheme$(EXE) lib/chibi/io/io$(SO) + $(CHIBI) tests/io-tests.scm + test-match: chibi-scheme$(EXE) $(CHIBI) tests/match-tests.scm diff --git a/lib/chibi/io/port.c b/lib/chibi/io/port.c index 2e3d3c87..58f5c539 100644 --- a/lib/chibi/io/port.c +++ b/lib/chibi/io/port.c @@ -19,6 +19,7 @@ #define sexp_cookie_seek_set(vec, x) sexp_vector_set((sexp)vec, SEXP_FOUR, x) #define sexp_cookie_close_set(vec, x) sexp_vector_set((sexp)vec, SEXP_FIVE, x) +#if SEXP_USE_STRING_STREAMS #if ! SEXP_USE_BOEHM static int in_heap_p (sexp_heap h, sexp p) { for ( ; h; h = h->next) @@ -124,7 +125,7 @@ static int sexp_cookie_cleaner (void *cookie) { return (sexp_exceptionp(res) ? -1 : sexp_truep(res)); } -#if (SEXP_USE_STRING_STREAMS && !SEXP_BSD) +#if !SEXP_BSD static cookie_io_functions_t sexp_cookie = { .read = (cookie_read_function_t*)sexp_cookie_reader, @@ -142,8 +143,6 @@ static cookie_io_functions_t sexp_cookie_no_seek = { #endif -#if SEXP_USE_STRING_STREAMS - static sexp sexp_make_custom_port (sexp ctx, sexp self, char *mode, sexp read, sexp write, sexp seek, sexp close) { diff --git a/tests/io-tests.scm b/tests/io-tests.scm new file mode 100644 index 00000000..57c5f1b3 --- /dev/null +++ b/tests/io-tests.scm @@ -0,0 +1,56 @@ + +(cond-expand + (modules (import (chibi io) (only (chibi test) test-begin test test-end))) + (else #f)) + +(test-begin "io") + +(define long-string (make-string 2000 #\a)) + +(test "input-string-port" 1025 + (call-with-input-string (substring long-string 0 1025) + (lambda (in) + (let loop ((c (read-char in)) (i 0)) + (cond ((eof-object? c) i) + ((> i 1025) (error "read past eof")) + (else (loop (read-char in) (+ i 1)))))))) + +(test "read-line" '("abc" "def") + (call-with-input-string "abc\ndef\n" + (lambda (in) (let ((line (read-line in))) (list line (read-line in)))))) + +(test "read-line-to-eof" '("abc" "def") + (call-with-input-string "abc\ndef" + (lambda (in) (let ((line (read-line in))) (list line (read-line in)))))) + +(test "null-output-port" #t + (let ((out (make-null-output-port))) + (write 1 out) + (close-output-port out) + #t)) + +(test "null-input-port" #t + (let ((in (make-concatenated-port))) + (let ((res (eof-object? (read-char in)))) + (close-input-port in) + res))) + +(define (string-upcase str) + (list->string (map char-upcase (string->list str)))) + +(test "upcase-input-port" "ABC" + (call-with-input-string "abc" + (lambda (in) + (let ((in (make-filtered-input-port string-upcase in))) + (let ((res (read-line in))) + (close-input-port in) + res))))) + +(test "upcase-output-port" "ABC" + (call-with-output-string + (lambda (out) + (let ((out (make-filtered-output-port string-upcase out))) + (display "abc" out) + (close-output-port out))))) + +(test-end) diff --git a/tests/lib-tests.scm b/tests/lib-tests.scm index 80f66d8d..6f3329b7 100644 --- a/tests/lib-tests.scm +++ b/tests/lib-tests.scm @@ -18,6 +18,7 @@ (load "tests/record-tests.scm") (load "tests/hash-tests.scm") (load "tests/sort-tests.scm") + (load "tests/io-tests.scm") (load "tests/thread-tests.scm"))) (else #f))