From bbf90b9f45576928652ac66df591103931b9fcd2 Mon Sep 17 00:00:00 2001 From: Chris Birchall Date: Tue, 15 Jan 2019 21:43:25 +0000 Subject: [PATCH] Add a unit test for ContT.defer --- tests/src/test/scala/cats/tests/ContTSuite.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/src/test/scala/cats/tests/ContTSuite.scala b/tests/src/test/scala/cats/tests/ContTSuite.scala index e4e6e28585..af8df13cea 100644 --- a/tests/src/test/scala/cats/tests/ContTSuite.scala +++ b/tests/src/test/scala/cats/tests/ContTSuite.scala @@ -64,4 +64,19 @@ class ContTSuite extends CatsSuite { withContLaw[Eval, Int, String, Int] } + test("ContT.defer defers evaluation until run is invoked") { + forAll { (b: Int, cb: Int => Eval[String]) => + var didSideEffect = false + + val contT = ContT.defer[Eval, String, Int] { + didSideEffect = true + b + } + didSideEffect should ===(false) + + contT.run(cb) + didSideEffect should ===(true) + } + } + }