From 531889f410e72460fb5fcd5c061f31cead2026d2 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sun, 5 Nov 2017 12:38:28 -0800 Subject: Add multiple-identical-apply-calls unit test --- core/src/test/scala/forge/ApplicativeTests.scala | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'core') diff --git a/core/src/test/scala/forge/ApplicativeTests.scala b/core/src/test/scala/forge/ApplicativeTests.scala index 621dc679..aff635f5 100644 --- a/core/src/test/scala/forge/ApplicativeTests.scala +++ b/core/src/test/scala/forge/ApplicativeTests.scala @@ -106,6 +106,16 @@ object ApplicativeTests extends TestSuite { down2 == Some(Seq("hello2", "hello2hello2", "hello2hello2hello2")) ) } + 'appliesEvaluatedOncePerLexicalCallsite - { + // If you have multiple Applyable#apply() lexically in the source code of + // your Opt{...} call, each one gets evaluated once, even if the LHS of each + // apply() call is identical. It's up to the downstream zipMap() + // implementation to decide if it wants to dedup them or do other things. + val counter = new Counter() + def up = Opt{ "hello" + counter() } + val down = Opt{ Seq(1, 2, 3).map(n => n + up() + up()) } + assert(down == Some(Seq("1hello1hello2", "2hello1hello2", "3hello1hello2"))) + } } } -- cgit v1.2.3