From 8c63a525089597af1f9282c76daf97bf2b6058e0 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 22 Oct 2022 12:43:39 -0400 Subject: New (optional) names for Frac type + fixed module of CSP concurrency. --- stdlib/source/library/lux.lux | 3 + .../source/library/lux/control/concurrency/cps.lux | 76 ------------------ .../source/library/lux/control/concurrency/csp.lux | 76 ++++++++++++++++++ stdlib/source/library/lux/ffi.jvm.lux | 2 +- stdlib/source/library/lux/ffi.old.lux | 2 +- .../library/lux/meta/target/jvm/constant.lux | 2 +- .../library/lux/meta/target/jvm/constant/pool.lux | 2 +- stdlib/source/library/lux/world/net/http.lux | 22 +----- .../source/library/lux/world/net/http/client.lux | 11 +-- .../source/library/lux/world/net/http/header.lux | 78 ++++++++++++++---- stdlib/source/library/lux/world/net/http/mime.lux | 22 ++++-- .../source/library/lux/world/net/http/status.lux | 6 +- stdlib/source/test/lux/control.lux | 4 +- stdlib/source/test/lux/control/concurrency/cps.lux | 92 ---------------------- stdlib/source/test/lux/control/concurrency/csp.lux | 92 ++++++++++++++++++++++ stdlib/source/test/lux/math/number/frac.lux | 2 +- stdlib/source/test/lux/world/input/keyboard.lux | 2 +- stdlib/source/test/lux/world/net.lux | 2 + stdlib/source/test/lux/world/net/http/client.lux | 5 +- stdlib/source/test/lux/world/net/http/header.lux | 73 +++++++++++++++++ stdlib/source/test/lux/world/net/http/status.lux | 1 + 21 files changed, 351 insertions(+), 224 deletions(-) delete mode 100644 stdlib/source/library/lux/control/concurrency/cps.lux create mode 100644 stdlib/source/library/lux/control/concurrency/csp.lux delete mode 100644 stdlib/source/test/lux/control/concurrency/cps.lux create mode 100644 stdlib/source/test/lux/control/concurrency/csp.lux create mode 100644 stdlib/source/test/lux/world/net/http/header.lux (limited to 'stdlib') diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index af8942f2e..e6aae9218 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -5830,3 +5830,6 @@ [Generation] [Declaration] ) + +(type .public F64 Frac) +(type .public Double Frac) diff --git a/stdlib/source/library/lux/control/concurrency/cps.lux b/stdlib/source/library/lux/control/concurrency/cps.lux deleted file mode 100644 index f8cd41a77..000000000 --- a/stdlib/source/library/lux/control/concurrency/cps.lux +++ /dev/null @@ -1,76 +0,0 @@ -(.require - [library - [lux (.except try) - [abstract - [functor (.only Functor)] - [monad (.only Monad do)]] - [control - ["[0]" try (.only Try) (.use "[1]#[0]" monad)] - ["[0]" exception (.only Exception)]]]] - [// - ["[0]" async (.only Async) (.use "[1]#[0]" monad)] - ["[0]" frp]]) - -(type .public (Process a) - (Async (Try a))) - -(type .public Channel' frp.Channel') -(type .public Channel frp.Channel) -(type .public Sink frp.Sink) - -(def .public channel - (All (_ a) (-> Any [(Channel a) (Sink a)])) - frp.channel) - -(def .public functor - (Functor Process) - (implementation - (def (each $) - (async#each (try#each $))))) - -(def .public monad - (Monad Process) - (implementation - (def functor ..functor) - (def in (|>> try#in async#in)) - (def (conjoint atatx) - (do async.monad - [tatx atatx] - (when tatx - {try.#Success atx} - atx - - {try.#Failure error} - (in {try.#Failure error})))))) - -(exception.def .public channel_has_been_closed) - -(def .public (read it) - (All (_ r w) - (-> (Channel' r w) (Process [r (Channel' r w)]))) - (let [[output resolver] (async.async [])] - (exec - (async.future - (async.upon! (function (_ head,tail) - (resolver (when head,tail - {.#Some [head tail]} - {try.#Success [head tail]} - - {.#None} - (exception.except ..channel_has_been_closed [])))) - it)) - output))) - -(def .public (write value sink) - (All (_ w) - (-> w (Sink w) (Process Any))) - (async.future (at sink feed value))) - -(def .public (close sink) - (All (_ w) - (-> (Sink w) (Process Any))) - (async.future (at sink close))) - -(def .public try - (All (_ a) (-> (Process a) (Process (Try a)))) - (async#each (|>> {try.#Success}))) diff --git a/stdlib/source/library/lux/control/concurrency/csp.lux b/stdlib/source/library/lux/control/concurrency/csp.lux new file mode 100644 index 000000000..f8cd41a77 --- /dev/null +++ b/stdlib/source/library/lux/control/concurrency/csp.lux @@ -0,0 +1,76 @@ +(.require + [library + [lux (.except try) + [abstract + [functor (.only Functor)] + [monad (.only Monad do)]] + [control + ["[0]" try (.only Try) (.use "[1]#[0]" monad)] + ["[0]" exception (.only Exception)]]]] + [// + ["[0]" async (.only Async) (.use "[1]#[0]" monad)] + ["[0]" frp]]) + +(type .public (Process a) + (Async (Try a))) + +(type .public Channel' frp.Channel') +(type .public Channel frp.Channel) +(type .public Sink frp.Sink) + +(def .public channel + (All (_ a) (-> Any [(Channel a) (Sink a)])) + frp.channel) + +(def .public functor + (Functor Process) + (implementation + (def (each $) + (async#each (try#each $))))) + +(def .public monad + (Monad Process) + (implementation + (def functor ..functor) + (def in (|>> try#in async#in)) + (def (conjoint atatx) + (do async.monad + [tatx atatx] + (when tatx + {try.#Success atx} + atx + + {try.#Failure error} + (in {try.#Failure error})))))) + +(exception.def .public channel_has_been_closed) + +(def .public (read it) + (All (_ r w) + (-> (Channel' r w) (Process [r (Channel' r w)]))) + (let [[output resolver] (async.async [])] + (exec + (async.future + (async.upon! (function (_ head,tail) + (resolver (when head,tail + {.#Some [head tail]} + {try.#Success [head tail]} + + {.#None} + (exception.except ..channel_has_been_closed [])))) + it)) + output))) + +(def .public (write value sink) + (All (_ w) + (-> w (Sink w) (Process Any))) + (async.future (at sink feed value))) + +(def .public (close sink) + (All (_ w) + (-> (Sink w) (Process Any))) + (async.future (at sink close))) + +(def .public try + (All (_ a) (-> (Process a) (Process (Try a)))) + (async#each (|>> {try.#Success}))) diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index 0f704a0cb..8db8186a6 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -1,6 +1,6 @@ (.require [library - [lux (.except Primitive Type Declaration int char is as type) + [lux (.except Primitive Type Declaration Double int char is as type) [abstract ["[0]" monad (.only do)]] [control diff --git a/stdlib/source/library/lux/ffi.old.lux b/stdlib/source/library/lux/ffi.old.lux index 7444e1d3a..d1922147b 100644 --- a/stdlib/source/library/lux/ffi.old.lux +++ b/stdlib/source/library/lux/ffi.old.lux @@ -1,6 +1,6 @@ (.require [library - [lux (.except is as type) + [lux (.except Double is as type) [abstract ["[0]" monad (.only Monad do)] ["[0]" enum]] diff --git a/stdlib/source/library/lux/meta/target/jvm/constant.lux b/stdlib/source/library/lux/meta/target/jvm/constant.lux index 3b77b382a..a24ae8cb8 100644 --- a/stdlib/source/library/lux/meta/target/jvm/constant.lux +++ b/stdlib/source/library/lux/meta/target/jvm/constant.lux @@ -1,6 +1,6 @@ (.require [library - [lux (.except) + [lux (.except Double) ["[0]" ffi (.only import)] [abstract [monad (.only do)] diff --git a/stdlib/source/library/lux/meta/target/jvm/constant/pool.lux b/stdlib/source/library/lux/meta/target/jvm/constant/pool.lux index 759d88314..bb57608a0 100644 --- a/stdlib/source/library/lux/meta/target/jvm/constant/pool.lux +++ b/stdlib/source/library/lux/meta/target/jvm/constant/pool.lux @@ -1,6 +1,6 @@ (.require [library - [lux (.except) + [lux (.except Double) ["[0]" ffi] [abstract [equivalence (.only Equivalence)] diff --git a/stdlib/source/library/lux/world/net/http.lux b/stdlib/source/library/lux/world/net/http.lux index 3c95a1c03..37d9c0fd4 100644 --- a/stdlib/source/library/lux/world/net/http.lux +++ b/stdlib/source/library/lux/world/net/http.lux @@ -8,13 +8,12 @@ [data [binary (.only Binary)]]]] [/ - [version (.only Version)]] + [version (.only Version)] + [status (.only Status)] + [header (.only Headers)]] [// (.only Address) [uri (.only URI) - [scheme (.only Scheme)]] - [// - ["[0]" environment - ["[1]" \\parser (.only Environment)]]]]) + [scheme (.only Scheme)]]]) (type .public Method (Variant @@ -28,19 +27,6 @@ {#Options} {#Trace})) -(type .public Status - Nat) - -(type .public Headers - Environment) - -(def .public empty - Headers - environment.empty) - -(type .public Header - (-> Headers Headers)) - (type .public (Body !) (-> (Maybe Nat) (! (Try [Nat Binary])))) diff --git a/stdlib/source/library/lux/world/net/http/client.lux b/stdlib/source/library/lux/world/net/http/client.lux index c11a8285d..49b376ee3 100644 --- a/stdlib/source/library/lux/world/net/http/client.lux +++ b/stdlib/source/library/lux/world/net/http/client.lux @@ -28,11 +28,12 @@ [syntax (.only syntax)] ["[0]" template]]]]] ["[0]" // (.only) + ["[0]" header (.only Headers)] [// (.only URL)]]) (type .public (Client !) (Interface - (is (-> //.Method URL //.Headers (Maybe Binary) + (is (-> //.Method URL Headers (Maybe Binary) (! (Try (//.Response !)))) request))) @@ -44,7 +45,7 @@ [(with_expansions [ (method_function )] (def .public ( url headers data client) (All (_ !) - (-> URL //.Headers (Maybe Binary) (Client !) + (-> URL Headers (Maybe Binary) (Client !) (! (Try (//.Response !))))) (at client request {} url headers data)))] @@ -173,9 +174,9 @@ output)))))))))) (def (default_headers connection) - (-> java/net/HttpURLConnection (IO (Try //.Headers))) + (-> java/net/HttpURLConnection (IO (Try Headers))) (loop (again [index +0 - headers //.empty]) + headers header.empty]) (do [! (try.with io.monad)] [?name (java/net/URLConnection::getHeaderFieldKey (ffi.as_int index) connection)] (when ?name @@ -242,5 +243,5 @@ {try.#Failure error}))))))) (def .public headers - (-> (List [Text Text]) //.Headers) + (-> (List [Text Text]) Headers) (dictionary.of_list text.hash)) diff --git a/stdlib/source/library/lux/world/net/http/header.lux b/stdlib/source/library/lux/world/net/http/header.lux index 91ad629a2..81c801924 100644 --- a/stdlib/source/library/lux/world/net/http/header.lux +++ b/stdlib/source/library/lux/world/net/http/header.lux @@ -1,35 +1,81 @@ (.require [library - [lux (.except) + [lux (.except has) [control - ["[0]" pipe]] + ["[0]" pipe] + ["[0]" try (.only Try)] + ["[0]" exception (.only Exception)]] [data [text - ["%" \\format (.only format)]] + ["%" \\format]] [collection - ["[0]" dictionary (.only Dictionary)]]]]] - [// (.only Header) + ["[0]" dictionary]]] + [math + [number + ["[0]" nat]]] + [world + ["[0]" environment + ["[1]" \\parser (.only Environment)]]]]] + [// ["[0]" mime (.only MIME)] [// (.only URL)]]) -(def .public (has name value) - (-> Text Text Header) - (dictionary.revised' name "" +(type .public Headers + Environment) + +(def .public empty + Headers + environment.empty) + +... https://developer.mozilla.org/en-US/docs/Glossary/HTTP_header +(type .public (Header of) + (Record + [#name Text + #in (-> of Text) + #out (-> Text (Try of))])) + +(exception.def .public (unknown [name]) + (Exception Text) + (exception.report + (list ["Name" (%.text name)]))) + +(def .public (one header it) + (All (_ of) + (-> (Header of) Headers + (Try of))) + (when (dictionary.value (the #name header) it) + {.#Some raw} + ((the #out header) raw) + + {.#None} + (exception.except ..unknown [(the #name header)]))) + +(def .public (has header value) + (All (_ of) + (-> (Header of) of Headers + Headers)) + (dictionary.revised' (the #name header) "" (|>> (pipe.when "" - value + ((the #in header) value) previous - (format previous "," value))))) + (%.format previous "," ((the #in header) value)))))) (def .public content_length - (-> Nat Header) - (|>> %.nat (..has "Content-Length"))) + (Header Nat) + [#name "Content-Length" + #in (at nat.decimal encoded) + #out (at nat.decimal decoded)]) (def .public content_type - (-> MIME Header) - (|>> mime.name (..has "Content-Type"))) + (Header MIME) + [#name "Content-Type" + #in mime.name + #out (|>> mime.mime {try.#Success})]) (def .public location - (-> URL Header) - (..has "Location")) + (Header URL) + [#name "Location" + #in (|>>) + #out (|>> {try.#Success})]) diff --git a/stdlib/source/library/lux/world/net/http/mime.lux b/stdlib/source/library/lux/world/net/http/mime.lux index 76a1fe51f..0ff909b96 100644 --- a/stdlib/source/library/lux/world/net/http/mime.lux +++ b/stdlib/source/library/lux/world/net/http/mime.lux @@ -1,12 +1,16 @@ (.require [library [lux (.except) + [abstract + ["[0]" equivalence (.only Equivalence)] + ["[0]" hash (.only Hash)]] [data - ["[0]" text - ["%" \\format (.only format)] + ["[0]" text (.only) + ["%" \\format] ["[0]" encoding (.only Encoding)]]] - [type - [primitive (.except)]]]]) + [meta + [type + [primitive (.except)]]]]]) (primitive .public MIME Text @@ -18,6 +22,14 @@ (def .public name (-> MIME Text) (|>> representation)) + + (def .public equivalence + (Equivalence MIME) + (at equivalence.functor each ..name text.equivalence)) + + (def .public hash + (Hash MIME) + (at hash.functor each ..name text.hash)) ) ... https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types @@ -93,7 +105,7 @@ (def .public (text encoding) (-> Encoding MIME) - (..mime (format "text/plain; charset=" text.double_quote (encoding.name encoding) text.double_quote))) + (..mime (%.format "text/plain; charset=" text.double_quote (encoding.name encoding) text.double_quote))) (def .public utf_8 MIME diff --git a/stdlib/source/library/lux/world/net/http/status.lux b/stdlib/source/library/lux/world/net/http/status.lux index 3a6b2fc67..b7b4151a9 100644 --- a/stdlib/source/library/lux/world/net/http/status.lux +++ b/stdlib/source/library/lux/world/net/http/status.lux @@ -1,7 +1,9 @@ (.require [library - [lux (.except)]] - [// (.only Status)]) + [lux (.except)]]) + +(type .public Status + Nat) ... https://en.wikipedia.org/wiki/List_of_HTTP_status_codes (with_template [ ] diff --git a/stdlib/source/test/lux/control.lux b/stdlib/source/test/lux/control.lux index a53c174d5..5a57ac13d 100644 --- a/stdlib/source/test/lux/control.lux +++ b/stdlib/source/test/lux/control.lux @@ -15,7 +15,7 @@ ["[1]/[0]" semaphore] ["[1]/[0]" stm] ["[1]/[0]" event] - ["[1]/[0]" cps] + ["[1]/[0]" csp] ["[1]/[0]" incremental] ["[1]/[0]" structured] ["[1]/[0]" behavioral]] @@ -50,7 +50,7 @@ /concurrency/semaphore.test /concurrency/stm.test /concurrency/event.test - /concurrency/cps.test + /concurrency/csp.test /concurrency/incremental.test /concurrency/structured.test /concurrency/behavioral.test diff --git a/stdlib/source/test/lux/control/concurrency/cps.lux b/stdlib/source/test/lux/control/concurrency/cps.lux deleted file mode 100644 index 5bf53cb96..000000000 --- a/stdlib/source/test/lux/control/concurrency/cps.lux +++ /dev/null @@ -1,92 +0,0 @@ -(.require - [library - [lux (.except) - [abstract - [monad (.only do)] - [\\specification - ["$[0]" functor (.only Injection Comparison)] - ["$[0]" monad]]] - [control - ["[0]" io] - ["[0]" try] - ["[0]" exception]] - [math - ["[0]" random]] - [test - ["_" property (.only Test)] - ["[0]" unit]]]] - [\\library - ["[0]" / (.only) - [// - ["[0]" async]]]]) - -(def injection - (Injection /.Process) - (at /.monad in)) - -(def comparison - (Comparison /.Process) - (function (_ == left right) - (io.run! - (do io.monad - [?left (async.value left) - ?right (async.value right)] - (in (when [?left ?right] - [{.#Some {try.#Success left}} - {.#Some {try.#Success right}}] - (== left right) - - _ - false)))))) - -(def .public test - Test - (<| (_.covering /._) - (do [! random.monad] - [expected random.nat] - (all _.and - (_.for [/.Process] - (all _.and - (_.for [/.functor] - ($functor.spec ..injection ..comparison /.functor)) - (_.for [/.monad] - ($monad.spec ..injection ..comparison /.monad)) - )) - (_.coverage [/.Channel /.Channel' /.Sink /.channel] - ... This is already been tested for the FRP module. - true) - (in (do async.monad - [it (do /.monad - [.let [[channel sink] (/.channel [])] - _ (/.write expected sink) - [actual channel] (/.read channel)] - (in (same? expected actual)))] - (unit.coverage [/.read /.write] - (try.else false it)))) - (in (do async.monad - [it (do /.monad - [.let [[channel sink] (/.channel [])] - _ (/.close sink) - it (/.try (/.write expected sink))] - (in (when it - {try.#Failure _} - true - - _ - false)))] - (unit.coverage [/.close /.try] - (try.else false it)))) - (in (do async.monad - [it (do /.monad - [.let [[channel sink] (/.channel [])] - _ (/.close sink) - it (/.try (/.read channel))] - (in (when it - {try.#Failure error} - (exception.match? /.channel_has_been_closed error) - - _ - false)))] - (unit.coverage [/.channel_has_been_closed] - (try.else false it)))) - )))) diff --git a/stdlib/source/test/lux/control/concurrency/csp.lux b/stdlib/source/test/lux/control/concurrency/csp.lux new file mode 100644 index 000000000..5bf53cb96 --- /dev/null +++ b/stdlib/source/test/lux/control/concurrency/csp.lux @@ -0,0 +1,92 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)] + [\\specification + ["$[0]" functor (.only Injection Comparison)] + ["$[0]" monad]]] + [control + ["[0]" io] + ["[0]" try] + ["[0]" exception]] + [math + ["[0]" random]] + [test + ["_" property (.only Test)] + ["[0]" unit]]]] + [\\library + ["[0]" / (.only) + [// + ["[0]" async]]]]) + +(def injection + (Injection /.Process) + (at /.monad in)) + +(def comparison + (Comparison /.Process) + (function (_ == left right) + (io.run! + (do io.monad + [?left (async.value left) + ?right (async.value right)] + (in (when [?left ?right] + [{.#Some {try.#Success left}} + {.#Some {try.#Success right}}] + (== left right) + + _ + false)))))) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [expected random.nat] + (all _.and + (_.for [/.Process] + (all _.and + (_.for [/.functor] + ($functor.spec ..injection ..comparison /.functor)) + (_.for [/.monad] + ($monad.spec ..injection ..comparison /.monad)) + )) + (_.coverage [/.Channel /.Channel' /.Sink /.channel] + ... This is already been tested for the FRP module. + true) + (in (do async.monad + [it (do /.monad + [.let [[channel sink] (/.channel [])] + _ (/.write expected sink) + [actual channel] (/.read channel)] + (in (same? expected actual)))] + (unit.coverage [/.read /.write] + (try.else false it)))) + (in (do async.monad + [it (do /.monad + [.let [[channel sink] (/.channel [])] + _ (/.close sink) + it (/.try (/.write expected sink))] + (in (when it + {try.#Failure _} + true + + _ + false)))] + (unit.coverage [/.close /.try] + (try.else false it)))) + (in (do async.monad + [it (do /.monad + [.let [[channel sink] (/.channel [])] + _ (/.close sink) + it (/.try (/.read channel))] + (in (when it + {try.#Failure error} + (exception.match? /.channel_has_been_closed error) + + _ + false)))] + (unit.coverage [/.channel_has_been_closed] + (try.else false it)))) + )))) diff --git a/stdlib/source/test/lux/math/number/frac.lux b/stdlib/source/test/lux/math/number/frac.lux index d76cbe5a5..9d6844441 100644 --- a/stdlib/source/test/lux/math/number/frac.lux +++ b/stdlib/source/test/lux/math/number/frac.lux @@ -275,7 +275,7 @@ (def .public test Test (<| (_.covering /._) - (_.for [.Frac]) + (_.for [.Frac .F64 .Double]) (all _.and (do random.monad [left random.safe_frac diff --git a/stdlib/source/test/lux/world/input/keyboard.lux b/stdlib/source/test/lux/world/input/keyboard.lux index 408e3f92c..d04d4dba0 100644 --- a/stdlib/source/test/lux/world/input/keyboard.lux +++ b/stdlib/source/test/lux/world/input/keyboard.lux @@ -155,7 +155,7 @@ )) - (_.for [/.Press] + (_.for [/.Press /.#input /.#pressed?] (`` (all _.and (,, (with_template [ ] [(do random.monad diff --git a/stdlib/source/test/lux/world/net.lux b/stdlib/source/test/lux/world/net.lux index f0c4acb39..252c6e077 100644 --- a/stdlib/source/test/lux/world/net.lux +++ b/stdlib/source/test/lux/world/net.lux @@ -12,6 +12,7 @@ ["[0]" / ["[1][0]" http ["[1]/[0]" client] + ["[1]/[0]" header] ["[1]/[0]" status] ["[1]/[0]" version]] ["[1][0]" uri @@ -33,6 +34,7 @@ true) /http/client.test + /http/header.test /http/status.test /http/version.test diff --git a/stdlib/source/test/lux/world/net/http/client.lux b/stdlib/source/test/lux/world/net/http/client.lux index aa8ed3b58..ce0a35e93 100644 --- a/stdlib/source/test/lux/world/net/http/client.lux +++ b/stdlib/source/test/lux/world/net/http/client.lux @@ -29,6 +29,7 @@ [\\library ["[0]" / (.only) ["/[1]" // (.only) + ["[0]" header] ["[1][0]" status]]]]) (def (verification ! expected response) @@ -102,7 +103,7 @@ (`` (all _.and (,, (with_template [ ] [(_.coverage [] - (|> ( "" //.empty {.#None} mock) + (|> ( "" header.empty {.#None} mock) (verification io.monad ) io.run!))] @@ -117,7 +118,7 @@ (in (do [! async.monad] [.let [mock (/.async mock)] (,, (with_template [ ] - [ (|> ( "" //.empty {.#None} mock) + [ (|> ( "" header.empty {.#None} mock) (verification ! ))] ))] diff --git a/stdlib/source/test/lux/world/net/http/header.lux b/stdlib/source/test/lux/world/net/http/header.lux new file mode 100644 index 000000000..6a3c48a99 --- /dev/null +++ b/stdlib/source/test/lux/world/net/http/header.lux @@ -0,0 +1,73 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)]] + [control + ["|" pipe] + ["[0]" try (.use "[1]#[0]" functor)] + ["[0]" exception]] + [data + ["[0]" text (.use "[1]#[0]" equivalence)]] + [math + ["[0]" random (.only Random) (.use "[1]#[0]" monad)] + [number + ["[0]" nat (.use "[1]#[0]" equivalence)]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" / (.only) + [// + ["[0]" mime (.use "[1]#[0]" equivalence)]]]]) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [expected_content_length random.nat + expected_content_type (random.either (random#in mime.javascript) + (random#in mime.jpeg)) + expected_location (random.either (random#in "http://example.com/yolo") + (random#in "http://example.com/meme")) + header_name (random.lower_case 1) + expected_header_value (random.upper_case 1) + .let [header (is (/.Header Text) + [/.#name header_name + /.#in (|>>) + /.#out (|>> {try.#Success})])]]) + (all _.and + (_.coverage [/.Headers /.empty /.unknown] + (|> /.empty + (/.one header) + (|.when + {try.#Success _} + false + + {try.#Failure error} + (exception.match? /.unknown error)))) + (_.coverage [/.Header /.#name /.#in /.#out + /.has /.one] + (|> /.empty + (/.has header expected_header_value) + (/.one header) + (try#each (same? expected_header_value)) + (try.else false))) + (_.coverage [/.content_length] + (|> /.empty + (/.has /.content_length expected_content_length) + (/.one /.content_length) + (try#each (nat#= expected_content_length)) + (try.else false))) + (_.coverage [/.content_type] + (|> /.empty + (/.has /.content_type expected_content_type) + (/.one /.content_type) + (try#each (mime#= expected_content_type)) + (try.else false))) + (_.coverage [/.location] + (|> /.empty + (/.has /.location expected_location) + (/.one /.location) + (try#each (text#= expected_location)) + (try.else false))) + ))) diff --git a/stdlib/source/test/lux/world/net/http/status.lux b/stdlib/source/test/lux/world/net/http/status.lux index e155c44a0..f2522222a 100644 --- a/stdlib/source/test/lux/world/net/http/status.lux +++ b/stdlib/source/test/lux/world/net/http/status.lux @@ -113,6 +113,7 @@ (def .public test Test (<| (_.covering /._) + (_.for [/.Status]) (`` (.all _.and (,, (with_template [ ] [] -- cgit v1.2.3