aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/world
diff options
context:
space:
mode:
authorEduardo Julian2021-06-30 23:24:55 -0400
committerEduardo Julian2021-06-30 23:24:55 -0400
commit744ee69630de59ca3ba660b0aab6361cd17ce1b4 (patch)
tree329c11b8c3522c319c99ebd4d7c51ee0e7464bae /stdlib/source/test/lux/world
parent6633cd42f2892ea71530ddeeb93a7e7c0b59faa3 (diff)
"signature:" -> "interface:" & "structure:" -> "implementation:"
"signature" & "structure" feel like very ML-specific terminology and might not be easy on programmers unfamiliar with it.
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/world.lux6
-rw-r--r--stdlib/source/test/lux/world/console.lux2
-rw-r--r--stdlib/source/test/lux/world/net/http/client.lux84
-rw-r--r--stdlib/source/test/lux/world/shell.lux6
4 files changed, 93 insertions, 5 deletions
diff --git a/stdlib/source/test/lux/world.lux b/stdlib/source/test/lux/world.lux
index 62e0fc397..47e4ceb27 100644
--- a/stdlib/source/test/lux/world.lux
+++ b/stdlib/source/test/lux/world.lux
@@ -10,7 +10,10 @@
["#/." keyboard]]
["#." output #_
["#/." video #_
- ["#/." resolution]]]])
+ ["#/." resolution]]]
+ ["#." net #_
+ ["#/." http #_
+ ["#/." client]]]])
(def: #export test
Test
@@ -21,4 +24,5 @@
/program.test
/input/keyboard.test
/output/video/resolution.test
+ /net/http/client.test
))
diff --git a/stdlib/source/test/lux/world/console.lux b/stdlib/source/test/lux/world/console.lux
index 6c71f913c..56e3902f0 100644
--- a/stdlib/source/test/lux/world/console.lux
+++ b/stdlib/source/test/lux/world/console.lux
@@ -23,7 +23,7 @@
(def: simulation
(/.Simulation [Bit Text])
- (structure
+ (implementation
(def: (on_read [dead? content])
(do try.monad
[char (try.from_maybe (text.nth 0 content))
diff --git a/stdlib/source/test/lux/world/net/http/client.lux b/stdlib/source/test/lux/world/net/http/client.lux
new file mode 100644
index 000000000..0ac51bad0
--- /dev/null
+++ b/stdlib/source/test/lux/world/net/http/client.lux
@@ -0,0 +1,84 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [monad (#+ do)]]
+ [control
+ [pipe (#+ do>)]
+ ["." io (#+ IO)]
+ ["." try]
+ ["." function]]
+ [data
+ ["." binary]
+ ["." product]
+ [text
+ ["%" format (#+ format)]
+ [encoding
+ ["." utf8]]]]
+ [math
+ ["." random (#+ Random)]
+ [number
+ ["." nat]]]]
+ {1
+ ["." /
+ ["/#" //
+ ["#." status]]]})
+
+(def: #export test
+ Test
+ (<| (_.covering /._)
+ (_.for [/.Client])
+ (do random.monad
+ [on_post random.nat
+ on_get random.nat
+ on_put random.nat
+ on_patch random.nat
+ on_delete random.nat
+ on_head random.nat
+ on_connect random.nat
+ on_options random.nat
+ on_trace random.nat
+ #let [mock (: (/.Client IO)
+ (implementation
+ (def: (request method url headers data)
+ (io.io (let [value (case method
+ #//.Post on_post
+ #//.Get on_get
+ #//.Put on_put
+ #//.Patch on_patch
+ #//.Delete on_delete
+ #//.Head on_head
+ #//.Connect on_connect
+ #//.Options on_options
+ #//.Trace on_trace)
+ data (|> value
+ (\ nat.decimal encode)
+ (\ utf8.codec encode))]
+ (#try.Success [//status.ok
+ {#//.headers headers
+ #//.body (function (_ ?wanted_bytes)
+ (io.io (#try.Success [(binary.size data)
+ data])))}]))))))]]
+ (`` ($_ _.and
+ (~~ (template [<definition> <expected>]
+ [(_.cover [<definition>]
+ (|> (<definition> "" //.empty #.None mock)
+ (do> try.monad
+ [io.run]
+ [product.right (get@ #//.body) (function.apply #.None) io.run]
+ [product.right (\ utf8.codec decode)]
+ [(\ nat.decimal decode)]
+ [(nat.= <expected>) wrap])
+ (try.default false)))]
+
+ [/.post on_post]
+ [/.get on_get]
+ [/.put on_put]
+ [/.patch on_patch]
+ [/.delete on_delete]
+ [/.head on_head]
+ [/.connect on_connect]
+ [/.options on_options]
+ [/.trace on_trace]
+ ))
+ )))))
diff --git a/stdlib/source/test/lux/world/shell.lux b/stdlib/source/test/lux/world/shell.lux
index fa7d77f22..334250a96 100644
--- a/stdlib/source/test/lux/world/shell.lux
+++ b/stdlib/source/test/lux/world/shell.lux
@@ -35,7 +35,7 @@
(def: (simulation [environment working_directory command arguments])
(-> [Environment Path /.Command (List /.Argument)]
(/.Simulation Bit))
- (structure
+ (implementation
(def: (on_read dead?)
(if dead?
(exception.throw ..dead [])
@@ -65,14 +65,14 @@
(def: (io_shell command oops input destruction exit)
(-> /.Command Text Text Text /.Exit (/.Shell IO))
- (structure
+ (implementation
(def: execute
((debug.private /.can_execute)
(function (_ [environment working_directory command arguments])
(io.io
(#try.Success
(: (/.Process IO)
- (structure
+ (implementation
(def: read
((debug.private /.can_read)
(function (_ _)