diff options
author | Eduardo Julian | 2020-04-20 01:22:45 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-04-20 01:22:45 -0400 |
commit | 4428345ab84ed065193b8186e86474f496975569 (patch) | |
tree | 98affd9dfa6d08fc0656380a07a33252409768ef /stdlib/source/test | |
parent | 6d26d72e557eef73959846876dff7f14d8185d68 (diff) |
Got JVM anonymous classes to compile again.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/lux/control/pipe.lux | 84 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/reader.lux | 9 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/region.lux | 95 |
3 files changed, 123 insertions, 65 deletions
diff --git a/stdlib/source/test/lux/control/pipe.lux b/stdlib/source/test/lux/control/pipe.lux index 0aecde080..d705e23ca 100644 --- a/stdlib/source/test/lux/control/pipe.lux +++ b/stdlib/source/test/lux/control/pipe.lux @@ -13,7 +13,7 @@ [math ["r" random]]] {1 - ["." / #*]}) + ["." /]}) (def: #export test Test @@ -23,65 +23,65 @@ ($_ _.and (do @ [another r.nat] - (_.test "Can dismiss previous pipeline results and begin a new one." + (_.test (%.name (name-of /.new>)) (n.= (inc another) (|> sample (n.* 3) (n.+ 4) - (new> another [inc]))))) - (_.test "Let-binding" + (/.new> another [inc]))))) + (_.test (%.name (name-of /.let>)) (n.= (n.+ sample sample) (|> sample - (let> x [(n.+ x x)])))) - (_.test "'Conditional' branching." + (/.let> x [(n.+ x x)])))) + (_.test (%.name (name-of /.cond>)) (text@= (cond (n.= 0 sample) "zero" (n.even? sample) "even" "odd") (|> sample - (cond> [(n.= 0)] [(new> "zero" [])] - [n.even?] [(new> "even" [])] - [(new> "odd" [])])))) - (_.test "'If' branching." + (/.cond> [(n.= 0)] [(/.new> "zero" [])] + [n.even?] [(/.new> "even" [])] + [(/.new> "odd" [])])))) + (_.test (%.name (name-of /.if>)) (text@= (if (n.even? sample) "even" "odd") (|> sample - (if> [n.even?] - [(new> "even" [])] - [(new> "odd" [])])))) - (_.test "'When' branching." + (/.if> [n.even?] + [(/.new> "even" [])] + [(/.new> "odd" [])])))) + (_.test (%.name (name-of /.when>)) (n.= (if (n.even? sample) (n.* 2 sample) sample) (|> sample - (when> [n.even?] - [(n.* 2)])))) - (_.test "Can loop." + (/.when> [n.even?] + [(n.* 2)])))) + (_.test (%.name (name-of /.loop>)) (n.= (n.* 10 sample) (|> sample - (loop> [(n.= (n.* 10 sample)) not] - [(n.+ sample)])))) - (_.test "Monads." + (/.loop> [(n.= (n.* 10 sample)) not] + [(n.+ sample)])))) + (_.test (%.name (name-of /.do>)) (n.= (inc (n.+ 4 (n.* 3 sample))) (|> sample - (do> identity.monad - [(n.* 3)] - [(n.+ 4)] - [inc])))) - (_.test "Execution." + (/.do> identity.monad + [(n.* 3)] + [(n.+ 4)] + [inc])))) + (_.test (%.name (name-of /.exec>)) (n.= (n.* 10 sample) (|> sample - (exec> [%.nat (format "sample = ") log!]) + (/.exec> [%.nat (format "sample = ") log!]) (n.* 10)))) - (_.test "Tuple." + (_.test (%.name (name-of /.tuple>)) (let [[left middle right] (|> sample - (tuple> [inc] - [dec] - [%.nat]))] + (/.tuple> [inc] + [dec] + [%.nat]))] (and (n.= (inc sample) left) (n.= (dec sample) middle) (text@= (%.nat sample) right)))) - (_.test "Pattern-matching." + (_.test (%.name (name-of /.case>)) (text@= (case (n.% 10 sample) 0 "zero" 1 "one" @@ -96,15 +96,15 @@ _ "???") (|> sample (n.% 10) - (case> 0 "zero" - 1 "one" - 2 "two" - 3 "three" - 4 "four" - 5 "five" - 6 "six" - 7 "seven" - 8 "eight" - 9 "nine" - _ "???")))) + (/.case> 0 "zero" + 1 "one" + 2 "two" + 3 "three" + 4 "four" + 5 "five" + 6 "six" + 7 "seven" + 8 "eight" + 9 "nine" + _ "???")))) )))) diff --git a/stdlib/source/test/lux/control/reader.lux b/stdlib/source/test/lux/control/reader.lux index 434ec5896..4ad1e2a45 100644 --- a/stdlib/source/test/lux/control/reader.lux +++ b/stdlib/source/test/lux/control/reader.lux @@ -9,6 +9,7 @@ ["$." apply] ["$." monad]]}] [data + ["." name] [number ["n" nat]] [text @@ -32,7 +33,7 @@ (def: #export test Test - (<| (_.context (%.name (name-of /._))) + (<| (_.context (name.module (name-of /._))) (do r.monad [sample r.nat factor r.nat] @@ -41,14 +42,14 @@ ($apply.spec ..injection ..comparison /.apply) ($monad.spec ..injection ..comparison /.monad) - (_.test "Can query the environment." + (_.test (%.name (name-of /.ask)) (n.= sample (/.run sample /.ask))) - (_.test "Can modify an environment locally." + (_.test (%.name (name-of /.local)) (n.= (n.* factor sample) (/.run sample (/.local (n.* factor) /.ask)))) (let [(^open "io@.") io.monad] - (_.test "Can add reader functionality to any monad." + (_.test (%.name (name-of /.with)) (|> (: (/.Reader Any (IO Nat)) (do (/.with io.monad) [a (/.lift (io@wrap sample)) diff --git a/stdlib/source/test/lux/control/region.lux b/stdlib/source/test/lux/control/region.lux index e7000fc48..eec4e6903 100644 --- a/stdlib/source/test/lux/control/region.lux +++ b/stdlib/source/test/lux/control/region.lux @@ -2,10 +2,18 @@ [lux #* ["_" test (#+ Test)] [abstract - ["." monad (#+ do)]] + [functor (#+ Functor)] + [apply (#+ Apply)] + ["." monad (#+ Monad do)] + {[0 #test] + [/ + ["$." functor (#+ Injection Comparison)] + ["$." apply] + ["$." monad]]}] [control ["." try (#+ Try)]] [data + ["." name] [number ["n" nat]] [text @@ -13,12 +21,13 @@ [collection ["." list]]] [math - ["r" random]]] + ["r" random]] + [type (#+ :share)]] {1 - ["." / + ["." / (#+ Region) [// ["." thread (#+ Thread)] - ["ex" exception (#+ exception:)]]]}) + ["." exception (#+ exception:)]]]}) (exception: oops) @@ -36,61 +45,109 @@ [failure? #0 #1] ) +(def: (injection value) + (Injection (All [a] (All [! r] (Region r (Thread !) a)))) + (function (_ [region scope]) + (function (_ !) + [scope + (#try.Success value)]))) + +(def: comparison + (Comparison (All [a] (All [! r] (Region r (Thread !) a)))) + (function (_ == left right) + (case [(:assume (thread.run (:assume (/.run thread.monad left)))) + (:assume (thread.run (:assume (/.run thread.monad right))))] + [(#try.Success left) (#try.Success right)] + (== left right) + + _ + false))) + (def: #export test Test - (<| (_.context (%.name (name-of /._))) + (<| (_.context (name.module (name-of /._))) (do r.monad [expected-clean-ups (|> r.nat (:: @ map (|>> (n.% 100) (n.max 1))))] ($_ _.and - (_.test "Clean-up functions are always run when region execution is done." + ($functor.spec ..injection ..comparison (: (All [! r] + (Functor (Region r (thread.Thread !)))) + (/.functor thread.functor))) + ($apply.spec ..injection ..comparison (: (All [! r] + (Apply (Region r (thread.Thread !)))) + (/.apply thread.monad))) + ($monad.spec ..injection ..comparison (: (All [! r] + (Monad (Region r (thread.Thread !)))) + (/.monad thread.monad))) + + (_.test (%.name (name-of /.run)) (thread.run (do thread.monad [clean-up-counter (thread.box 0) - #let [@@ @ + #let [//@ @ count-clean-up (function (_ value) (do @ [_ (thread.update inc clean-up-counter)] (wrap (#try.Success []))))] outcome (/.run @ (do (/.monad @) - [_ (monad.map @ (/.acquire @@ count-clean-up) + [_ (monad.map @ (/.acquire //@ count-clean-up) (list.n/range 1 expected-clean-ups))] (wrap []))) actual-clean-ups (thread.read clean-up-counter)] (wrap (and (success? outcome) (n.= expected-clean-ups actual-clean-ups)))))) - (_.test "Can clean-up despite errors." + (_.test (%.name (name-of /.fail)) + (thread.run + (do thread.monad + [clean-up-counter (thread.box 0) + #let [//@ @ + count-clean-up (function (_ value) + (do @ + [_ (thread.update inc clean-up-counter)] + (wrap (#try.Success []))))] + outcome (/.run @ + (do (/.monad @) + [_ (monad.map @ (/.acquire //@ count-clean-up) + (list.n/range 1 expected-clean-ups)) + _ (/.fail //@ (exception.construct ..oops []))] + (wrap []))) + actual-clean-ups (thread.read clean-up-counter)] + (wrap (and (failure? outcome) + (n.= expected-clean-ups + actual-clean-ups)))))) + (_.test (%.name (name-of /.throw)) (thread.run (do thread.monad [clean-up-counter (thread.box 0) - #let [@@ @ + #let [//@ @ count-clean-up (function (_ value) (do @ [_ (thread.update inc clean-up-counter)] (wrap (#try.Success []))))] outcome (/.run @ (do (/.monad @) - [_ (monad.map @ (/.acquire @@ count-clean-up) + [_ (monad.map @ (/.acquire //@ count-clean-up) (list.n/range 1 expected-clean-ups)) - _ (/.throw @@ oops [])] + _ (/.throw //@ ..oops [])] (wrap []))) actual-clean-ups (thread.read clean-up-counter)] (wrap (and (failure? outcome) (n.= expected-clean-ups actual-clean-ups)))))) - (_.test "Errors can propagate from the cleaners." + (_.test (%.name (name-of /.acquire)) (thread.run (do thread.monad [clean-up-counter (thread.box 0) - #let [@@ @ + #let [//@ @ count-clean-up (function (_ value) (do @ [_ (thread.update inc clean-up-counter)] - (wrap (: (Try Any) (ex.throw oops [])))))] + (wrap (: (Try Any) + (exception.throw ..oops [])))))] outcome (/.run @ (do (/.monad @) - [_ (monad.map @ (/.acquire @@ count-clean-up) + [_ (monad.map @ (/.acquire //@ count-clean-up) (list.n/range 1 expected-clean-ups))] (wrap []))) actual-clean-ups (thread.read clean-up-counter)] @@ -98,14 +155,14 @@ (failure? outcome)) (n.= expected-clean-ups actual-clean-ups)))))) - (_.test "Can lift operations." + (_.test (%.name (name-of /.lift)) (thread.run (do thread.monad [clean-up-counter (thread.box 0) - #let [@@ @] + #let [//@ @] outcome (/.run @ (do (/.monad @) - [_ (/.lift @@ (thread.write expected-clean-ups clean-up-counter))] + [_ (/.lift //@ (thread.write expected-clean-ups clean-up-counter))] (wrap []))) actual-clean-ups (thread.read clean-up-counter)] (wrap (and (success? outcome) |