Skip to content

Commit

Permalink
Json snapshot tests (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol authored Mar 21, 2024
1 parent 5981e3b commit 3e1e202
Show file tree
Hide file tree
Showing 112 changed files with 11,034 additions and 79 deletions.
23 changes: 16 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ inThisBuild(
)

val V = new {
val scala = "3.3.0"
val scribe = "3.11.1"
val scala = "3.3.3"
val scribe = "3.13.1"
val upickle = "2.0.0"
val cats = "2.9.0"
val cats = "2.10.0"
val jsonrpclib = "0.0.5"
val fs2 = "3.5.0"
val http4s = "0.23.23"
val fs2 = "3.10.0"
val http4s = "0.23.26"
val laminar = "0.14.5"
val decline = "2.4.1"
val jsoniter = "2.20.3"
val weaver = "0.8.3"
val weaver = "0.8.4"
val circe = "0.14.5"
val http4sJdkClient = "0.9.1"
val organizeImports = "0.6.0"
Expand Down Expand Up @@ -192,8 +192,17 @@ lazy val tests = projectMatrix
.settings(
libraryDependencies += "org.http4s" %% "http4s-jdk-http-client" % V.http4sJdkClient % Test,
libraryDependencies += "com.disneystreaming" %%% "weaver-cats" % V.weaver % Test,
Test / fork := virtualAxes.value.contains(VirtualAxis.jvm)
libraryDependencies += "com.lihaoyi" %%% "pprint" % "0.8.1" % Test,
libraryDependencies += "org.typelevel" %%% "shapeless3-deriving" % "3.4.1" % Test,
libraryDependencies += "org.scalacheck" %%% "scalacheck" % "1.17.0" % Test,
libraryDependencies += "io.github.irevive" %%% "union-derivation-core" % "0.1.0" % Test,
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
Test / fork := virtualAxes.value.contains(VirtualAxis.jvm),
snapshotsPackageName := "tests.core",
snapshotsForceOverwrite := !sys.env.contains("CI"),
scalacOptions += "-Yretain-trees"
)
.enablePlugins(SnapshotsPlugin)

lazy val example = projectMatrix
.in(file("modules/example"))
Expand Down
11 changes: 10 additions & 1 deletion modules/generate/src/main/scala/render.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ class Render(manager: Manager, packageName: String = "langoustine.lsp"):
if a.values.nonEmpty then
line(s"object ${a.name} extends $impl[${a.name}]:")
nest {
val rendered = List.newBuilder[String]
a.values.foreach { entry =>
val value =
base match
Expand All @@ -1083,9 +1084,17 @@ class Render(manager: Manager, packageName: String = "langoustine.lsp"):
cw.commentLine(d.value)
}
}
line(s"val ${sanitise(entry.name.value)} = entry($value)")
val entryName = sanitise(entry.name.value)
rendered += entryName
line(s"val ${entryName} = entry($value)")
}

line("override def ALL = Set(")
nest {
line(rendered.result.mkString(", "))
}
line(")")

}
end if
line("")
Expand Down
27 changes: 27 additions & 0 deletions modules/lsp/src/main/scala/enumTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,24 @@ import runtime.*
import upickle.default.*
import scala.reflect.*

trait Bijection[A, T]:
def apply(a: A): T
def reverse(a: T): A
def domain: Set[A]

private[lsp] trait IntEnum[T](using ev: T =:= Int):
private val intCodec = upickle.default.readwriter[Int]
given reader: Reader[T] = intCodec.asInstanceOf[Reader[T]]
given writer: Writer[T] = intCodec.asInstanceOf[Writer[T]]

protected def ALL: Set[T]

given Bijection[T, Int] with
def apply(a: T): Int = ev.apply(a)
def reverse(a: Int): T =
ev.flip.apply(a)
lazy val domain = ALL

given Typeable[T] with
def unapply(s: Any): Option[s.type & T] =
s match
Expand All @@ -42,6 +55,12 @@ private[lsp] trait StringEnum[T](using ev: T =:= String):
private val stringCodec = upickle.default.readwriter[String]
given reader: Reader[T] = stringCodec.asInstanceOf[Reader[T]]
given writer: Writer[T] = stringCodec.asInstanceOf[Writer[T]]
protected def ALL: Set[T]

given Bijection[T, String] with
def apply(a: T): String = ev.apply(a)
def reverse(a: String): T = ev.flip.apply(a)
lazy val domain = ALL

given Typeable[T] with
def unapply(s: Any): Option[s.type & T] =
Expand All @@ -61,6 +80,14 @@ private[lsp] trait UIntEnum[T](using ev: T =:= uinteger):
given reader: Reader[T] = intCodec.asInstanceOf[Reader[T]]
given writer: Writer[T] = intCodec.asInstanceOf[Writer[T]]

protected def ALL: Set[T]

given Bijection[T, uinteger] with
def apply(a: T): uinteger = ev.apply(a)
def reverse(a: uinteger): T =
ev.flip.apply(a)
lazy val domain = ALL

given Typeable[T] with
def unapply(s: Any): Option[s.type & T] =
s match
Expand Down
Loading

0 comments on commit 3e1e202

Please sign in to comment.