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

37 lines
995 B
Text
Raw Normal View History

2014-07-10 01:19:14 +00:00
(defmodule unit-calrissian-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-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))))