diff options
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/aedifex/artifact/snapshot/build.lux (renamed from stdlib/source/test/aedifex/artifact/build.lux) | 11 | ||||
-rw-r--r-- | stdlib/source/test/aedifex/artifact/snapshot/stamp.lux | 48 | ||||
-rw-r--r-- | stdlib/source/test/aedifex/artifact/snapshot/time.lux | 42 | ||||
-rw-r--r-- | stdlib/source/test/aedifex/artifact/time_stamp.lux | 33 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/concurrency/actor.lux | 22 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/parser/xml.lux | 40 | ||||
-rw-r--r-- | stdlib/source/test/lux/macro/template.lux | 25 | ||||
-rw-r--r-- | stdlib/source/test/lux/type.lux | 2 | ||||
-rw-r--r-- | stdlib/source/test/lux/type/abstract.lux | 110 |
9 files changed, 266 insertions, 67 deletions
diff --git a/stdlib/source/test/aedifex/artifact/build.lux b/stdlib/source/test/aedifex/artifact/snapshot/build.lux index d0920b44c..e3fdcab62 100644 --- a/stdlib/source/test/aedifex/artifact/build.lux +++ b/stdlib/source/test/aedifex/artifact/snapshot/build.lux @@ -11,23 +11,28 @@ [parser ["<.>" xml]]] [math - ["." random]]] + ["." random (#+ Random)]]] {#program ["." /]}) +(def: #export random + (Random /.Build) + random.nat) + (def: #export test Test (<| (_.covering /._) (_.for [/.Build] ($_ _.and (_.for [/.equivalence] - ($equivalence.spec /.equivalence random.nat)) + ($equivalence.spec /.equivalence ..random)) (do random.monad - [expected random.nat] + [expected ..random] (_.cover [/.format /.parser] (|> expected /.format + list (<xml>.run /.parser) (try\map (\ /.equivalence = expected)) (try.default false)))) diff --git a/stdlib/source/test/aedifex/artifact/snapshot/stamp.lux b/stdlib/source/test/aedifex/artifact/snapshot/stamp.lux new file mode 100644 index 000000000..aab722cad --- /dev/null +++ b/stdlib/source/test/aedifex/artifact/snapshot/stamp.lux @@ -0,0 +1,48 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence]]}] + [control + ["." try ("#\." functor)] + [parser + ["<.>" xml]]] + [math + ["." random (#+ Random)]] + [time + ["." instant]]] + {#program + ["." /]} + ["$." // #_ + ["#." time] + ["#." build]]) + +(def: #export random + (Random /.Stamp) + ($_ random.and + $//time.random + $//build.random + )) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Stamp]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + + (do random.monad + [expected ..random] + ($_ _.and + (_.cover [/.format /.parser] + (|> expected + /.format + (<xml>.run' /.parser) + (try\map (\ instant.equivalence = expected)) + (try.default false))) + )) + ))) diff --git a/stdlib/source/test/aedifex/artifact/snapshot/time.lux b/stdlib/source/test/aedifex/artifact/snapshot/time.lux new file mode 100644 index 000000000..567c70ce4 --- /dev/null +++ b/stdlib/source/test/aedifex/artifact/snapshot/time.lux @@ -0,0 +1,42 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence]]}] + [control + ["." try ("#\." functor)] + [parser + ["<.>" text]]] + [math + ["." random (#+ Random)]] + [time + ["." instant]]] + {#program + ["." /]}) + +(def: #export random + (Random /.Time) + random.instant) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Time]) + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + + (do random.monad + [expected ..random] + ($_ _.and + (_.cover [/.format /.parser] + (|> expected + /.format + (<text>.run /.parser) + (try\map (\ instant.equivalence = expected)) + (try.default false))) + )) + ))) diff --git a/stdlib/source/test/aedifex/artifact/time_stamp.lux b/stdlib/source/test/aedifex/artifact/time_stamp.lux deleted file mode 100644 index 7dea57392..000000000 --- a/stdlib/source/test/aedifex/artifact/time_stamp.lux +++ /dev/null @@ -1,33 +0,0 @@ -(.module: - [lux #* - ["_" test (#+ Test)] - [abstract - [monad (#+ do)]] - [control - ["." try ("#\." functor)] - [parser - ["<.>" text]]] - [math - ["." random (#+ Random)] - [number - ["n" nat] - ["i" int]]] - [time - ["." instant]]] - {#program - ["." /]}) - -(def: #export test - Test - (<| (_.covering /._) - (_.for [/.Time_Stamp]) - ($_ _.and - (do random.monad - [expected random.instant] - (_.cover [/.format /.parser] - (|> expected - /.format - (<text>.run /.parser) - (try\map (\ instant.equivalence = expected)) - (try.default false)))) - ))) diff --git a/stdlib/source/test/lux/control/concurrency/actor.lux b/stdlib/source/test/lux/control/concurrency/actor.lux index d983ab382..487e4c48c 100644 --- a/stdlib/source/test/lux/control/concurrency/actor.lux +++ b/stdlib/source/test/lux/control/concurrency/actor.lux @@ -32,9 +32,6 @@ ((on_mail message state self) (message state self)) - ((on_stop cause state) - (promise\wrap [])) - (message: (count! {increment Nat} state self Nat) (let [state' (n.+ increment state)] (promise\wrap (#try.Success [state' state'])))) @@ -90,9 +87,16 @@ [actor (/.spawn! (: (/.Behavior Any Any) {#/.on_init (|>>) #/.on_mail (function (_ message state self) - (message state self)) - #/.on_stop (function (_ cause state) - (promise.future (write cause)))}) + (do {! promise.monad} + [outcome (message state self)] + (case outcome + (#try.Failure cause) + (do ! + [_ (promise.future (write cause))] + (wrap outcome)) + + (#try.Success _) + (wrap outcome))))}) [])] (/.poison! actor))) _ (promise.wait 100) @@ -172,11 +176,7 @@ [anonymous (/.actor {Nat initial_state} ((on_mail message state self) - (message (inc state) self)) - - ((on_stop cause state) - (promise\wrap (exec (%.nat state) - [])))) + (message (inc state) self))) sent/inc? (/.mail! inc! anonymous) sent/dec? (/.mail! dec! anonymous) poisoned? (/.poison! anonymous) diff --git a/stdlib/source/test/lux/control/parser/xml.lux b/stdlib/source/test/lux/control/parser/xml.lux index a9f71af71..c2d0ac4e2 100644 --- a/stdlib/source/test/lux/control/parser/xml.lux +++ b/stdlib/source/test/lux/control/parser/xml.lux @@ -39,7 +39,7 @@ [expected (random.ascii/alpha 1)] (_.cover [<exception>] (`` (and (~~ (template [<parser> <input>] - [(|> (/.run <parser> <input>) + [(|> (/.run <parser> (list <input>)) (!expect (^multi (#try.Failure error) (exception.match? <exception> error))))] @@ -61,7 +61,7 @@ (do {! random.monad} [expected (random.ascii/alpha 1)] (_.cover [/.run /.text] - (|> (/.run /.text (#xml.Text expected)) + (|> (/.run /.text (list (#xml.Text expected))) (!expect (^multi (#try.Success actual) (text\= expected actual)))))) (!failure /.unconsumed_inputs @@ -70,7 +70,7 @@ (do {! random.monad} [expected (random.ascii/alpha 1)] (_.cover [/.ignore] - (|> (/.run /.ignore (#xml.Text expected)) + (|> (/.run /.ignore (list (#xml.Text expected))) (!expect (#try.Success []))))) (do {! random.monad} [expected ..random_tag] @@ -79,7 +79,7 @@ [actual /.tag _ /.ignore] (wrap (name\= expected actual))) - (#xml.Node expected (dictionary.new name.hash) (list))) + (list (#xml.Node expected (dictionary.new name.hash) (list)))) (!expect (#try.Success #1))))) (do {! random.monad} [expected ..random_tag] @@ -87,7 +87,7 @@ (|> (/.run (do //.monad [_ (/.node expected)] /.ignore) - (#xml.Node expected (dictionary.new name.hash) (list))) + (list (#xml.Node expected (dictionary.new name.hash) (list)))) (!expect (#try.Success []))))) (!failure /.wrong_tag [[(/.node ["" expected]) @@ -101,10 +101,10 @@ [_ (/.node expected_tag) _ (/.attribute expected_attribute)] /.ignore) - (#xml.Node expected_tag - (|> (dictionary.new name.hash) - (dictionary.put expected_attribute expected_value)) - (list))) + (list (#xml.Node expected_tag + (|> (dictionary.new name.hash) + (dictionary.put expected_attribute expected_value)) + (list)))) (!expect (#try.Success []))))) (!failure /.unknown_attribute [[(do //.monad @@ -123,11 +123,11 @@ (do ! [_ (/.node expected)] /.ignore))) - (#xml.Node expected - (dictionary.new name.hash) - (list (#xml.Node expected - (dictionary.new name.hash) - (list))))) + (list (#xml.Node expected + (dictionary.new name.hash) + (list (#xml.Node expected + (dictionary.new name.hash) + (list)))))) (!expect (#try.Success []))))) (!failure /.empty_input [[(do //.monad @@ -195,15 +195,15 @@ ($_ _.and (_.cover [/.somewhere] (|> (/.run parser - (node parent - (list.concat (list (list.repeat repetitions (node wrong (list))) - (list (node right (list))) - (list.repeat repetitions (node wrong (list))))))) + (list (node parent + (list.concat (list (list.repeat repetitions (node wrong (list))) + (list (node right (list))) + (list.repeat repetitions (node wrong (list)))))))) (!expect (#try.Success [])))) (_.cover [/.nowhere] (|> (/.run parser - (node parent - (list.repeat repetitions (node wrong (list))))) + (list (node parent + (list.repeat repetitions (node wrong (list)))))) (!expect (^multi (#try.Failure error) (exception.match? /.nowhere error))))) )) diff --git a/stdlib/source/test/lux/macro/template.lux b/stdlib/source/test/lux/macro/template.lux index 53d7d114e..b129aaaef 100644 --- a/stdlib/source/test/lux/macro/template.lux +++ b/stdlib/source/test/lux/macro/template.lux @@ -3,9 +3,15 @@ ["_" test (#+ Test)] [abstract [monad (#+ do)]] + [control + ["." try] + ["." exception]] [data [collection ["." list]]] + ["." macro + [syntax (#+ syntax:)] + ["." code]] [math ["." random (#+ Random)] [number @@ -19,6 +25,15 @@ (-> Nat Nat) (|>> !pow/2))) +(syntax: (macro_error macro) + (function (_ compiler) + (case ((macro.expand macro) compiler) + (#try.Failure error) + (#try.Success [compiler (list (code.text error))]) + + (#try.Success _) + (#try.Failure "OOPS!")))) + (def: #export test Test (<| (_.covering /._) @@ -97,5 +112,15 @@ can_refer! can_shadow!))) )))) + (_.cover [/.irregular_arguments] + (/.with [(arity/3 <0> <1> <2>) + ""] + (exception.match? /.irregular_arguments + (macro_error (arity/3 "a" "b"))))) + (_.cover [/.cannot_shadow_definition] + (exception.match? /.cannot_shadow_definition + (macro_error (/.with [(macro_error <0> <1> <2>) + ""] + "")))) ))) )) diff --git a/stdlib/source/test/lux/type.lux b/stdlib/source/test/lux/type.lux index 168ed29d1..70b13a382 100644 --- a/stdlib/source/test/lux/type.lux +++ b/stdlib/source/test/lux/type.lux @@ -17,6 +17,7 @@ {1 ["." / ("#\." equivalence)]} ["." / #_ + ["#." abstract] ["#." check] ["#." dynamic] ["#." implicit] @@ -164,6 +165,7 @@ {(Maybe a) example} (List a))))) + /abstract.test /check.test /dynamic.test /implicit.test diff --git a/stdlib/source/test/lux/type/abstract.lux b/stdlib/source/test/lux/type/abstract.lux new file mode 100644 index 000000000..30ad27687 --- /dev/null +++ b/stdlib/source/test/lux/type/abstract.lux @@ -0,0 +1,110 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + ["." meta] + [abstract + [monad (#+ do)]] + [control + ["." try] + ["." exception]] + [data + ["." text ("#\." equivalence)]] + ["." macro + [syntax (#+ syntax:)] + ["." code] + ["." template]] + ["." math + ["." random] + [number + ["n" nat]]]] + {1 + ["." /]}) + +(template.with_locals [g!Foo g!Bar] + (as_is (template [<syntax> <meta>] + [(syntax: (<syntax>) + (do meta.monad + [frame <meta>] + (wrap (list (code.text (get@ #/.name frame))))))] + + [current /.current] + [specific (/.specific (template.text [g!Foo]))] + ) + + (syntax: (with_no_active_frames macro) + (function (_ compiler) + (let [verdict (case ((macro.expand macro) compiler) + (#try.Failure error) + (exception.match? /.no_active_frames error) + + (#try.Success _) + false)] + (#try.Success [compiler (list (code.bit verdict))])))) + + (with_expansions [no_current! (..with_no_active_frames (..current)) + no_specific! (..with_no_active_frames (..specific))] + (/.abstract: (g!Foo a) + Text + + (/.abstract: (g!Bar a) + Nat + + (def: #export test + Test + (<| (_.covering /._) + (_.for [/.abstract:]) + (do random.monad + [expected_foo (random.ascii/lower 5) + expected_bar random.nat] + ($_ _.and + (_.cover [/.:abstraction] + (and (exec (: (g!Foo Text) + (/.:abstraction g!Foo expected_foo)) + true) + (exec (: (g!Bar Text) + (/.:abstraction expected_bar)) + true))) + (_.cover [/.:representation] + (and (|> expected_foo + (/.:abstraction g!Foo) + (: (g!Foo Bit)) + (/.:representation g!Foo) + (text\= expected_foo)) + (|> (/.:abstraction expected_bar) + (: (g!Bar Bit)) + /.:representation + (n.= expected_bar)))) + (_.cover [/.:transmutation] + (and (exec (|> expected_foo + (/.:abstraction g!Foo) + (: (g!Foo .Macro)) + (/.:transmutation g!Foo) + (: (g!Foo .Lux))) + true) + (exec (|> (/.:abstraction expected_bar) + (: (g!Bar .Macro)) + /.:transmutation + (: (g!Bar .Lux))) + true))) + (_.cover [/.^:representation] + (and (let [(/.^:representation g!Foo actual_foo) + (: (g!Foo .Module) + (/.:abstraction g!Foo expected_foo))] + (text\= expected_foo actual_foo)) + (let [(/.^:representation actual_bar) + (: (g!Bar .Module) + (/.:abstraction expected_bar))] + (n.= expected_bar actual_bar)))) + (_.for [/.Frame] + ($_ _.and + (_.cover [/.current] + (text\= (template.text [g!Bar]) + (..current))) + (_.cover [/.specific] + (text\= (template.text [g!Foo]) + (..specific))) + (_.cover [/.no_active_frames] + (and no_current! + no_specific!)) + )) + ))))))))) |