forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infrastructure to run the JUnit tests of upstream Scala.js.
And run one test for now: `compiler/IntTest.scala`.
- Loading branch information
Showing
4 changed files
with
184 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import scala.annotation.tailrec | ||
|
||
import sbt._ | ||
|
||
import org.scalajs.ir.ScalaJSVersions | ||
|
||
object ConstantHolderGenerator { | ||
/** Generate a *.scala file that contains the given values as literals. */ | ||
def generate(dir: File, fqn: String, values: (String, Any)*): Seq[File] = { | ||
val (fullPkg@(_ :+ pkg)) :+ objectName = fqn.split('.').toSeq | ||
|
||
val out = dir / (objectName + ".scala") | ||
|
||
val defs = for { | ||
(name, value) <- values | ||
} yield { | ||
s"val $name = ${literal(value)}" | ||
} | ||
|
||
val scalaCode = | ||
s""" | ||
package ${fullPkg.mkString(".")} | ||
|
||
private[$pkg] object $objectName { | ||
${defs.mkString("\n")} | ||
} | ||
""" | ||
|
||
IO.write(out, scalaCode) | ||
|
||
Seq(out) | ||
} | ||
|
||
@tailrec | ||
private final def literal(v: Any): String = v match { | ||
case s: String => "raw\"\"\"" + s + "\"\"\"" | ||
case b: Boolean => b.toString | ||
case f: File => literal(f.getAbsolutePath) | ||
|
||
case _ => | ||
throw new IllegalArgumentException( | ||
"Unsupported value type: " + v.getClass) | ||
} | ||
} |