From e1b932ec27b1de95eba2708fdbd771e890339a66 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 5 Mar 2024 22:57:20 +0000 Subject: [PATCH] remove hardcoded filename in test event generator --- pkgs/ifwait/test-ifwait.fnl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pkgs/ifwait/test-ifwait.fnl b/pkgs/ifwait/test-ifwait.fnl index 17bb4a0..03dca1a 100644 --- a/pkgs/ifwait/test-ifwait.fnl +++ b/pkgs/ifwait/test-ifwait.fnl @@ -1,15 +1,21 @@ (local fennel (require :fennel)) -(fn event-fn [groups] - (let [data (with-open [e (io.open "events-fixture" "r")] (e:read "*a")) +(fn event-generator [events] + (coroutine.wrap + (fn [] + (each [_ e (ipairs events)] (coroutine.yield e))))) + +(fn file-events [path] + (let [data (with-open [e (io.open path "r")] (e:read "*a")) parse (fennel.parser data)] - (coroutine.wrap - (fn [] - (each [ok ast parse] - (if ok (coroutine.yield ast))))))) + (icollect [_ ast parse] + ast))) + (set _G.arg (doto ["-v" "dummy0" "up"] (tset 0 "test"))) (local ifwait (require :ifwait)) -(ifwait.run event-fn) + + +(ifwait.run #(event-generator (file-events "events-fixture")))