From 608e6cc2a23fd5bae231a18f4f7443c9dab9b71c Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 26 Apr 2017 17:16:59 -0600 Subject: [PATCH] add tests for `racket/port` Also, fix some doc typos. --- .../scribblings/reference/string-input.scrbl | 6 +-- .../tests/racket/portlib.rktl | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/pkgs/racket-doc/scribblings/reference/string-input.scrbl b/pkgs/racket-doc/scribblings/reference/string-input.scrbl index cbd23d189c..a07e4e44b3 100644 --- a/pkgs/racket-doc/scribblings/reference/string-input.scrbl +++ b/pkgs/racket-doc/scribblings/reference/string-input.scrbl @@ -235,9 +235,9 @@ arguments. The four arguments correspond to the location of the special value within the port, as described in @secref["customport"]. If the procedure is called more than once with valid arguments, the @exnraise[exn:fail:contract]. If -@racket[read-bytes-avail] returns a special-producing procedure, then +@racket[read-bytes-avail!] returns a special-producing procedure, then it does not place characters in @racket[bstr]. Similarly, -@racket[read-bytes-avail] places only as many bytes into @racket[bstr] +@racket[read-bytes-avail!] places only as many bytes into @racket[bstr] as are available before a special value in the port's stream.} @defproc[(read-bytes-avail!* [bstr bytes?] @@ -351,7 +351,7 @@ case that @racket[progress] becomes ready before bytes are peeked.} Like @racket[read-bytes-avail!*], but for @tech{peek}ing, and with @racket[skip-bytes-amt] and @racket[progress] arguments like @racket[peek-bytes-avail!]. Since this procedure never blocks, it may -return before even @racket[skip-amt] bytes are available from the +return before even @racket[skip-bytes-amt] bytes are available from the port.} @defproc[(peek-bytes-avail!/enable-break [bstr (and/c bytes? (not/c immutable?))] diff --git a/pkgs/racket-test-core/tests/racket/portlib.rktl b/pkgs/racket-test-core/tests/racket/portlib.rktl index 13c558b750..a184f50d36 100644 --- a/pkgs/racket-test-core/tests/racket/portlib.rktl +++ b/pkgs/racket-test-core/tests/racket/portlib.rktl @@ -1201,4 +1201,43 @@ ;; -------------------------------------------------- +(let () + ;; Check `special-filter-input-port` + (define-values (i o) (make-pipe-with-specials)) + (define fi (special-filter-input-port + i + (lambda (proc bstr) + (bytes-set! bstr 0 (char->integer #\z)) + 1))) + (write-bytes #"abc" o) + (test #"abc" read-bytes 3 fi) + (write-special 'hello o) + (test #"z" read-bytes 1 fi) + (write-bytes #"ab" o) + (write-bytes #"c" o) + (write-special 'ok o) + (write-special 'bye o) + (test #"abczz" peek-bytes 5 0 fi) + (test #"abczz" peek-bytes 5 0 fi) + (test #"abcz" read-bytes 4 fi) + (define bstr (make-bytes 5)) + (test 1 peek-bytes-avail! bstr 0 #f fi) + (test #"z" subbytes bstr 0 1)) + +(let () + ;; Check `special-filter-input-port` with `peeking-input-port` + (define-values (i o) (make-pipe-with-specials)) + (define fi (special-filter-input-port + i + (lambda (proc bstr) + (bytes-set! bstr 0 (char->integer #\z)) + 1))) + (define pi (peeking-input-port fi)) + (write-bytes #"abc" o) + (write-special 'hello o) + (write-special 'again o) + (test #"abczz" peek-bytes 5 0 pi)) + +;; -------------------------------------------------- + (report-errs)