diff options
author | Eduardo Julian | 2022-11-07 02:48:02 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-11-07 02:48:02 -0400 |
commit | 13c594758482bac0a7550bcb89cfeda8c5f0a1f3 (patch) | |
tree | 251236c17f3fe0fbd7b302d4f143e51a85539cf3 /stdlib/source/test | |
parent | ae4c0a4746d59b552ebeba166a43ce756dd265af (diff) |
Added support for inline testing.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/lux/test.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/test/inline.lux | 50 | ||||
-rw-r--r-- | stdlib/source/test/lux/test/tally.lux | 3 | ||||
-rw-r--r-- | stdlib/source/test/lux/world/net.lux | 15 | ||||
-rw-r--r-- | stdlib/source/test/lux/world/net/http/response.lux | 23 | ||||
-rw-r--r-- | stdlib/source/test/lux/world/net/uri.lux | 85 | ||||
-rw-r--r-- | stdlib/source/test/lux/world/net/uri/port.lux | 1 |
7 files changed, 157 insertions, 24 deletions
diff --git a/stdlib/source/test/lux/test.lux b/stdlib/source/test/lux/test.lux index 8d9be9f39..34891bf65 100644 --- a/stdlib/source/test/lux/test.lux +++ b/stdlib/source/test/lux/test.lux @@ -7,7 +7,8 @@ ["[1][0]" coverage] ["[1][0]" tally] ["[1][0]" unit] - ["[1][0]" property]]) + ["[1][0]" property] + ["[1][0]" inline]]) (def .public test Test @@ -16,4 +17,5 @@ /tally.test /unit.test /property.test + /inline.test )) diff --git a/stdlib/source/test/lux/test/inline.lux b/stdlib/source/test/lux/test/inline.lux new file mode 100644 index 000000000..e5cf9cfd6 --- /dev/null +++ b/stdlib/source/test/lux/test/inline.lux @@ -0,0 +1,50 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)]] + [control + ["[0]" try] + ["[0]" exception]] + [data + ["[0]" text]] + [math + ["[0]" random (.only Random) (.use "[1]#[0]" monad)]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" /]]) + +(/.static (random#in true)) +(/.static 123,456,789 (random#in true)) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + []) + (all _.and + (_.coverage [/.Test /.static] + true) + (_.coverage [/.dynamic] + (and (when (try (/.dynamic true)) + {try.#Success _} + true + + {try.#Failure _} + false) + (when (try (/.dynamic false)) + {try.#Success _} + false + + {try.#Failure _} + true))) + (_.coverage [/.failure] + (when (try (/.dynamic false)) + {try.#Success _} + false + + {try.#Failure error} + (text.contains? (the exception.#label /.failure) + error))) + ))) diff --git a/stdlib/source/test/lux/test/tally.lux b/stdlib/source/test/lux/test/tally.lux index a0c511680..3ac26f403 100644 --- a/stdlib/source/test/lux/test/tally.lux +++ b/stdlib/source/test/lux/test/tally.lux @@ -45,6 +45,9 @@ (n.= 1 (the /.#failures /.failure)) (n.= 0 (set.size (the /.#expected /.failure))) (n.= 0 (set.size (the /.#actual /.failure))))) + (_.coverage [/.failed?] + (and (/.failed? /.failure) + (not (/.failed? /.success)))) (_.coverage [/.and /.#expected /.#actual] (and (let [it (/.and /.success /.success)] (and (n.= 2 (the /.#successes it)) diff --git a/stdlib/source/test/lux/world/net.lux b/stdlib/source/test/lux/world/net.lux index ad3a3fa1e..ea22fbca4 100644 --- a/stdlib/source/test/lux/world/net.lux +++ b/stdlib/source/test/lux/world/net.lux @@ -11,6 +11,7 @@ ["[0]" /]] ["[0]" / ["[1][0]" mime] + ["[1][0]" uri] ["[1][0]" http ["[1]/[0]" client] ["[1]/[0]" cookie] @@ -18,13 +19,7 @@ ["[1]/[0]" status] ["[1]/[0]" version] ["[1]/[0]" response] - ["[1]/[0]" request]] - ["[1][0]" uri - ["[1]/[0]" encoding] - ["[1]/[0]" scheme] - ["[1]/[0]" port] - ["[1]/[0]" path] - ["[1]/[0]" query]]]) + ["[1]/[0]" request]]]) (def .public test Test @@ -49,9 +44,5 @@ /http/response.test /http/request.test - /uri/encoding.test - /uri/scheme.test - /uri/port.test - /uri/path.test - /uri/query.test + /uri.test ))) diff --git a/stdlib/source/test/lux/world/net/http/response.lux b/stdlib/source/test/lux/world/net/http/response.lux index 28d726a1f..bdefd87c2 100644 --- a/stdlib/source/test/lux/world/net/http/response.lux +++ b/stdlib/source/test/lux/world/net/http/response.lux @@ -65,7 +65,8 @@ .let [expected_css (css.rule selector.any (list [property.text_color (value.rgb color)]))]]) - (_.for [/.Response]) + (_.for [/.Response + /.#message /.#status]) (`` (all _.and (,, (with_template [<coverage> <response> <status> @@ -84,14 +85,14 @@ (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] + [/.empty (/.empty async.monad expected_status) expected_status 0 mime.utf_8] + [/.not_found (/.not_found async.monad) status.not_found 0 mime.utf_8] + [/.content (/.content async.monad expected_status expected_mime utf8_data) expected_status utf8_length expected_mime] + [/.bad_request (/.bad_request async.monad utf8) status.bad_request utf8_length mime.utf_8] + [/.ok (/.ok async.monad expected_mime utf8_data) status.ok utf8_length expected_mime] )) (_.coverage [/.temporary_redirect] - (let [response (/.temporary_redirect expected_url)] + (let [response (/.temporary_redirect async.monad expected_url)] (and (same? status.temporary_redirect (the /.#status response)) (|> response (the [/.#message //.#headers]) @@ -99,7 +100,7 @@ (try#each (text#= expected_url)) (try.else false))))) (in (do async.monad - [.let [response (/.text utf8)] + [.let [response (/.text async.monad utf8)] body ((the [/.#message //.#body] response) {.#None})] (unit.coverage [/.text] (and (same? status.ok (the /.#status response)) @@ -118,7 +119,7 @@ (binary#= utf8_data))) (try.else false)))))) (in (do async.monad - [.let [response (/.html expected_html) + [.let [response (/.html async.monad expected_html) data (|> expected_html html.html utf8#encoded) @@ -141,7 +142,7 @@ (binary#= data))) (try.else false)))))) (in (do async.monad - [.let [response (/.json expected_json) + [.let [response (/.json async.monad expected_json) data (|> expected_json json#encoded utf8#encoded) @@ -164,7 +165,7 @@ (binary#= data))) (try.else false)))))) (in (do async.monad - [.let [response (/.css expected_css) + [.let [response (/.css async.monad expected_css) data (|> expected_css css.css utf8#encoded) diff --git a/stdlib/source/test/lux/world/net/uri.lux b/stdlib/source/test/lux/world/net/uri.lux new file mode 100644 index 000000000..ef8d33f2d --- /dev/null +++ b/stdlib/source/test/lux/world/net/uri.lux @@ -0,0 +1,85 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)]] + [data + ["[0]" text (.only) + ["%" \\format]]] + [math + ["[0]" random (.only Random)]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" / (.only) + ["[0]" scheme] + ["[0]" query (.use "[1]#[0]" codec)]]] + ["[0]" / + ["[1][0]" encoding] + ["[1][0]" scheme] + ["[1][0]" port] + ["[1][0]" path] + ["[1][0]" query]]) + +(def user_info + (Random Text) + (do random.monad + [name (random.upper_cased 1) + password (random.upper_cased 2)] + (in (/.user_info name password)))) + +(def authority + (Random /.Authority) + (all random.and + (random.maybe ..user_info) + (random.lower_cased 3) + (random.maybe /port.random) + )) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [scheme /scheme.random + authority ..authority + path (random.lower_cased 4) + query (/query.random 5) + fragment (random.lower_cased 6)]) + (_.for [/.URI]) + (all _.and + (_.coverage [/.uri] + (let [it (/.uri scheme {.#None} path {.#Some query} {.#None})] + (and (text.contains? (scheme.name scheme) it) + (text.contains? path it) + (text.contains? (query#encoded query) it)))) + (_.coverage [/.Authority + /.#user /.#host /.#port + /.user_info] + (let [it (/.uri scheme {.#Some authority} path {.#None} {.#None})] + (and (text.contains? (scheme.name scheme) it) + (text.contains? path it) + (when (the /.#user authority) + {.#Some user} + (text.contains? user it) + + {.#None} + true) + (text.contains? (the /.#host authority) it) + (when (the /.#port authority) + {.#Some port} + (text.contains? (%.nat port) it) + + {.#None} + true)))) + (_.coverage [/.Fragment] + (let [it (/.uri scheme {.#None} path {.#None} {.#Some fragment})] + (and (text.contains? (scheme.name scheme) it) + (text.contains? path it) + (text.contains? fragment it)))) + + /encoding.test + /scheme.test + /port.test + /path.test + /query.test + ))) diff --git a/stdlib/source/test/lux/world/net/uri/port.lux b/stdlib/source/test/lux/world/net/uri/port.lux index d91dc1d5d..73ee68337 100644 --- a/stdlib/source/test/lux/world/net/uri/port.lux +++ b/stdlib/source/test/lux/world/net/uri/port.lux @@ -109,6 +109,7 @@ (<| (_.covering /._) (do [! random.monad] []) + (_.for [/.Port]) (`` (all _.and (_.coverage [(,, (with_template [<port>] [<port>] |