Skip to content
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
5 changes: 5 additions & 0 deletions CompareApp.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// receive 2 file paths as input and compare the files, exit with status code 0 if there was no breaking change, 1 otherwise
//> using scala "2.13.16"
//> using dep "org.scalameta::scalameta:4.13.9"
//> using test.dep "org.scalameta::munit::0.7.29"
//> using resourceDir "./resources"
//> using dep "com.lihaoyi::upickle::4.2.1"
import java.nio.file.{Paths, Files}
import java.nio.charset.StandardCharsets
import BreakingChangeDetector.CompareSummary._
Expand Down
6 changes: 0 additions & 6 deletions project.scala

This file was deleted.

1 change: 1 addition & 0 deletions resources/scala-3/Scala3Class.scala_test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case class Scala3Class(a: Int)(using b: String)
13 changes: 10 additions & 3 deletions src/FileParser.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.meta._
import scala.meta.Dialect

case class ScalaFile(
imports: List[String],
Expand Down Expand Up @@ -44,9 +45,11 @@ object FileParser {
}
}

def parse(content: String): ScalaFile = {
def parse(
content: String,
dialect: Dialect = dialects.Scala213Source3
): ScalaFile = {
val input = Input.String(content)
val dialect = dialects.Scala213Source3
val exampleTree: Source = dialect(input).parse[Source].get

val tree =
Expand Down Expand Up @@ -78,6 +81,10 @@ object FileParser {
val path = java.nio.file.Paths.get(filePath)
val bytes = java.nio.file.Files.readAllBytes(path)
val text = new String(bytes, "UTF-8")
parse(text)
val dialect =
if (filePath.split(java.io.File.separator).contains("scala-3"))
dialects.Scala3
else dialects.Scala213Source3
parse(text, dialect)
}
}
2 changes: 1 addition & 1 deletion test/BreakingChangeDetector.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class BreakingChangeDetectorTest extends munit.FunSuite {
compared.find(_.isBreakingChange).nonEmpty
)
}

runWithFiles("V10.scala_test.prev", "V10.scala_test")
runWithFiles("V10.scala_test", "V10.scala_test.prev")
}
Expand Down
9 changes: 9 additions & 0 deletions test/FileParser.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,13 @@ class FileParserTest extends munit.FunSuite {
val parsedFile = FileParser.fromPathToClassDef(file)
println(parsedFile)
}
test("uses Scala3 dialect for sources in scala-3 directory") {
val file = Thread
.currentThread()
.getContextClassLoader
.getResource("scala-3/Scala3Class.scala_test")
.getPath
val parsedFile = FileParser.fromPathToClassDef(file)
assert(parsedFile.classes.head.name == "Scala3Class")
}
}