cripslock

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 12105544e26f3f24c10bed2618d1b1bf7cc45779
parent 2cbeb5efcdadfe1414a844959e77ada2f23dc741
Author: Daniel Barlow <dan@telent.net>
Date:   Tue, 15 Jul 2025 18:58:44 +0100

read blocks

Diffstat:
Atests/paras.txt | 8++++++++
Mtextile.fnl | 15+++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/tests/paras.txt b/tests/paras.txt @@ -0,0 +1,8 @@ +this is a paragraph + +this is +also a paragraph + +paragraphs are separated by blank lines + +the final para might not have a trailing blank line diff --git a/textile.fnl b/textile.fnl @@ -1,6 +1,21 @@ (import-macros { : define-tests : expect : expect= } :assert) +(fn read-blocks [stream] + (fn [] + (let [lines (icollect [l #(stream:read "L") + &until (= l "\n")] + l)] + (if (= (# lines) 0) + nil + (table.concat lines ""))))) +(define-tests :read-blocks + (with-open [f (io.open "tests/paras.txt" :r)] + (let [paras + (icollect [p (read-blocks f)] + p)] + (expect= (# paras) 4) + (expect= (. paras 2) "this is\nalso a paragraph\n")))) {}