mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Flush when getting string from r6rs string output port
* module/rnrs/io/ports.scm (open-string-output-port): Calling the get-string proc should flush the buffer and reset the file position. * test-suite/tests/r6rs-ports.test ("8.2.10 Output ports"): Add tests. Thanks to Freja Nordsiek for the report.
This commit is contained in:
parent
1da66a6ab1
commit
e13cd5c77c
2 changed files with 20 additions and 1 deletions
|
@ -387,7 +387,11 @@ read from/written to in @var{port}."
|
|||
as a string, and a thunk to retrieve the characters associated with that port."
|
||||
(let ((port (open-output-string)))
|
||||
(values port
|
||||
(lambda () (get-output-string port)))))
|
||||
(lambda ()
|
||||
(let ((s (get-output-string port)))
|
||||
(seek port 0 SEEK_SET)
|
||||
(truncate-file port 0)
|
||||
s)))))
|
||||
|
||||
(define* (open-file-output-port filename
|
||||
#:optional
|
||||
|
|
|
@ -745,6 +745,21 @@ not `set-port-position!'"
|
|||
(with-test-prefix "open-file-output-port"
|
||||
(test-output-file-opener open-file-output-port (test-file)))
|
||||
|
||||
(pass-if "open-string-output-port"
|
||||
(call-with-values open-string-output-port
|
||||
(lambda (port proc)
|
||||
(and (port? port) (thunk? proc)))))
|
||||
|
||||
(pass-if-equal "calling string output port truncates port"
|
||||
'("hello" "" "world")
|
||||
(call-with-values open-string-output-port
|
||||
(lambda (port proc)
|
||||
(display "hello" port)
|
||||
(let* ((s1 (proc))
|
||||
(s2 (proc)))
|
||||
(display "world" port)
|
||||
(list s1 s2 (proc))))))
|
||||
|
||||
(pass-if "open-bytevector-output-port"
|
||||
(let-values (((port get-content)
|
||||
(open-bytevector-output-port #f)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue