diff options
author | Eduardo Julian | 2022-10-27 00:00:03 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-10-27 00:00:03 -0400 |
commit | 54d22bc41b874d52a94a96aafca18ab3a6357edb (patch) | |
tree | f8560699f618eabbc25a621e9d62f0bc000b2125 /stdlib/source/test | |
parent | 8d4c256f8b56561869c14df02db695d774c74fa6 (diff) |
Added support for aspect-oriented programming.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/lux/control.lux | 2 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/aspect.lux | 139 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/format/json.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/world/net.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/world/net/uri/query.lux | 43 |
5 files changed, 189 insertions, 3 deletions
diff --git a/stdlib/source/test/lux/control.lux b/stdlib/source/test/lux/control.lux index 5a57ac13d..67903a051 100644 --- a/stdlib/source/test/lux/control.lux +++ b/stdlib/source/test/lux/control.lux @@ -4,6 +4,7 @@ [test ["_" property (.only Test)]]]] ["[0]" / + ["[1][0]" aspect] ["[1][0]" concatenative] ["[1][0]" concurrency ["[1]/[0]" actor] @@ -66,6 +67,7 @@ (def .public test Test (all _.and + /aspect.test /concatenative.test ..concurrency /continuation.test diff --git a/stdlib/source/test/lux/control/aspect.lux b/stdlib/source/test/lux/control/aspect.lux new file mode 100644 index 000000000..a98d83918 --- /dev/null +++ b/stdlib/source/test/lux/control/aspect.lux @@ -0,0 +1,139 @@ +(.require + [library + [lux (.except global) + [abstract + [monad (.only do)]] + [control + [function + ["?" predicate]]] + [data + ["[0]" text (.use "[1]#[0]" equivalence) + ["%" \\format]]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat]]] + [meta + ["[0]" symbol (.use "[1]#[0]" equivalence)] + ["[0]" static] + ["[0]" code]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" /]]) + +(def (double it) + (/.After Nat) + (n.+ it it)) + +(def can_double + (Random Nat) + (random.only (function (_ it) + (not (n.= it (double it)))) + random.nat)) + +(def global + Nat + (static.random code.nat ..can_double)) + +(def (triple it) + (-> Nat Nat) + (all n.+ it it it)) + +(def pre_double + (/.Around Nat Nat) + (/.before ..double)) + +(def after_aspect + /.Aspect + (list [(all ?.or + (/.when_global (|>> (the /.#name) + (symbol#= (symbol ..global)))) + (/.when_local ?.all)) + (symbol ..double)])) + +(def before_aspect + /.Aspect + (list [(/.when_global (|>> (the /.#name) + (symbol#= (symbol ..triple)))) + (symbol ..pre_double)])) + +(def this_module + Text + (let [[module _] (symbol .._)] + module)) + +(def another_module + Text + (let [[module _] (symbol /._)] + module)) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [local ..can_double]) + (_.for [/.Aspect]) + (all _.and + (_.for [/.with] + (all _.and + (_.for [/.Advice /.After] + (_.for [/.Reference /.#name /.#type + /.Scenario /.#Global /.#Local] + (all _.and + (_.coverage [/.Local] + (n.= (double local) + (/.with ..after_aspect + local))) + (_.coverage [/.Global] + (n.= (double ..global) + (/.with ..after_aspect + ..global)))))) + (_.coverage [/.Around /.before] + (n.= (triple (double local)) + (/.with ..before_aspect + (triple local)))) + )) + (_.for [/.Join_Point /.#location /.#scenario + /.Point_Cut] + (all _.and + (_.coverage [/.when_local] + (and (n.= (triple (double local)) + (/.with (list [(/.when_local ?.all) + (symbol ..double)]) + (triple local))) + (n.= (triple local) + (/.with (list [(/.when_local ?.none) + (symbol ..double)]) + (triple local))))) + (_.coverage [/.when_global] + (and (n.= (triple (double local)) + (/.with (list [(/.when_global ?.all) + (symbol ..pre_double)]) + (triple local))) + (n.= (triple local) + (/.with (list [(/.when_global ?.none) + (symbol ..pre_double)]) + (triple local))))) + (_.coverage [/.when_module] + (and (n.= (triple (double local)) + (/.with (list [(?.and (/.when_module (text#= this_module)) + (/.when_local ?.all)) + (symbol ..double)]) + (triple local))) + (n.= (triple local) + (/.with (list [(?.and (/.when_module (text#= another_module)) + (/.when_local ?.all)) + (symbol ..double)]) + (triple local))))) + (_.coverage [/.typed?] + (and (n.= (triple (double local)) + (/.with (list [(/.typed? Nat) + (symbol ..double)]) + (triple local))) + (n.= ((pre_double triple) local) + (/.with (list [(/.typed? (-> Nat Nat)) + (symbol ..pre_double)]) + (triple local))))) + )) + ))) diff --git a/stdlib/source/test/lux/data/format/json.lux b/stdlib/source/test/lux/data/format/json.lux index 691f4d357..caabbe222 100644 --- a/stdlib/source/test/lux/data/format/json.lux +++ b/stdlib/source/test/lux/data/format/json.lux @@ -357,7 +357,7 @@ (do random.monad [sample ..random] - (_.coverage [/.Null /.null?] + (_.coverage [/.Null /.#Null /.null?] (at bit.equivalence = (/.null? sample) (when sample @@ -422,7 +422,7 @@ [(do random.monad [key (random.alphabetic 1) value <random>] - (_.coverage [<type> <field>] + (_.coverage [<type> <tag> <field>] (|> (/.object (list [key {<tag> value}])) (<field> key) (try#each (at <equivalence> = value)) diff --git a/stdlib/source/test/lux/world/net.lux b/stdlib/source/test/lux/world/net.lux index 9856b8a00..b2c286fc0 100644 --- a/stdlib/source/test/lux/world/net.lux +++ b/stdlib/source/test/lux/world/net.lux @@ -20,7 +20,8 @@ ["[1][0]" uri ["[1]/[0]" encoding] ["[1]/[0]" scheme] - ["[1]/[0]" path]]]) + ["[1]/[0]" path] + ["[1]/[0]" query]]]) (def .public test Test @@ -48,4 +49,5 @@ /uri/encoding.test /uri/scheme.test /uri/path.test + /uri/query.test ))) diff --git a/stdlib/source/test/lux/world/net/uri/query.lux b/stdlib/source/test/lux/world/net/uri/query.lux new file mode 100644 index 000000000..ecdd3c2c4 --- /dev/null +++ b/stdlib/source/test/lux/world/net/uri/query.lux @@ -0,0 +1,43 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)] + [\\specification + ["[0]S" equivalence] + ["[0]S" codec]]] + [data + [collection + ["[0]" dictionary]]] + [math + ["[0]" random (.only Random) (.use "[1]#[0]" monad)]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" /]]) + +(def .public (random size) + (-> Nat (Random /.Query)) + (when size + 0 (random#in /.empty) + _ (do random.monad + [key (random.alphabetic size) + value (random.unicode size) + query (random (-- size))] + (in (dictionary.has key value query))))) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + []) + (_.for [/.Query]) + (all _.and + (_.for [/.equivalence] + (equivalenceS.spec /.equivalence (..random 2))) + (_.for [/.codec] + (codecS.spec /.equivalence /.codec (..random 3))) + + (_.coverage [/.empty] + (dictionary.empty? /.empty)) + ))) |