2014-04-25 17:02:16 +00:00
|
|
|
(defmodule unit-error-monad-tests
|
|
|
|
(export all)
|
|
|
|
(import
|
|
|
|
(from lfeunit-util
|
|
|
|
(check-failed-assert 2)
|
|
|
|
(check-wrong-assert-exception 2))))
|
|
|
|
|
|
|
|
(include-lib "deps/lfeunit/include/lfeunit-macros.lfe")
|
|
|
|
(include-lib "include/monads.lfe")
|
|
|
|
(include-lib "include/monad-tests.lfe")
|
|
|
|
|
2014-05-13 23:30:46 +00:00
|
|
|
(test-monad 'error-monad)
|
2014-04-25 17:02:16 +00:00
|
|
|
|
|
|
|
(deftest return-ok
|
|
|
|
(is-equal 'ok
|
2014-05-13 23:30:46 +00:00
|
|
|
(return 'error-monad 'ok)))
|
2014-04-25 17:02:16 +00:00
|
|
|
|
|
|
|
(deftest return-value
|
|
|
|
(is-equal #(ok 123)
|
2014-05-13 23:30:46 +00:00
|
|
|
(return 'error-monad 123)))
|
2014-04-25 17:02:16 +00:00
|
|
|
|
|
|
|
(deftest fail-with-reason
|
|
|
|
(is-equal #(error reason)
|
2014-05-13 23:30:46 +00:00
|
|
|
(fail 'error-monad 'reason)))
|
2014-04-25 17:02:16 +00:00
|
|
|
|
|
|
|
(deftest fail-short-circuits-value
|
2014-05-13 23:30:46 +00:00
|
|
|
(is-equal (fail 'error-monad 'something-bad)
|
|
|
|
(>> 'error-monad
|
|
|
|
(fail 'error-monad 'something-bad)
|
|
|
|
(return 'error-monad 123))))
|
2014-04-25 17:02:16 +00:00
|
|
|
|
|
|
|
(deftest fail-short-circuits-error
|
|
|
|
(is-equal #(error something-bad)
|
2014-05-13 23:30:46 +00:00
|
|
|
(>> 'error-monad
|
|
|
|
(fail 'error-monad 'something-bad)
|
2014-04-25 17:02:16 +00:00
|
|
|
(throw 'error))))
|