mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 14:19:18 +02:00
Removing warnings in port.c, adding basic io tests.
This commit is contained in:
parent
097ce7bfe0
commit
fe610fa47e
4 changed files with 62 additions and 3 deletions
3
Makefile
3
Makefile
|
@ -259,6 +259,9 @@ test-flonums: chibi-scheme$(EXE)
|
||||||
test-hash: chibi-scheme$(EXE) lib/srfi/69/hash$(SO)
|
test-hash: chibi-scheme$(EXE) lib/srfi/69/hash$(SO)
|
||||||
$(CHIBI) tests/hash-tests.scm
|
$(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)
|
test-match: chibi-scheme$(EXE)
|
||||||
$(CHIBI) tests/match-tests.scm
|
$(CHIBI) tests/match-tests.scm
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#define sexp_cookie_seek_set(vec, x) sexp_vector_set((sexp)vec, SEXP_FOUR, x)
|
#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)
|
#define sexp_cookie_close_set(vec, x) sexp_vector_set((sexp)vec, SEXP_FIVE, x)
|
||||||
|
|
||||||
|
#if SEXP_USE_STRING_STREAMS
|
||||||
#if ! SEXP_USE_BOEHM
|
#if ! SEXP_USE_BOEHM
|
||||||
static int in_heap_p (sexp_heap h, sexp p) {
|
static int in_heap_p (sexp_heap h, sexp p) {
|
||||||
for ( ; h; h = h->next)
|
for ( ; h; h = h->next)
|
||||||
|
@ -124,7 +125,7 @@ static int sexp_cookie_cleaner (void *cookie) {
|
||||||
return (sexp_exceptionp(res) ? -1 : sexp_truep(res));
|
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 = {
|
static cookie_io_functions_t sexp_cookie = {
|
||||||
.read = (cookie_read_function_t*)sexp_cookie_reader,
|
.read = (cookie_read_function_t*)sexp_cookie_reader,
|
||||||
|
@ -142,8 +143,6 @@ static cookie_io_functions_t sexp_cookie_no_seek = {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SEXP_USE_STRING_STREAMS
|
|
||||||
|
|
||||||
static sexp sexp_make_custom_port (sexp ctx, sexp self, char *mode,
|
static sexp sexp_make_custom_port (sexp ctx, sexp self, char *mode,
|
||||||
sexp read, sexp write,
|
sexp read, sexp write,
|
||||||
sexp seek, sexp close) {
|
sexp seek, sexp close) {
|
||||||
|
|
56
tests/io-tests.scm
Normal file
56
tests/io-tests.scm
Normal file
|
@ -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)
|
|
@ -18,6 +18,7 @@
|
||||||
(load "tests/record-tests.scm")
|
(load "tests/record-tests.scm")
|
||||||
(load "tests/hash-tests.scm")
|
(load "tests/hash-tests.scm")
|
||||||
(load "tests/sort-tests.scm")
|
(load "tests/sort-tests.scm")
|
||||||
|
(load "tests/io-tests.scm")
|
||||||
(load "tests/thread-tests.scm")))
|
(load "tests/thread-tests.scm")))
|
||||||
(else #f))
|
(else #f))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue