1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-27 21:40:34 +02:00

New line or field iteration procedures in (ice-9 rdelim)

* NEWS: Update
* module/ice-9/rdelim (for-rdelim-from-port, for-delimited-from-port,
  for-line-in-file): New procedures.
* doc/ref/api-io.texi: Documentation of `for-rdelim-for-port`-related
  procedures.
* test-suite/tests/rdelim.test: Tests for `for-rdelim-for-port`-related
  procedures.

Signed-off-by: Mikael Djurfeldt <mikael@djurfeldt.com>
This commit is contained in:
Adam Faiz 2024-12-19 22:36:38 +01:00 committed by Mikael Djurfeldt
parent a9c079b13b
commit c2829e4a86
4 changed files with 96 additions and 2 deletions

View file

@ -20,7 +20,8 @@
(define-module (test-suite test-rdelim)
#:use-module (ice-9 rdelim)
#:use-module ((rnrs io ports) #:select (open-bytevector-input-port get-u8))
#:use-module (test-suite lib))
#:use-module (test-suite lib)
#:use-module (test-suite guile-test))
(with-test-prefix "read-line"
@ -247,6 +248,37 @@
(string=? (substring buf 0 len) s)
(string=? (substring buf len) ".")))))
(with-test-prefix "for-line-in-file"
(define (test-file)
(data-file-name "ports-test.tmp"))
(let ((lst '())
(lines '())
(string "line1\nline2\nline3")
(filename (test-file)))
(call-with-input-string
"A\0B\0C"
(lambda (port)
(pass-if "for-delimited-from-port parses stream correctly"
(for-delimited-from-port port
(lambda (entry)
(set! lst (cons entry lst)))
#:delims "\0")
(equal? lst '("C" "B" "A")))))
(let ((port (open-output-file filename)))
(display string port)
(close-port port))
(pass-if "for-line-in-file parses file correctly"
(for-line-in-file filename
(lambda (line)
(set! lines (cons line lines))))
(equal? lines '("line3" "line2" "line1"))))
(delete-file (test-file))
)
;;; Local Variables:
;;; eval: (put 'with-test-prefix 'scheme-indent-function 1)
;;; eval: (put 'pass-if 'scheme-indent-function 1)