(.require [library [lux (.except) [abstract [monad (.only do)]] [control ["[0]" maybe] ["[0]" try] ["[0]" exception] [concurrency ["[0]" async (.only Async)]]] [data ["[0]" text (.use "[1]#[0]" equivalence) ["%" \\format (.only format)]]] [math ["[0]" random]] [meta ["lux_[0]" version] [compiler ["[0]" version]]] [world ["[0]" console (.only Console Mock)]] [test ["[0]" unit] ["_" property (.only Test)]]]] [/// ["@[0]" profile]] [\\program ["[0]" /]]) (exception.def .public console_is_closed!) (def mock (Mock [Bit Text]) (implementation (def (on_read [open? state]) (if open? (try.of_maybe (do maybe.monad [head (text.char 0 state) [_ tail] (text.split_at 1 state)] (in [[open? tail] head]))) (exception.except ..console_is_closed! []))) (def (on_read_line [open? state]) (if open? (try.of_maybe (do maybe.monad [[output state] (text.split_by text.new_line state)] (in [[open? state] output]))) (exception.except ..console_is_closed! []))) (def (on_write input [open? state]) (if open? {try.#Success [open? (format state input)]} (exception.except ..console_is_closed! []))) (def (on_close [open? buffer]) (if open? {try.#Success [false buffer]} (exception.except ..console_is_closed! []))))) (def .public echo (-> Text (Console Async)) (|>> [true] (console.mock ..mock) console.async)) (def .public test Test (<| (_.covering /._) (do random.monad [profile @profile.random] (in (do async.monad [.let [console (..echo "")] verdict (do (try.with async.monad) [_ (/.do! console profile) logging (of console read_line [])] (in (text#= (version.format lux_version.latest) logging)))] (unit.coverage [/.do!] (try.else false verdict)))))))