aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/lux/meta/global.lux40
-rw-r--r--stdlib/source/test/lux/test/tally.lux6
-rw-r--r--stdlib/source/test/lux/world/net.lux2
-rw-r--r--stdlib/source/test/lux/world/net/http/cookie.lux113
-rw-r--r--stdlib/source/test/lux/world/net/http/header.lux18
5 files changed, 175 insertions, 4 deletions
diff --git a/stdlib/source/test/lux/meta/global.lux b/stdlib/source/test/lux/meta/global.lux
new file mode 100644
index 000000000..9ee42b9f9
--- /dev/null
+++ b/stdlib/source/test/lux/meta/global.lux
@@ -0,0 +1,40 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ [monad (.only do)]]
+ [math
+ ["[0]" random (.only Random)]
+ [number
+ ["n" nat]]]
+ [meta
+ ["[0]" static]
+ ["[0]" code]]
+ [test
+ ["_" property (.only Test)]]]]
+ [\\library
+ ["[0]" /]])
+
+(with_expansions [<before> (static.random_nat)
+ <after> (static.random code.nat
+ (random.only (|>> (n.= <before>) not) random.nat))]
+ (def my_global
+ Nat
+ <before>)
+
+ (/.with [..my_global <after>]
+ (def my_local
+ Nat
+ (n.+ my_global my_global)))
+
+ (def .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [])
+ (all _.and
+ (_.coverage [/.with]
+ (and (n.= (n.+ <after> <after>) my_local)
+ (not (n.= (n.+ <before> <before>) my_local))))
+ )))
+ )
diff --git a/stdlib/source/test/lux/test/tally.lux b/stdlib/source/test/lux/test/tally.lux
index c1d43ad79..a0c511680 100644
--- a/stdlib/source/test/lux/test/tally.lux
+++ b/stdlib/source/test/lux/test/tally.lux
@@ -35,17 +35,17 @@
(n.= 0 (the /.#failures /.empty))
(n.= 0 (set.size (the /.#expected /.empty)))
(n.= 0 (set.size (the /.#actual /.empty)))))
- (_.coverage [/.success]
+ (_.coverage [/.success /.#successes]
(and (n.= 1 (the /.#successes /.success))
(n.= 0 (the /.#failures /.success))
(n.= 0 (set.size (the /.#expected /.success)))
(n.= 0 (set.size (the /.#actual /.success)))))
- (_.coverage [/.failure]
+ (_.coverage [/.failure /.#failures]
(and (n.= 0 (the /.#successes /.failure))
(n.= 1 (the /.#failures /.failure))
(n.= 0 (set.size (the /.#expected /.failure)))
(n.= 0 (set.size (the /.#actual /.failure)))))
- (_.coverage [/.and]
+ (_.coverage [/.and /.#expected /.#actual]
(and (let [it (/.and /.success /.success)]
(and (n.= 2 (the /.#successes it))
(n.= 0 (the /.#failures it))))
diff --git a/stdlib/source/test/lux/world/net.lux b/stdlib/source/test/lux/world/net.lux
index 53788fd79..f9b3417ed 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]" cookie]
["[1]/[0]" header]
["[1]/[0]" status]
["[1]/[0]" version]]
@@ -35,6 +36,7 @@
true)
/http/client.test
+ /http/cookie.test
/http/header.test
/http/status.test
/http/version.test
diff --git a/stdlib/source/test/lux/world/net/http/cookie.lux b/stdlib/source/test/lux/world/net/http/cookie.lux
new file mode 100644
index 000000000..8ce0ef756
--- /dev/null
+++ b/stdlib/source/test/lux/world/net/http/cookie.lux
@@ -0,0 +1,113 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ ["[0]" monad (.only do)]
+ [\\specification
+ ["[0]S" equivalence]]]
+ [control
+ ["|" pipe]
+ ["[0]" try (.use "[1]#[0]" functor)]]
+ [data
+ ["[0]" text (.use "[1]#[0]" equivalence)]
+ [collection
+ ["[0]" dictionary]]]
+ [math
+ ["[0]" random (.only Random)]]
+ [test
+ ["_" property (.only Test)]]]]
+ [\\library
+ ["[0]" /]])
+
+(def .public (random cookies)
+ (-> (List (Ex (_ of) [(/.Cookie of) (Random of)]))
+ (Random /.Jar))
+ (monad.mix random.monad
+ (function (_ [cookie random] jar)
+ (do random.monad
+ [value random]
+ (in (/.has cookie value jar))))
+ /.empty
+ cookies))
+
+(def .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [name (random.upper_case 1)
+ fake_name (random.upper_case 2)
+ expected (random.lower_case 1)
+ .let [cookie (is (/.Cookie Text)
+ [/.#name name
+ /.#in (|>>)
+ /.#out (|>> {try.#Success})])
+ fake_cookie (is (/.Cookie Text)
+ [/.#name fake_name
+ /.#in (|>>)
+ /.#out (|>> {try.#Success})])]
+
+ duration random.duration
+ instant random.instant
+ domain (random.lower_case 2)
+ path (random.lower_case 3)])
+ (_.for [/.Cookie /.#name /.#in /.#out])
+ (all _.and
+ (_.for [/.equivalence]
+ (equivalenceS.spec /.equivalence (..random (list [cookie (random.lower_case 1)]))))
+ (_.for [/.Jar]
+ (all _.and
+ (_.coverage [/.empty]
+ (dictionary.empty? /.empty))
+ (_.coverage [/.has /.value]
+ (|> /.empty
+ (/.has cookie expected)
+ (/.value cookie)
+ (try#each (text#= expected))
+ (try.else false)))
+ (_.coverage [/.unknown]
+ (|> /.empty
+ (/.has cookie expected)
+ (/.value fake_cookie)
+ (|.when
+ {try.#Success _} false
+ {try.#Failure _} true)))
+ ))
+ (_.for [/.Attribute]
+ (`` (all _.and
+ (,, (with_template [<attribute> <value>]
+ [(_.coverage [<attribute>]
+ (|> /.empty
+ (/.has (<attribute> <value> cookie) expected)
+ (/.value cookie)
+ (try#each (text#= expected))
+ (try.else false)))]
+
+ [/.expires instant]
+ [/.max_age duration]
+ [/.domain domain]
+ [/.path path]
+ ))
+ (,, (with_template [<attribute>]
+ [(_.coverage [<attribute>]
+ (|> /.empty
+ (/.has (<attribute> cookie) expected)
+ (/.value cookie)
+ (try#each (text#= expected))
+ (try.else false)))]
+
+ [/.secure]
+ [/.http_only]
+ ))
+ (_.coverage [/.CSRF_Policy /.strict /.lax /.none /.same_site]
+ (let [uses_policy! (is (-> /.CSRF_Policy Bit)
+ (function (_ it)
+ (|> /.empty
+ (/.has (/.same_site it cookie) expected)
+ (/.value cookie)
+ (try#each (text#= expected))
+ (try.else false))))]
+ (and (uses_policy! /.strict)
+ (uses_policy! /.lax)
+ (uses_policy! /.none))))
+ )))
+ )))
diff --git a/stdlib/source/test/lux/world/net/http/header.lux b/stdlib/source/test/lux/world/net/http/header.lux
index 6a3c48a99..50b25f24b 100644
--- a/stdlib/source/test/lux/world/net/http/header.lux
+++ b/stdlib/source/test/lux/world/net/http/header.lux
@@ -18,7 +18,8 @@
[\\library
["[0]" / (.only)
[//
- ["[0]" mime (.use "[1]#[0]" equivalence)]]]])
+ ["[0]" mime (.use "[1]#[0]" equivalence)]
+ ["[0]" cookie (.only Cookie)]]]])
(def .public test
Test
@@ -70,4 +71,19 @@
(/.one /.location)
(try#each (text#= expected_location))
(try.else false)))
+ (do !
+ [name (random.upper_case 1)
+ expected_value (random.lower_case 1)
+ .let [cookie (is (Cookie Text)
+ [cookie.#name name
+ cookie.#in (|>>)
+ cookie.#out (|>> {try.#Success})])
+ expected_jar (|> cookie.empty
+ (cookie.has cookie expected_value))]]
+ (_.coverage [/.set_cookies]
+ (|> /.empty
+ (/.has /.set_cookies expected_jar)
+ (/.one /.set_cookies)
+ (try#each (at cookie.equivalence = expected_jar))
+ (try.else false))))
)))