Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

StandardProjectLayoutTest: add tests #3706

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}

}
Loading