diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-05 12:44:05 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-05 12:44:05 -0800 |
commit | 2fd4c498cc005182ef65a20db30f461f0893508a (patch) | |
tree | 5c9c7c76f394e13a9f5799291a1dd45948f9ca22 /core/src/test | |
parent | 531889f410e72460fb5fcd5c061f31cead2026d2 (diff) | |
download | mill-2fd4c498cc005182ef65a20db30f461f0893508a.tar.gz mill-2fd4c498cc005182ef65a20db30f461f0893508a.tar.bz2 mill-2fd4c498cc005182ef65a20db30f461f0893508a.zip |
Add test to verify before-hand evaluation order of `Applyable#apply` calls
Diffstat (limited to 'core/src/test')
-rw-r--r-- | core/src/test/scala/forge/ApplicativeTests.scala | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/core/src/test/scala/forge/ApplicativeTests.scala b/core/src/test/scala/forge/ApplicativeTests.scala index aff635f5..f5c725a2 100644 --- a/core/src/test/scala/forge/ApplicativeTests.scala +++ b/core/src/test/scala/forge/ApplicativeTests.scala @@ -116,6 +116,21 @@ object ApplicativeTests extends TestSuite { val down = Opt{ Seq(1, 2, 3).map(n => n + up() + up()) } assert(down == Some(Seq("1hello1hello2", "2hello1hello2", "3hello1hello2"))) } + 'appliesEvaluateBeforehand - { + // Every Applyable#apply() within a Opt{...} block evaluates before any + // other logic within that block, even if they would happen first in the + // normal Scala evaluation order + val counter = new Counter() + def up = Opt{ counter() } + val down = Opt{ + val res = counter() + val one = up() + val two = up() + val three = up() + (res, one, two, three) + } + assert(down == Some((4, 1, 2, 3))) + } } } |