calrissian/test/unit/unit-error-monad-tests.lfe

37 lines
964 B
Text
Raw Normal View History

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")
(test-monad 'error-monad)
2014-04-25 17:02:16 +00:00
(deftest return-ok
(is-equal 'ok
(return 'error-monad 'ok)))
2014-04-25 17:02:16 +00:00
(deftest return-value
(is-equal #(ok 123)
(return 'error-monad 123)))
2014-04-25 17:02:16 +00:00
(deftest fail-with-reason
(is-equal #(error reason)
(fail 'error-monad 'reason)))
2014-04-25 17:02:16 +00:00
(deftest fail-short-circuits-value
(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)
(>> 'error-monad
(fail 'error-monad 'something-bad)
2014-04-25 17:02:16 +00:00
(throw 'error))))