diff options
Diffstat (limited to 'stdlib/source/test/lux/data')
-rw-r--r-- | stdlib/source/test/lux/data/binary.lux | 23 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/error.lux | 64 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/format/json.lux | 1 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/format/xml.lux | 2 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/number/rev.lux | 1 | ||||
-rw-r--r-- | stdlib/source/test/lux/data/text/regex.lux | 12 |
6 files changed, 19 insertions, 84 deletions
diff --git a/stdlib/source/test/lux/data/binary.lux b/stdlib/source/test/lux/data/binary.lux index 8fb17114e..4b1ff0c54 100644 --- a/stdlib/source/test/lux/data/binary.lux +++ b/stdlib/source/test/lux/data/binary.lux @@ -8,8 +8,9 @@ {[0 #test] [/ ["$." equivalence]]}] + [control + ["." try (#+ Try)]] [data - ["." error (#+ Error)] [number ["." i64] ["." nat]] @@ -19,12 +20,12 @@ ["." / (#+ Binary)]}) (def: (succeed result) - (-> (Error Bit) Bit) + (-> (Try Bit) Bit) (case result - (#error.Failure _) + (#try.Failure _) #0 - (#error.Success output) + (#try.Success output) output)) (def: #export (binary size) @@ -34,19 +35,19 @@ (if (n/< size idx) (do r.monad [byte r.nat] - (exec (error.assume (/.write/8 idx byte output)) + (exec (try.assume (/.write/8 idx byte output)) (recur (inc idx)))) (:: r.monad wrap output))))) (def: (bits-io bytes read write value) - (-> Nat (-> Nat Binary (Error Nat)) (-> Nat Nat Binary (Error Any)) Nat Bit) + (-> Nat (-> Nat Binary (Try Nat)) (-> Nat Nat Binary (Try Any)) Nat Bit) (let [binary (/.create bytes) cap (case bytes 8 (dec 0) _ (|> 1 (i64.left-shift (n/* 8 bytes)) dec)) capped-value (i64.and cap value)] (succeed - (do error.monad + (do try.monad [_ (write 0 value binary) output (read 0 binary)] (wrap (n/= capped-value output)))))) @@ -76,13 +77,13 @@ (bits-io 8 /.read/64 /.write/64 value)) (_.test "Can slice binaries." (let [slice-size (|> to (n/- from) inc) - random-slice (error.assume (/.slice from to random-binary)) + random-slice (try.assume (/.slice from to random-binary)) idxs (list.n/range 0 (dec slice-size)) reader (function (_ binary idx) (/.read/8 idx binary))] (and (n/= slice-size (/.size random-slice)) - (case [(monad.map error.monad (reader random-slice) idxs) - (monad.map error.monad (|>> (n/+ from) (reader random-binary)) idxs)] - [(#error.Success slice-vals) (#error.Success binary-vals)] + (case [(monad.map try.monad (reader random-slice) idxs) + (monad.map try.monad (|>> (n/+ from) (reader random-binary)) idxs)] + [(#try.Success slice-vals) (#try.Success binary-vals)] (:: (list.equivalence nat.equivalence) = slice-vals binary-vals) _ diff --git a/stdlib/source/test/lux/data/error.lux b/stdlib/source/test/lux/data/error.lux deleted file mode 100644 index 340b4b73b..000000000 --- a/stdlib/source/test/lux/data/error.lux +++ /dev/null @@ -1,64 +0,0 @@ -(.module: - [lux #* - ["_" test (#+ Test)] - [abstract - [monad (#+ do Monad)] - {[0 #test] - [/ - ["$." functor (#+ Injection Comparison)] - ["$." apply] - ["$." monad] - ["$." equivalence]]}] - [control - pipe - ["." io]] - [data - ["%" text/format (#+ format)] - [number - ["." nat]]] - [math - ["r" random (#+ Random)]]] - {1 - ["." / (#+ Error)]}) - -(def: injection - (Injection Error) - (|>> #/.Success)) - -(def: comparison - (Comparison Error) - (function (_ ==) - (:: (/.equivalence ==) =))) - -(def: #export (error element) - (All [a] (-> (Random a) (Random (Error a)))) - ($_ r.or - (r.unicode 1) - element)) - -(def: #export test - Test - (<| (_.context (%.name (name-of /._))) - ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) (..error r.nat)) - ($functor.spec ..injection ..comparison /.functor) - ($apply.spec ..injection ..comparison /.apply) - ($monad.spec ..injection ..comparison /.monad) - (do r.monad - [left r.nat - right r.nat - #let [expected (n/+ left right) - (^open "io@.") io.monad]] - (_.test "Can add error functionality to any monad." - (let [lift (/.lift io.monad)] - (|> (do (/.with io.monad) - [a (lift (io@wrap left)) - b (wrap right)] - (wrap (n/+ a b))) - io.run - (case> (#/.Success actual) - (n/= expected actual) - - _ - false))))) - ))) diff --git a/stdlib/source/test/lux/data/format/json.lux b/stdlib/source/test/lux/data/format/json.lux index 61cf67a6c..4ccd4e337 100644 --- a/stdlib/source/test/lux/data/format/json.lux +++ b/stdlib/source/test/lux/data/format/json.lux @@ -14,7 +14,6 @@ pipe ["p" parser]] [data - ["." error] ["." bit] ["." maybe] ["." text] diff --git a/stdlib/source/test/lux/data/format/xml.lux b/stdlib/source/test/lux/data/format/xml.lux index 6ca73269a..a7236ede6 100644 --- a/stdlib/source/test/lux/data/format/xml.lux +++ b/stdlib/source/test/lux/data/format/xml.lux @@ -10,11 +10,11 @@ ["$." codec]]}] [control pipe + ["E" try] ["p" parser ["</>" xml]]] [data ["." name] - ["E" error] ["." maybe] ["." text ("#@." equivalence)] [collection diff --git a/stdlib/source/test/lux/data/number/rev.lux b/stdlib/source/test/lux/data/number/rev.lux index 9b25ae6af..37df07567 100644 --- a/stdlib/source/test/lux/data/number/rev.lux +++ b/stdlib/source/test/lux/data/number/rev.lux @@ -14,7 +14,6 @@ ["$." monoid] ["$." codec]]}] [data - ["." error] [number ["." i64]]] [math diff --git a/stdlib/source/test/lux/data/text/regex.lux b/stdlib/source/test/lux/data/text/regex.lux index 61e1df77a..7789cc9bf 100644 --- a/stdlib/source/test/lux/data/text/regex.lux +++ b/stdlib/source/test/lux/data/text/regex.lux @@ -5,12 +5,12 @@ [abstract/monad (#+ do)] [control pipe + ["." try] ["p" parser ["<.>" text (#+ Parser)] ["s" code]]] [data [number (#+ hex)] - ["." error] ["." text ("#@." equivalence)]] [math ["r" random]] @@ -23,7 +23,7 @@ (-> (Parser Text) Text Bit) (|> input (<text>.run regex) - (case> (#error.Success parsed) + (case> (#try.Success parsed) (text@= parsed input) _ @@ -33,7 +33,7 @@ (-> Text (Parser Text) Text Bit) (|> input (<text>.run regex) - (case> (#error.Success parsed) + (case> (#try.Success parsed) (text@= test parsed) _ @@ -43,7 +43,7 @@ (All [a] (-> (Parser a) Text Bit)) (|> input (<text>.run regex) - (case> (#error.Failure _) + (case> (#try.Failure _) true _ @@ -53,10 +53,10 @@ (macro.with-gensyms [g!message g!_] (wrap (list (` (|> (~ input) (<text>.run (~ regex)) - (case> (^ (#error.Success (~ pattern))) + (case> (^ (#try.Success (~ pattern))) true - (#error.Failure (~ g!message)) + (#try.Failure (~ g!message)) (exec (log! (format "{{{Failure}}} " (~ g!message))) false) |