Skip to content

Commit 673c72f

Browse files
committed
StandardProjectLayoutTest: add tests
1 parent e46fe8d commit 673c72f

File tree

2 files changed

+63
-6
lines changed

2 files changed

+63
-6
lines changed

scalafmt-core/shared/src/main/scala/org/scalafmt/config/ProjectFiles.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ object ProjectFiles {
128128
@inline private def is3(implicit dialect: Dialect) =
129129
dialect.allowSignificantIndentation
130130

131-
@inline private def nd(text: sourcecode.Text[Dialect]) =
131+
@inline private[config] def nd(text: sourcecode.Text[Dialect]) =
132132
Some(NamedDialect(text))
133-
private val s210 = nd(dialects.Scala210)
134-
private val s211 = nd(dialects.Scala211)
135-
private val s212 = nd(NamedDialect.scala212)
136-
private val s213 = nd(NamedDialect.scala213)
137-
private val s3 = nd(NamedDialect.scala3)
133+
private[config] val s210 = nd(dialects.Scala210)
134+
private[config] val s211 = nd(dialects.Scala211)
135+
private[config] val s212 = nd(NamedDialect.scala212)
136+
private[config] val s213 = nd(NamedDialect.scala213)
137+
private[config] val s3 = nd(NamedDialect.scala3)
138138

139139
override def getDialectByLang(lang: String)(implicit
140140
dialect: Dialect
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.scalafmt.config
2+
3+
import java.nio.file.Path
4+
import scala.meta.dialects
5+
6+
import org.scalafmt.sysops.AbsoluteFile
7+
8+
class StandordProjectLayoutTest extends munit.FunSuite {
9+
10+
import ProjectFiles.Layout.StandardConvention._
11+
12+
Seq(
13+
"/prj/src/main/scalaX/file" -> "scalaX",
14+
"/prj/src/main/scalaX/src/file" -> "scalaX",
15+
"/prj/src/main/scalaX/src/x/file" -> "scalaX",
16+
"/prj/src/main/scalaX/test/src/file" -> "scalaX",
17+
"/prj/src/main/scalaX/src/x/test/file" -> "scalaX",
18+
"/prj/src/main/scalaX/test/src/y/file" -> "scalaX",
19+
"/prj/src/main/scalaX/x/test/src/file" -> "scalaX",
20+
"/prj/src/main/scalaX/test/y/src/file" -> "scalaX",
21+
"/prj/src/main/scalaX/src/x/src/x/file" -> "scalaX"
22+
).foreach { case (path, expectedLang) =>
23+
test(s"StandardConvention.getLang($path) == $expectedLang") {
24+
val file = AbsoluteFile(Path.of(path))
25+
val actualLang = getLang(file)
26+
assertEquals(actualLang.orNull, expectedLang)
27+
}
28+
}
29+
30+
Seq(
31+
(s210, "scala-2.10", None),
32+
(s211, "scala-2.10", s210),
33+
(s210, "scala-2.11", s211),
34+
(s211, "scala-2.11", None),
35+
(s212, "scala-2.11", s211),
36+
(s211, "scala-2.12", s212),
37+
(s212, "scala-2.12", None),
38+
(s213, "scala-2.12", s212),
39+
(s212, "scala-2.13", s213),
40+
(s213, "scala-2.13", None),
41+
(s3, "scala-2.13", s213),
42+
(s212, "scala-2", None),
43+
(s213, "scala-2", None),
44+
(s3, "scala-2", s213),
45+
(s213, "scala-3", s3),
46+
(s3, "scala-3", None),
47+
(nd(dialects.Scala3Future), "scala-3", None)
48+
).foreach { case (curDialectOpt, lang, expDialectOpt) =>
49+
val curName = curDialectOpt.map(_.name).orNull
50+
val expName = expDialectOpt.map(_.name).orNull
51+
test(s"StandardConvention.getDialectByLang($lang)($curName) == $expName") {
52+
val initDialect = curDialectOpt.fold(dialects.Scala3Future)(_.dialect)
53+
assertEquals(getDialectByLang(lang)(initDialect), expDialectOpt)
54+
}
55+
}
56+
57+
}

0 commit comments

Comments
 (0)