From 634502e7246f8850ad6c649b79ae9f072f45baf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 11 Sep 2023 17:54:35 +0200 Subject: Introduce stream-split-by. This procedure isn't currently used, but as noted is really useful for grouping a character stream into a word stream, which is a later commit will use for it for justifying posibly infinite streams of text. --- tests/test/srfi-41-util.scm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/test/srfi-41-util.scm') diff --git a/tests/test/srfi-41-util.scm b/tests/test/srfi-41-util.scm index ff0e3cce..9a753b03 100644 --- a/tests/test/srfi-41-util.scm +++ b/tests/test/srfi-41-util.scm @@ -8,6 +8,7 @@ :use-module (srfi srfi-88) :use-module (srfi srfi-41 util) :use-module (srfi srfi-41) + :use-module ((srfi srfi-1) :select (circular-list)) :use-module ((ice-9 sandbox) :select (call-with-time-limit))) (test-equal "Finite stream" @@ -86,3 +87,22 @@ (test-equal "time limited stream" '(1 2 3) (stream->list strm)))) + + +(test-group "stream-split-by" + (let ((hello-chars-stream (stream-unfold + car + (const #t) + cdr + (apply circular-list + (string->list "Hello "))))) + (test-equal "Check that test list looks as expected" + (string->list "Hello Hell") + (stream->list 10 hello-chars-stream)) + (test-equal "Check that it splits correctly" + '("Hello " "Hello " "Hello ") + (stream->list + 3 + (stream-map list->string + (stream-split-by (lambda (c) (char=? c #\space)) + hello-chars-stream)))))) -- cgit v1.2.3