Skip to content

Commit b237fb3

Browse files
committed
Test added
1 parent 9688625 commit b237fb3

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package scala.tools.nsc.transform.delambdafy
2+
3+
import scala.reflect.io.Path.jfile2path
4+
import scala.tools.nsc.backend.jvm.CodeGenTools.getGeneratedClassfiles
5+
import scala.tools.nsc.backend.jvm.CodeGenTools.makeSourceFile
6+
import scala.tools.nsc.backend.jvm.CodeGenTools.newCompilerWithoutVirtualOutdir
7+
import scala.tools.nsc.io.AbstractFile
8+
import scala.tools.testing.TempDir
9+
10+
import org.junit.Assert.assertTrue
11+
import org.junit.Test
12+
import org.junit.runner.RunWith
13+
import org.junit.runners.JUnit4
14+
15+
@RunWith(classOf[JUnit4])
16+
class DelambdafyTest {
17+
def compileToMultipleOutputWithDelamdbafyMethod(): List[(String, Array[Byte])] = {
18+
val codeForMultiOutput = """
19+
object Delambdafy {
20+
type -->[D, I] = PartialFunction[D, I]
21+
22+
def main(args: Array[String]): Unit = {
23+
val result = List(1, 2, 4).map { a =>
24+
val list = List("1", "2", "3").map { _ + "test" }
25+
list.find { _ == a.toString + "test" }
26+
}
27+
println(result)
28+
lazy val _foo = foo(result) {
29+
case x :: xs if x isDefined => x.get.length
30+
case _ => 0
31+
}
32+
println(_foo)
33+
lazy val bar: Int => Int = {
34+
case 2 => 23
35+
case _ =>
36+
val v = List(1).map { _ + 42 }.head
37+
v + 31
38+
}
39+
bar(3)
40+
lazy val _baz = baz {
41+
case 1 =>
42+
val local = List(1).map(_ + 1)
43+
local.head
44+
}
45+
}
46+
47+
def baz[T](f: Any --> Any): Any => Any = f
48+
49+
def foo(b: List[Option[String]])(a: List[Option[String]] => Int): Int = a(b)
50+
}
51+
"""
52+
val srcFile = makeSourceFile(codeForMultiOutput, "delambdafyTest.scala")
53+
val outDir = AbstractFile.getDirectory(TempDir.createTempDir())
54+
val outDirPath = outDir.canonicalPath
55+
val extraArgs = "-Ybackend:GenBCode -Ydelambdafy:method"
56+
val argsWithOutDir = extraArgs + s" -d $outDirPath -cp $outDirPath"
57+
val compiler = newCompilerWithoutVirtualOutdir(extraArgs = argsWithOutDir)
58+
compiler.settings.outputDirs.add(srcFile.file, outDir)
59+
60+
new compiler.Run().compileSources(List(srcFile))
61+
62+
val classfiles = getGeneratedClassfiles(outDir)
63+
outDir.delete()
64+
classfiles
65+
}
66+
67+
@Test
68+
def shouldFindOutputFoldersForAllPromotedLambdasAsMethod(): Unit = {
69+
val actual = compileToMultipleOutputWithDelamdbafyMethod()
70+
71+
assertTrue(actual.length > 0)
72+
}
73+
}

0 commit comments

Comments
 (0)