aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
authorEduardo Julian2022-10-28 23:11:52 -0400
committerEduardo Julian2022-10-28 23:11:52 -0400
commit736521eb56a45122eb0a545b677d3ffca1451080 (patch)
tree484221adf44f4cd5b9d0132fc41441d0ad098533 /stdlib/source/test
parent54d22bc41b874d52a94a96aafca18ab3a6357edb (diff)
Eliminated the .alias# extension. Now detecting aliases in .def#.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux/data/color/named.lux9
-rw-r--r--stdlib/source/test/lux/meta/type/resource.lux2
-rw-r--r--stdlib/source/test/lux/meta/type/row.lux56
-rw-r--r--stdlib/source/test/lux/world/net.lux4
-rw-r--r--stdlib/source/test/lux/world/net/http/client.lux3
-rw-r--r--stdlib/source/test/lux/world/net/http/response.lux189
-rw-r--r--stdlib/source/test/lux/world/net/http/status.lux21
7 files changed, 263 insertions, 21 deletions
diff --git a/stdlib/source/test/lux/data/color/named.lux b/stdlib/source/test/lux/data/color/named.lux
index 34a5a5a3d..4a9a633c9 100644
--- a/stdlib/source/test/lux/data/color/named.lux
+++ b/stdlib/source/test/lux/data/color/named.lux
@@ -3,6 +3,8 @@
[lux (.except)
[abstract
[monad (.only do)]]
+ [control
+ ["[0]" maybe]]
[data
[collection
["[0]" list]
@@ -214,6 +216,13 @@
(def unique_colors
(set.of_list //.hash ..all_colors))
+ (def .public random
+ (Random //.Color)
+ (do [! random.monad]
+ [choice (at ! each (n.% (set.size ..unique_colors))
+ random.nat)]
+ (in (maybe.trusted (list.item choice ..all_colors)))))
+
(def verdict
(n.= (list.size ..all_colors)
(set.size ..unique_colors)))
diff --git a/stdlib/source/test/lux/meta/type/resource.lux b/stdlib/source/test/lux/meta/type/resource.lux
index 33859dd4e..4b134ebbe 100644
--- a/stdlib/source/test/lux/meta/type/resource.lux
+++ b/stdlib/source/test/lux/meta/type/resource.lux
@@ -161,7 +161,7 @@
(syntax (_ [exception <code>.symbol
to_expand <code>.any])
(monad.do meta.monad
- [[_ _ exception] (meta.export exception)]
+ [[_ exception] (meta.export exception)]
(function (_ compiler)
{.#Right [compiler
(list (code.bit (when ((expansion.single to_expand) compiler)
diff --git a/stdlib/source/test/lux/meta/type/row.lux b/stdlib/source/test/lux/meta/type/row.lux
index fb2abf4de..b74441df1 100644
--- a/stdlib/source/test/lux/meta/type/row.lux
+++ b/stdlib/source/test/lux/meta/type/row.lux
@@ -112,7 +112,7 @@
(_.coverage [/.the]
(and (|> (/.row [@birth expected_birth
@life_span expected_life_span])
- (is Mortal)
+ (is (Mortal Any))
(/.the @birth)
(same? expected_birth))
(|> (/.row [@name expected_name
@@ -129,18 +129,48 @@
(/.the @id)
(same? expected_id))))
(_.coverage [/.has]
- (|> (/.row [@birth dummy_birth
- @life_span expected_life_span])
- (is Mortal)
- (/.has @birth expected_birth)
- (/.the @birth)
- (same? expected_birth)))
+ (and (|> (/.row [@birth dummy_birth
+ @life_span expected_life_span])
+ (is (Mortal Any))
+ (/.has @birth expected_birth)
+ (/.the @birth)
+ (same? expected_birth))
+ (|> (/.row [@name dummy_name
+ @birth expected_birth
+ @life_span expected_life_span])
+ (is (Human Any))
+ (/.has @name expected_name)
+ (/.the @name)
+ (same? expected_name))
+ (|> (/.row [@id dummy_id
+ @name expected_name
+ @birth expected_birth
+ @life_span expected_life_span])
+ (is (TransHuman Nat Any))
+ (/.has @id expected_id)
+ (/.the @id)
+ (same? expected_id))))
(_.coverage [/.revised]
- (|> (/.row [@birth dummy_birth
- @life_span expected_life_span])
- (is Mortal)
- (/.revised @birth (function (_ _) expected_birth))
- (/.the @birth)
- (same? expected_birth)))
+ (and (|> (/.row [@birth dummy_birth
+ @life_span expected_life_span])
+ (is (Mortal Any))
+ (/.revised @birth (function (_ _) expected_birth))
+ (/.the @birth)
+ (same? expected_birth))
+ (|> (/.row [@name dummy_name
+ @birth expected_birth
+ @life_span expected_life_span])
+ (is (Human Any))
+ (/.revised @name (function (_ _) expected_name))
+ (/.the @name)
+ (same? expected_name))
+ (|> (/.row [@id dummy_id
+ @name expected_name
+ @birth expected_birth
+ @life_span expected_life_span])
+ (is (TransHuman Nat Any))
+ (/.revised @id (function (_ _) expected_id))
+ (/.the @id)
+ (same? expected_id))))
))
)))
diff --git a/stdlib/source/test/lux/world/net.lux b/stdlib/source/test/lux/world/net.lux
index b2c286fc0..08c56fa4b 100644
--- a/stdlib/source/test/lux/world/net.lux
+++ b/stdlib/source/test/lux/world/net.lux
@@ -16,7 +16,8 @@
["[1]/[0]" cookie]
["[1]/[0]" header]
["[1]/[0]" status]
- ["[1]/[0]" version]]
+ ["[1]/[0]" version]
+ ["[1]/[0]" response]]
["[1][0]" uri
["[1]/[0]" encoding]
["[1]/[0]" scheme]
@@ -45,6 +46,7 @@
/http/header.test
/http/status.test
/http/version.test
+ /http/response.test
/uri/encoding.test
/uri/scheme.test
diff --git a/stdlib/source/test/lux/world/net/http/client.lux b/stdlib/source/test/lux/world/net/http/client.lux
index ed3eb915c..3eee7b77a 100644
--- a/stdlib/source/test/lux/world/net/http/client.lux
+++ b/stdlib/source/test/lux/world/net/http/client.lux
@@ -29,12 +29,13 @@
[\\library
["[0]" / (.only)
["/[1]" // (.only)
+ [response (.only Response)]
["[0]" header]
["[1][0]" status]]]])
(def (verification ! expected response)
(All (_ !)
- (-> (Monad !) Nat (! (Try (//.Response !)))
+ (-> (Monad !) Nat (! (Try (Response !)))
(! Bit)))
(do !
[response response]
diff --git a/stdlib/source/test/lux/world/net/http/response.lux b/stdlib/source/test/lux/world/net/http/response.lux
new file mode 100644
index 000000000..28d726a1f
--- /dev/null
+++ b/stdlib/source/test/lux/world/net/http/response.lux
@@ -0,0 +1,189 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ [monad (.only do)]]
+ [control
+ ["[0]" try (.use "[1]#[0]" functor)]
+ [concurrency
+ ["[0]" async]]]
+ [data
+ ["[0]" product]
+ ["[0]" binary (.use "[1]#[0]" equivalence)]
+ ["[0]" color
+ [named
+ ["[1]T" \\test]]]
+ ["[0]" text (.use "[1]#[0]" equivalence)
+ [encoding
+ ["[0]" utf8 (.use "[1]#[0]" codec)]]]
+ [format
+ ["[0]" html]
+ ["[0]" css (.only)
+ ["[0]" selector]
+ ["[0]" property]
+ ["[0]" value]]
+ ["[0]" json (.use "[1]#[0]" codec)
+ ["[1]T" \\test]]]]
+ [math
+ ["[0]" random (.only Random)]
+ [number
+ ["n" nat]]]
+ [test
+ ["_" property (.only Test)]
+ ["[0]" unit]]]]
+ [\\library
+ ["[0]" / (.only)
+ ["/[1]" // (.only)
+ ["[0]" header]
+ ["[0]" status]
+ [//
+ ["[0]" mime (.use "[1]#[0]" equivalence)]]]]]
+ [//
+ ["[0]T" status]
+ [//
+ ["[0]T" mime]]])
+
+(def .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [expected_status statusT.random
+ expected_mime mimeT.random
+
+ utf8_length (at ! each (n.% 10) random.nat)
+ utf8 (random.upper_cased utf8_length)
+ .let [utf8_data (utf8#encoded utf8)]
+
+ expected_url (at ! each (text.prefix "http://www.example.com/")
+ (random.upper_cased 1))
+
+ .let [expected_html (html.html/5
+ (html.head (html.title (html.text utf8)))
+ (html.body (html.paragraph (list) (html.text utf8))))]
+ expected_json jsonT.random
+ color colorT.random
+ .let [expected_css (css.rule selector.any
+ (list [property.text_color
+ (value.rgb color)]))]])
+ (_.for [/.Response])
+ (`` (all _.and
+ (,, (with_template [<coverage> <response>
+ <status>
+ <content_length> <content_type>]
+ [(_.coverage [<coverage>]
+ (let [response <response>]
+ (and (same? <status> (the /.#status response))
+ (|> response
+ (the [/.#message //.#headers])
+ (header.one header.content_length)
+ (try#each (n.= <content_length>))
+ (try.else false))
+ (|> response
+ (the [/.#message //.#headers])
+ (header.one header.content_type)
+ (try#each (mime#= <content_type>))
+ (try.else false)))))]
+
+ [/.empty (/.empty expected_status) expected_status 0 mime.utf_8]
+ [/.not_found /.not_found status.not_found 0 mime.utf_8]
+ [/.content (/.content expected_status expected_mime utf8_data) expected_status utf8_length expected_mime]
+ [/.bad_request (/.bad_request utf8) status.bad_request utf8_length mime.utf_8]
+ [/.ok (/.ok expected_mime utf8_data) status.ok utf8_length expected_mime]
+ ))
+ (_.coverage [/.temporary_redirect]
+ (let [response (/.temporary_redirect expected_url)]
+ (and (same? status.temporary_redirect (the /.#status response))
+ (|> response
+ (the [/.#message //.#headers])
+ (header.one header.location)
+ (try#each (text#= expected_url))
+ (try.else false)))))
+ (in (do async.monad
+ [.let [response (/.text utf8)]
+ body ((the [/.#message //.#body] response) {.#None})]
+ (unit.coverage [/.text]
+ (and (same? status.ok (the /.#status response))
+ (|> response
+ (the [/.#message //.#headers])
+ (header.one header.content_length)
+ (try#each (n.= utf8_length))
+ (try.else false))
+ (|> response
+ (the [/.#message //.#headers])
+ (header.one header.content_type)
+ (try#each (mime#= mime.utf_8))
+ (try.else false))
+ (|> body
+ (try#each (|>> product.right
+ (binary#= utf8_data)))
+ (try.else false))))))
+ (in (do async.monad
+ [.let [response (/.html expected_html)
+ data (|> expected_html
+ html.html
+ utf8#encoded)
+ length (binary.size data)]
+ body ((the [/.#message //.#body] response) {.#None})]
+ (unit.coverage [/.html]
+ (and (same? status.ok (the /.#status response))
+ (|> response
+ (the [/.#message //.#headers])
+ (header.one header.content_length)
+ (try#each (n.= length))
+ (try.else false))
+ (|> response
+ (the [/.#message //.#headers])
+ (header.one header.content_type)
+ (try#each (mime#= mime.html))
+ (try.else false))
+ (|> body
+ (try#each (|>> product.right
+ (binary#= data)))
+ (try.else false))))))
+ (in (do async.monad
+ [.let [response (/.json expected_json)
+ data (|> expected_json
+ json#encoded
+ utf8#encoded)
+ length (binary.size data)]
+ body ((the [/.#message //.#body] response) {.#None})]
+ (unit.coverage [/.json]
+ (and (same? status.ok (the /.#status response))
+ (|> response
+ (the [/.#message //.#headers])
+ (header.one header.content_length)
+ (try#each (n.= length))
+ (try.else false))
+ (|> response
+ (the [/.#message //.#headers])
+ (header.one header.content_type)
+ (try#each (mime#= mime.json))
+ (try.else false))
+ (|> body
+ (try#each (|>> product.right
+ (binary#= data)))
+ (try.else false))))))
+ (in (do async.monad
+ [.let [response (/.css expected_css)
+ data (|> expected_css
+ css.css
+ utf8#encoded)
+ length (binary.size data)]
+ body ((the [/.#message //.#body] response) {.#None})]
+ (unit.coverage [/.css]
+ (and (same? status.ok (the /.#status response))
+ (|> response
+ (the [/.#message //.#headers])
+ (header.one header.content_length)
+ (try#each (n.= length))
+ (try.else false))
+ (|> response
+ (the [/.#message //.#headers])
+ (header.one header.content_type)
+ (try#each (mime#= mime.css))
+ (try.else false))
+ (|> body
+ (try#each (|>> product.right
+ (binary#= data)))
+ (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 f2522222a..a7cb40039 100644
--- a/stdlib/source/test/lux/world/net/http/status.lux
+++ b/stdlib/source/test/lux/world/net/http/status.lux
@@ -1,11 +1,16 @@
(.require
[library
[lux (.except all)
+ [abstract
+ [monad (.only do)]]
+ [control
+ ["[0]" maybe]]
[data
[collection
["[0]" list]
["[0]" set (.only Set)]]]
[math
+ ["[0]" random (.only Random)]
[number
["n" nat]]]
[meta
@@ -14,8 +19,7 @@
[test
["_" property (.only Test)]]]]
[\\library
- ["[0]" / (.only)
- ["/[1]" //]]])
+ ["[0]" /]])
(with_expansions [<categories> (these [informational
[/.continue
@@ -85,9 +89,9 @@
/.not_extended
/.network_authentication_required]])]
(def all
- (List //.Status)
+ (List /.Status)
(list.together (`` (list (,, (with_template [<category> <status+>]
- [((is (-> Any (List //.Status))
+ [((is (-> Any (List /.Status))
(function (_ _)
(`` (list (,, (template.spliced <status+>))))))
123)]
@@ -95,9 +99,16 @@
<categories>))))))
(def unique
- (Set //.Status)
+ (Set /.Status)
(set.of_list n.hash ..all))
+ (def .public random
+ (Random /.Status)
+ (do [! random.monad]
+ [choice (at ! each (n.% (set.size ..unique))
+ random.nat)]
+ (in (maybe.trusted (list.item choice all)))))
+
(def verdict
(n.= (list.size ..all)
(set.size ..unique)))