|
| 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