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

34 lines
929 B
Text
Raw Permalink Normal View History

2014-07-10 01:19:14 +00:00
(defmodule unit-calrissian-error-monad-tests
2015-05-21 22:31:11 +00:00
(behaviour ltest-unit)
(export all))
2014-07-10 01:19:14 +00:00
2015-05-21 22:31:11 +00:00
(include-lib "ltest/include/ltest-macros.lfe")
(include-lib "calrissian/include/monads.lfe")
(include-lib "calrissian/include/monad-tests.lfe")
2014-07-10 01:19:14 +00:00
2014-07-10 02:28:06 +00:00
(test-monad (monad 'error))
2014-07-10 01:19:14 +00:00
(deftest return-ok
(is-equal 'ok
2014-07-10 02:28:06 +00:00
(return (monad 'error) 'ok)))
2014-07-10 01:19:14 +00:00
(deftest return-value
(is-equal #(ok 123)
2014-07-10 02:28:06 +00:00
(return (monad 'error) 123)))
2014-07-10 01:19:14 +00:00
(deftest fail-with-reason
(is-equal #(error reason)
2014-07-10 02:28:06 +00:00
(fail (monad 'error) 'reason)))
2014-07-10 01:19:14 +00:00
(deftest fail-short-circuits-value
2014-07-10 02:28:06 +00:00
(is-equal (fail (monad 'error) 'something-bad)
(>> (monad 'error)
(fail (monad 'error) 'something-bad)
(return (monad 'error) 123))))
2014-07-10 01:19:14 +00:00
(deftest fail-short-circuits-error
(is-equal #(error something-bad)
2014-07-10 02:28:06 +00:00
(>> (monad 'error)
(fail (monad 'error) 'something-bad)
2014-07-10 01:19:14 +00:00
(throw 'error))))