(.module: [lux #* ["_" test (#+ Test)] [abstract [monad (#+ do)]] [control ["." try] ["." exception (#+ exception:)] [concurrency ["." promise (#+ Promise)]] [security ["!" capability]]] [data ["." maybe] ["." text ("#\." equivalence) ["%" format (#+ format)]]] [math ["." random]] [tool [compiler ["." version] ["." language #_ ["#/." lux #_ ["#" version]]]]] [world ["." console (#+ Console Simulation)]]] [/// ["@." profile]] {#program ["." /]}) (exception: #export console_is_closed!) (structure: simulation (Simulation [Bit Text]) (def: (on_read [open? state]) (if open? (try.from_maybe (do maybe.monad [head (text.nth 0 state) [_ tail] (text.split 1 state)] (wrap [[open? tail] head]))) (exception.throw ..console_is_closed! []))) (def: (on_read_line [open? state]) (if open? (try.from_maybe (do maybe.monad [[output state] (text.split_with text.new_line state)] (wrap [[open? state] output]))) (exception.throw ..console_is_closed! []))) (def: (on_write input [open? state]) (if open? (#try.Success [open? (format state input)]) (exception.throw ..console_is_closed! []))) (def: (on_close [open? buffer]) (if open? (#try.Success [false buffer]) (exception.throw ..console_is_closed! [])))) (def: #export echo (-> Text (Console Promise)) (|>> [true] (console.mock ..simulation) console.async)) (def: #export test Test (<| (_.covering /._) (do random.monad [profile @profile.random] (wrap (do promise.monad [#let [console (..echo "")] verdict (do (try.with promise.monad) [_ (/.do! console profile) logging (!.use (\ console read_line) [])] (wrap (text\= (version.format language/lux.version) logging)))] (_.cover' [/.do!] (try.default false verdict)))))))