aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/world/net/http/response.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test/lux/world/net/http/response.lux')
-rw-r--r--stdlib/source/test/lux/world/net/http/response.lux189
1 files changed, 189 insertions, 0 deletions
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))))))
+ ))))