2014-07-10 01:19:14 +00:00
|
|
|
(defmodule unit-calrissian-error-monad-tests
|
2014-08-22 02:40:41 +00:00
|
|
|
(behaviour ltest-unit)
|
2014-07-10 01:19:14 +00:00
|
|
|
(export all)
|
|
|
|
(import
|
2014-08-22 02:40:41 +00:00
|
|
|
(from ltest
|
2014-07-10 01:19:14 +00:00
|
|
|
(check-failed-assert 2)
|
|
|
|
(check-wrong-assert-exception 2))))
|
|
|
|
|
2014-08-22 02:40:41 +00:00
|
|
|
(include-lib "deps/ltest/include/ltest-macros.lfe")
|
2014-07-10 01:19:14 +00:00
|
|
|
(include-lib "include/monads.lfe")
|
|
|
|
(include-lib "include/monad-tests.lfe")
|
|
|
|
|
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))))
|