summaryrefslogtreecommitdiff
path: root/core/src/test/scala/forge/ApplicativeTests.scala
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-05 08:23:21 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-05 08:23:21 -0800
commit404a677955ae54fdfabb8d1001a5ed7a80778044 (patch)
treedfc567b62f550a649e116c4cb95c70ff1a35076b /core/src/test/scala/forge/ApplicativeTests.scala
parent8a873f3336400035a9fae5ed64a57b022d9b48da (diff)
downloadmill-404a677955ae54fdfabb8d1001a5ed7a80778044.tar.gz
mill-404a677955ae54fdfabb8d1001a5ed7a80778044.tar.bz2
mill-404a677955ae54fdfabb8d1001a5ed7a80778044.zip
More `ApplicativeTests`
Diffstat (limited to 'core/src/test/scala/forge/ApplicativeTests.scala')
-rw-r--r--core/src/test/scala/forge/ApplicativeTests.scala19
1 files changed, 15 insertions, 4 deletions
diff --git a/core/src/test/scala/forge/ApplicativeTests.scala b/core/src/test/scala/forge/ApplicativeTests.scala
index 462cb180..000554ef 100644
--- a/core/src/test/scala/forge/ApplicativeTests.scala
+++ b/core/src/test/scala/forge/ApplicativeTests.scala
@@ -71,10 +71,9 @@ object ApplicativeTests extends TestSuite {
assert(res == Some("lol hello"))
}
'upstreamAlwaysEvaluated - {
- // Validate the assumption that whether or not control-flow reaches the
- // Applyable#apply call inside an Opt{...} block, we always evaluate the
- // LHS of the Applyable#apply because it gets lifted out of any control
- // flow statements
+ // Whether or not control-flow reaches the Applyable#apply call inside an
+ // Opt{...} block, we always evaluate the LHS of the Applyable#apply
+ // because it gets lifted out of any control flow statements
val counter = new Counter()
def up = Opt{ "lol " + counter() }
val down = Opt{ if ("lol".length > 10) up() else "fail" }
@@ -83,6 +82,18 @@ object ApplicativeTests extends TestSuite {
counter.value == 1
)
}
+ 'upstreamEvaluatedOnlyOnce - {
+ // Even if control-flow reaches the Applyable#apply call more than once,
+ // it only gets evaluated once due to its lifting out of the Opt{...} block
+ val counter = new Counter()
+ def up = Opt{ "lol " + counter() }
+ def runTwice[T](t: => T) = (t, t)
+ val down = Opt{ runTwice(up()) }
+ assert(
+ down == Some(("lol 1", "lol 1")),
+ counter.value == 1
+ )
+ }
}
}