diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ProjectFiles.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ProjectFiles.scala index 4ecc0dbb97..03d227039b 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ProjectFiles.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/config/ProjectFiles.scala @@ -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 diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/config/StandordProjectLayoutTest.scala b/scalafmt-tests/src/test/scala/org/scalafmt/config/StandordProjectLayoutTest.scala new file mode 100644 index 0000000000..9bdc4b82a4 --- /dev/null +++ b/scalafmt-tests/src/test/scala/org/scalafmt/config/StandordProjectLayoutTest.scala @@ -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) + } + } + +}