From 8bd1d1b3a4750b26f1540717839c1aa196f2a520 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 17 May 2017 20:23:02 -0400 Subject: - Renamed "Error" to "Result". --- stdlib/test/test/lux/concurrency/actor.lux | 2 +- stdlib/test/test/lux/concurrency/frp.lux | 3 +- stdlib/test/test/lux/concurrency/promise.lux | 3 +- stdlib/test/test/lux/control/exception.lux | 4 +- stdlib/test/test/lux/data/error.lux | 56 ---------------------------- stdlib/test/test/lux/data/format/json.lux | 2 +- stdlib/test/test/lux/data/result.lux | 56 ++++++++++++++++++++++++++++ stdlib/test/test/lux/data/text/lexer.lux | 12 +++--- stdlib/test/test/lux/data/text/regex.lux | 3 +- stdlib/test/test/lux/macro/syntax.lux | 4 +- stdlib/test/tests.lux | 2 +- 11 files changed, 72 insertions(+), 75 deletions(-) delete mode 100644 stdlib/test/test/lux/data/error.lux create mode 100644 stdlib/test/test/lux/data/result.lux (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/concurrency/actor.lux b/stdlib/test/test/lux/concurrency/actor.lux index a4c69a880..a92c2c376 100644 --- a/stdlib/test/test/lux/concurrency/actor.lux +++ b/stdlib/test/test/lux/concurrency/actor.lux @@ -4,7 +4,7 @@ (control monad) (data [number] text/format - [error #- fail]) + ["R" result]) (concurrency [promise #+ Promise Monad "Promise/" Monad] ["&" actor #+ actor:])) lux/test) diff --git a/stdlib/test/test/lux/concurrency/frp.lux b/stdlib/test/test/lux/concurrency/frp.lux index a141753a8..245428f38 100644 --- a/stdlib/test/test/lux/concurrency/frp.lux +++ b/stdlib/test/test/lux/concurrency/frp.lux @@ -3,8 +3,7 @@ (lux [io #- run] (control monad) (data [number] - text/format - [error #- fail]) + text/format) (concurrency [promise #+ Promise Monad "Promise/" Monad] ["&" frp])) lux/test) diff --git a/stdlib/test/test/lux/concurrency/promise.lux b/stdlib/test/test/lux/concurrency/promise.lux index 7ad25fc46..8c4e623e4 100644 --- a/stdlib/test/test/lux/concurrency/promise.lux +++ b/stdlib/test/test/lux/concurrency/promise.lux @@ -4,8 +4,7 @@ (control monad pipe) (data [number] - text/format - [error #- fail]) + text/format) (concurrency ["&" promise]) ["R" math/random]) lux/test) diff --git a/stdlib/test/test/lux/control/exception.lux b/stdlib/test/test/lux/control/exception.lux index 80267cedd..bef3ae4cd 100644 --- a/stdlib/test/test/lux/control/exception.lux +++ b/stdlib/test/test/lux/control/exception.lux @@ -3,7 +3,7 @@ (lux [io] (control monad ["&" exception #+ exception:]) - (data [error #- fail] + (data ["E" result] [text] text/format [number]) @@ -36,7 +36,7 @@ another-val) otherwise-val) default-val) - actual (|> (: (Error Nat) + actual (|> (: (E;Result Nat) (if should-throw? (&;throw this-ex "Uh-oh...") (&;return default-val))) diff --git a/stdlib/test/test/lux/data/error.lux b/stdlib/test/test/lux/data/error.lux deleted file mode 100644 index d90387c89..000000000 --- a/stdlib/test/test/lux/data/error.lux +++ /dev/null @@ -1,56 +0,0 @@ -(;module: - lux - (lux [io] - (control monad - pipe) - (data text/format - ["&" error])) - lux/test) - -(test: "Errors" - (let [(^open "&/") &;Monad] - ($_ seq - (assert "Functor correctly handles both cases." - (and (|> (: (&;Error Int) (#&;Success 10)) - (&/map i.inc) - (case> (#&;Success 11) true _ false)) - - (|> (: (&;Error Int) (#&;Error "YOLO")) - (&/map i.inc) - (case> (#&;Error "YOLO") true _ false)) - )) - - (assert "Applicative correctly handles both cases." - (and (|> (&/wrap 20) - (case> (#&;Success 20) true _ false)) - (|> (&/apply (&/wrap i.inc) (&/wrap 10)) - (case> (#&;Success 11) true _ false)) - (|> (&/apply (&/wrap i.inc) (#&;Error "YOLO")) - (case> (#&;Error "YOLO") true _ false)))) - - (assert "Monad correctly handles both cases." - (and (|> (do &;Monad - [f (wrap i.+) - a (wrap 10) - b (wrap 20)] - (wrap (f a b))) - (case> (#&;Success 30) true _ false)) - (|> (do &;Monad - [f (wrap i.+) - a (#&;Error "YOLO") - b (wrap 20)] - (wrap (f a b))) - (case> (#&;Error "YOLO") true _ false)) - )) - ))) - -(test: "Monad transformer" - (let [lift (&;lift-error io;Monad) - (^open "io/") io;Monad] - (assert "Can add error functionality to any monad." - (|> (io;run (do (&;ErrorT io;Monad) - [a (lift (io/wrap 123)) - b (wrap 456)] - (wrap (i.+ a b)))) - (case> (#&;Success 579) true - _ false))))) diff --git a/stdlib/test/test/lux/data/format/json.lux b/stdlib/test/test/lux/data/format/json.lux index 7acddf750..b52b72635 100644 --- a/stdlib/test/test/lux/data/format/json.lux +++ b/stdlib/test/test/lux/data/format/json.lux @@ -7,7 +7,7 @@ pipe) (data [text "Text/" Monoid] text/format - [error #- fail] + [result] [bool] [char] [maybe] diff --git a/stdlib/test/test/lux/data/result.lux b/stdlib/test/test/lux/data/result.lux new file mode 100644 index 000000000..aee931279 --- /dev/null +++ b/stdlib/test/test/lux/data/result.lux @@ -0,0 +1,56 @@ +(;module: + lux + (lux [io] + (control monad + pipe) + (data text/format + ["&" result])) + lux/test) + +(test: "Results" + (let [(^open "&/") &;Monad] + ($_ seq + (assert "Functor correctly handles both cases." + (and (|> (: (&;Result Int) (#&;Success 10)) + (&/map i.inc) + (case> (#&;Success 11) true _ false)) + + (|> (: (&;Result Int) (#&;Error "YOLO")) + (&/map i.inc) + (case> (#&;Error "YOLO") true _ false)) + )) + + (assert "Applicative correctly handles both cases." + (and (|> (&/wrap 20) + (case> (#&;Success 20) true _ false)) + (|> (&/apply (&/wrap i.inc) (&/wrap 10)) + (case> (#&;Success 11) true _ false)) + (|> (&/apply (&/wrap i.inc) (#&;Error "YOLO")) + (case> (#&;Error "YOLO") true _ false)))) + + (assert "Monad correctly handles both cases." + (and (|> (do &;Monad + [f (wrap i.+) + a (wrap 10) + b (wrap 20)] + (wrap (f a b))) + (case> (#&;Success 30) true _ false)) + (|> (do &;Monad + [f (wrap i.+) + a (#&;Error "YOLO") + b (wrap 20)] + (wrap (f a b))) + (case> (#&;Error "YOLO") true _ false)) + )) + ))) + +(test: "Monad transformer" + (let [lift (&;lift-result io;Monad) + (^open "io/") io;Monad] + (assert "Can add result functionality to any monad." + (|> (io;run (do (&;ResultT io;Monad) + [a (lift (io/wrap 123)) + b (wrap 456)] + (wrap (i.+ a b)))) + (case> (#&;Success 579) true + _ false))))) diff --git a/stdlib/test/test/lux/data/text/lexer.lux b/stdlib/test/test/lux/data/text/lexer.lux index 8a63cf573..f9b6bdc79 100644 --- a/stdlib/test/test/lux/data/text/lexer.lux +++ b/stdlib/test/test/lux/data/text/lexer.lux @@ -3,7 +3,7 @@ (lux (control monad pipe) [io] - (data [error #- fail] + (data ["E" result] [text "T/" Eq] text/format ["&" text/lexer] @@ -14,13 +14,13 @@ ## [Utils] (def: (should-fail input) - (All [a] (-> (Error a) Bool)) + (All [a] (-> (E;Result a) Bool)) (case input (#;Left _) true _ false)) (def: (should-passC test input) - (-> Char (Error Char) Bool) + (-> Char (E;Result Char) Bool) (case input (#;Right output) (C/= test output) @@ -29,7 +29,7 @@ false)) (def: (should-passT test input) - (-> Text (Error Text) Bool) + (-> Text (E;Result Text) Bool) (case input (#;Right output) (T/= test output) @@ -38,7 +38,7 @@ false)) (def: (should-passL test input) - (-> (List Char) (Error (List Char)) Bool) + (-> (List Char) (E;Result (List Char)) Bool) (let [(^open "L/") (list;Eq char;Eq)] (case input (#;Right output) @@ -48,7 +48,7 @@ false))) (def: (should-passE test input) - (-> (Either Char Char) (Error (Either Char Char)) Bool) + (-> (Either Char Char) (E;Result (Either Char Char)) Bool) (case input (#;Right output) (case [test output] diff --git a/stdlib/test/test/lux/data/text/regex.lux b/stdlib/test/test/lux/data/text/regex.lux index 62953b20b..e4cfa2e10 100644 --- a/stdlib/test/test/lux/data/text/regex.lux +++ b/stdlib/test/test/lux/data/text/regex.lux @@ -3,8 +3,7 @@ (lux [io] (control monad pipe) - (data [error #- fail] - [product] + (data [product] [text "T/" Eq] text/format (text [lexer] diff --git a/stdlib/test/test/lux/macro/syntax.lux b/stdlib/test/test/lux/macro/syntax.lux index f75a7117e..0badc67f3 100644 --- a/stdlib/test/test/lux/macro/syntax.lux +++ b/stdlib/test/test/lux/macro/syntax.lux @@ -9,7 +9,7 @@ [bool] [char] [ident] - [error #- fail]) + ["E" result]) ["R" math/random] [macro] (macro [code] @@ -45,7 +45,7 @@ false)) (def: (fails? input) - (All [a] (-> (Error a) Bool)) + (All [a] (-> (E;Result a) Bool)) (case input (#;Left _) true diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index b3eaeb22c..b55373330 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -25,7 +25,7 @@ (data ["_;" bit] ["_;" bool] ["_;" char] - ["_;" error] + ["_;" result] ["_;" ident] ["_;" identity] ["_;" log] -- cgit v1.2.3