Skip to content

Commit

Permalink
StandardProjectLayoutTest: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 26, 2023
1 parent a90c3d0 commit a5be500
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ object ProjectFiles {
@inline private def is3(implicit dialect: Dialect) =
dialect.allowSignificantIndentation

@inline private def nd(text: sourcecode.Text[Dialect]) =
@inline private[config] def nd(text: sourcecode.Text[Dialect]) =
Some(NamedDialect(text))
private val s210 = nd(dialects.Scala210)
private val s211 = nd(dialects.Scala211)
private val s212 = nd(NamedDialect.scala212)
private val s213 = nd(NamedDialect.scala213)
private val s3 = nd(NamedDialect.scala3)
private[config] val s210 = nd(dialects.Scala210)
private[config] val s211 = nd(dialects.Scala211)
private[config] val s212 = nd(NamedDialect.scala212)
private[config] val s213 = nd(NamedDialect.scala213)
private[config] val s3 = nd(NamedDialect.scala3)

override def getDialectByLang(lang: String)(implicit
dialect: Dialect
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.scalafmt.config

import scala.meta.dialects

import org.scalafmt.sysops.AbsoluteFile

class StandordProjectLayoutTest extends munit.FunSuite {

import ProjectFiles.Layout.StandardConvention._

Seq(
"/prj/src/main/scalaX/src" -> "scalaX",
"/prj/src/main/scalaX/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/src/src/src" -> "scalaX",
"/prj/src/main/scalaX/test/src" -> "scalaX",
"/prj/src/main/scalaX/src/test" -> "scalaX",
"/prj/src/main/scalaX/test/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/test/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/test" -> "scalaX",
"/prj/src/main/scalaX/test/src/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/test/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/src/test" -> "scalaX",
"/prj/src/main/scalaX/test/src/src/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/src/test/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/src/src/test" -> "scalaX",
"/prj/src/main/scalaX/x/test/src/src" -> "scalaX",
"/prj/src/main/scalaX/x/test/src/src/src" -> "scalaX",
"/prj/src/main/scalaX/x/test/src/src/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/x/src/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/x/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/src/x/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/src/src/x" -> "scalaX",
"/prj/src/main/scalaX/src/x/src/src/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/x/src/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/src/x/src/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/src/src/x/src" -> "scalaX",
"/prj/src/main/scalaX/src/src/src/src/src/x" -> "scalaX"
).foreach { case (path, expectedLang) =>
test(s"StandardConvention.getLang($path) == $expectedLang") {
val actualLang = getLang(AbsoluteFile(path))
assertEquals(actualLang.orNull, expectedLang)
}
}

Seq(
(s210, "scala-2.10", None),
(s211, "scala-2.10", s210),
(s210, "scala-2.11", s211),
(s211, "scala-2.11", None),
(s212, "scala-2.11", s211),
(s211, "scala-2.12", s212),
(s212, "scala-2.12", None),
(s213, "scala-2.12", s212),
(s212, "scala-2.13", s213),
(s213, "scala-2.13", None),
(s3, "scala-2.13", s213),
(s212, "scala-2", None),
(s213, "scala-2", None),
(s3, "scala-2", s213),
(s213, "scala-3", s3),
(s3, "scala-3", None),
(nd(dialects.Scala3Future), "scala-3", None)
).foreach { case (curDialectOpt, lang, expDialectOpt) =>
val curName = curDialectOpt.map(_.name).orNull
val expName = expDialectOpt.map(_.name).orNull
test(s"StandardConvention.getDialectByLang($lang)($curName) == $expName") {
val initDialect = curDialectOpt.fold(dialects.Scala3Future)(_.dialect)
assertEquals(getDialectByLang(lang)(initDialect), expDialectOpt)
}
}

}

0 comments on commit a5be500

Please sign in to comment.