Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahjohannessen committed Feb 23, 2024
1 parent 3190e1e commit 7fdb505
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import play.twirl.parser.TwirlIO
object Helper {
case class CompilationError(message: String, line: Int, column: Int) extends RuntimeException(message)

class CompilerHelper(sourceDir: File, generatedDir: File, generatedClasses: File) {
class CompilerHelper(sourceDir: File, val generatedDir: File, generatedClasses: File) {
import java.net._
import scala.collection.mutable
import scala.reflect.internal.util.Position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import play.twirl.parser.TwirlIO
object Helper {
case class CompilationError(message: String, line: Int, column: Int) extends RuntimeException(message)

class CompilerHelper(sourceDir: File, generatedDir: File, generatedClasses: File) {
class CompilerHelper(sourceDir: File, val generatedDir: File, generatedClasses: File) {
import java.net._
import scala.collection.mutable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import play.twirl.api.Html
import play.twirl.parser.TwirlIO
import org.scalatest.matchers.must.Matchers
import org.scalatest.wordspec.AnyWordSpec
import TwirlCompiler.ScalaCompat
import scala.io.Source

class CompilerSpec extends AnyWordSpec with Matchers {

Expand Down Expand Up @@ -159,6 +161,12 @@ class CompilerSpec extends AnyWordSpec with Matchers {
.static(Array(List(1, 2, 3), List(4, 5, 6)))
.toString
.trim

val compat = ScalaCompat(Option(BuildInfo.scalaVersion))
val generatedFile = helper.generatedDir.toPath.resolve("html/varArgsExistential.template.scala").toFile
val generatedText = Source.fromFile(generatedFile).getLines().mkString("\n")

generatedText must include(s"list.toIndexedSeq${compat.varargSplicesSyntax}")
text must be("123456")
}

Expand Down Expand Up @@ -329,4 +337,24 @@ class CompilerSpec extends AnyWordSpec with Matchers {
)
hello.static(args).toString.trim must be("the-key => the-value")
}

"ScalaCompat" should {

val cases = List(
None -> ": _*",
Some("2.12.18") -> ": _*",
Some("2.13.12") -> ": _*",
Some("3.3.1") -> "*"
)

"produce correct varargs splice syntax" in {

cases.foreach { case (version, expected) =>
ScalaCompat(version).varargSplicesSyntax must be(expected)
}

}

}

}

0 comments on commit 7fdb505

Please sign in to comment.