make file-stream-port? and terminal-port? total
This commit is contained in:
parent
66f7e0c3e3
commit
3c4f160346
|
@ -47,16 +47,24 @@ determines an output port that is typically used for errors and
|
|||
logging. For example, the default error display handler writes to this
|
||||
port.}
|
||||
|
||||
@defproc[(file-stream-port? [port port?]) boolean?]{
|
||||
Returns @racket[#t] if the given port is a @tech{file-stream port} (see
|
||||
@secref["file-ports"]), @racket[#f] otherwise.}
|
||||
@defproc[(file-stream-port? [v any/c]) boolean?]{
|
||||
Returns @racket[#t] if @racket[v] is a @tech{file-stream port} (see
|
||||
@secref["file-ports"]), @racket[#f] otherwise.
|
||||
|
||||
@defproc[(terminal-port? [port port?]) boolean?]{
|
||||
Returns @racket[#t] if the given port is attached to an interactive
|
||||
terminal, @racket[#f] otherwise.}
|
||||
@history[#:changed "7.2.0.5" @elem{Extended @racket[file-stream-port?]
|
||||
to any value, instead of resticting
|
||||
the domain to ports}]}
|
||||
|
||||
@defproc[(terminal-port? [v any/c]) boolean?]{
|
||||
Returns @racket[#t] if @racket[v] is a port that is attached to an
|
||||
interactive terminal, @racket[#f] otherwise.
|
||||
|
||||
@history[#:changed "7.2.0.5" @elem{Extended @racket[terminal-port?]
|
||||
to any value, instead of resticting
|
||||
the domain to ports}]}
|
||||
|
||||
@defthing[eof eof-object?]{A value (distinct from all other values)
|
||||
that represents an end-of-file.}
|
||||
|
||||
@defproc[(eof-object? [a any/c]) boolean?]{Returns @racket[#t] if
|
||||
@defproc[(eof-object? [v any/c]) boolean?]{Returns @racket[#t] if
|
||||
@racket[v] is @racket[eof], @racket[#f] otherwise.}
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
(define work-dir (make-temporary-file "path~a" 'directory))
|
||||
(current-directory work-dir)
|
||||
|
||||
(test #t port? (current-input-port))
|
||||
(test #t port? (current-output-port))
|
||||
(test #t input-port? (current-input-port))
|
||||
(test #t output-port? (current-output-port))
|
||||
(test #t output-port? (current-error-port))
|
||||
|
@ -18,16 +20,40 @@
|
|||
(test (void) current-output-port (current-output-port))
|
||||
(test (void) current-error-port (current-error-port))
|
||||
(test #t call-with-input-file testing.rktl input-port?)
|
||||
|
||||
(test #f port? 7)
|
||||
(test #f input-port? 7)
|
||||
(test #f output-port? 7)
|
||||
(test #f terminal-port? 7)
|
||||
(test #f file-stream-port? 7)
|
||||
|
||||
(define this-file (open-input-file testing.rktl))
|
||||
(test #t port? this-file)
|
||||
(test #t input-port? this-file)
|
||||
(test #f output-port? this-file)
|
||||
(test #f terminal-port? this-file)
|
||||
(test #t file-stream-port? this-file)
|
||||
(close-input-port this-file)
|
||||
|
||||
(define this-file (open-input-file testing.rktl #:mode 'binary))
|
||||
(test #t port? this-file)
|
||||
(test #t input-port? this-file)
|
||||
(test #f output-port? this-file)
|
||||
(test #f terminal-port? this-file)
|
||||
(test #t file-stream-port? this-file)
|
||||
(close-input-port this-file)
|
||||
|
||||
(define this-file (open-input-file testing.rktl #:mode 'text))
|
||||
(test #t port? this-file)
|
||||
(test #t input-port? this-file)
|
||||
(test #f output-port? this-file)
|
||||
(test #f terminal-port? this-file)
|
||||
(test #t file-stream-port? this-file)
|
||||
(arity-test port? 1 1)
|
||||
(arity-test input-port? 1 1)
|
||||
(arity-test output-port? 1 1)
|
||||
(arity-test terminal-port? 1 1)
|
||||
(arity-test file-stream-port? 1 1)
|
||||
(arity-test current-input-port 0 1)
|
||||
(arity-test current-output-port 0 1)
|
||||
(arity-test current-error-port 0 1)
|
||||
|
@ -61,6 +87,7 @@
|
|||
(err/rt-test (close-output-port 5))
|
||||
(err/rt-test (close-input-port (current-output-port)))
|
||||
(err/rt-test (close-output-port (current-input-port)))
|
||||
|
||||
(define (check-test-file name)
|
||||
(define test-file (open-input-file name))
|
||||
(test #t 'input-port?
|
||||
|
|
|
@ -12,11 +12,7 @@
|
|||
(make-struct-type-property 'file-stream))
|
||||
|
||||
(define (file-stream-port? p)
|
||||
(and (file-stream-ref
|
||||
(or (->core-input-port p #:default #f)
|
||||
(->core-output-port p #:default #f)
|
||||
(raise-argument-error 'file-stream-port?
|
||||
"port?"
|
||||
p))
|
||||
#f)
|
||||
#t))
|
||||
(define core-port (or (->core-input-port p #:default #f)
|
||||
(->core-output-port p #:default #f))
|
||||
(and (file-stream-ref core-port #f) #t))
|
||||
|
||||
|
|
|
@ -3291,8 +3291,6 @@ scheme_file_stream_port_p (int argc, Scheme_Object *argv[])
|
|||
return scheme_true;
|
||||
else if (SAME_OBJ(op->sub_type, fd_output_port_type))
|
||||
return scheme_true;
|
||||
} else {
|
||||
scheme_wrong_contract("file-stream-port?", "port?", 0, argc, argv);
|
||||
}
|
||||
|
||||
return scheme_false;
|
||||
|
|
Loading…
Reference in New Issue
Block a user