diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/test/scala/forge/ApplicativeTests.scala | 19 |
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 + ) + } } } |