Skip to content

Commit

Permalink
Merge pull request #259 from adpi2/scalajs-support
Browse files Browse the repository at this point in the history
Scala.js support in macroUtils, tagged and opaque
  • Loading branch information
pk044 committed Dec 8, 2022
2 parents 1ab7d68 + 6bec7e3 commit 7f3cade
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 42 deletions.
64 changes: 36 additions & 28 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lazy val baseSettings = Seq(
organizationName := "Iterators",
organizationHomepage := Some(url("https://iterato.rs")),
homepage := Some(url("https://github.com/theiterators/kebs")),
scalacOptions := Seq("-deprecation", "-unchecked", "-feature", "-encoding", "utf8")
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-encoding", "utf8")
)

lazy val commonMacroSettings = baseSettings ++ Seq(
Expand Down Expand Up @@ -104,20 +104,19 @@ def paradisePlugin(scalaVersion: String): Seq[ModuleID] =
else
Seq.empty

val scalaTest = "org.scalatest" %% "scalatest" % "3.2.14"
val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.17.0"
val scalaTest = Def.setting("org.scalatest" %%% "scalatest" % "3.2.14")
val scalaCheck = Def.setting("org.scalacheck" %%% "scalacheck" % "1.17.0")
val slick = "com.typesafe.slick" %% "slick" % "3.4.1"
val optionalSlick = optional(slick)
val playJson = "com.typesafe.play" %% "play-json" % "2.9.3"
val slickPg = "com.github.tminglei" %% "slick-pg" % "0.21.1"
val doobie = "org.tpolecat" %% "doobie-core" % "1.0.0-RC2"
val doobiePg = "org.tpolecat" %% "doobie-postgres" % "1.0.0-RC2"
val sprayJson = "io.spray" %% "spray-json" % "1.3.6"
val circe = "io.circe" %% "circe-core" % "0.14.3"
val circe = Def.setting("io.circe" %%% "circe-core" % "0.14.3")
val circeAuto = "io.circe" %% "circe-generic" % "0.14.3"
val circeAutoExtras = "io.circe" %% "circe-generic-extras" % "0.14.3"
val circeParser = "io.circe" %% "circe-parser" % "0.14.3"
val optionalCirce = optional(circe)

val jsonschema = "com.github.andyglow" %% "scala-jsonschema" % "0.7.9"

Expand Down Expand Up @@ -158,7 +157,7 @@ lazy val commonSettings = baseSettings ++ Seq(
Seq("-language:implicitConversions", "-Ykind-projector", "-Xignore-scala2-macros")
else Seq("-language:implicitConversions", "-language:experimental.macros")),
// (scalacOptions in Test) ++= Seq("-Ymacro-debug-lite" /*, "-Xlog-implicits"*/ ),
libraryDependencies += scalaTest % "test"
libraryDependencies += scalaTest.value % "test"
)

lazy val slickSettings = commonSettings ++ Seq(
Expand All @@ -174,7 +173,7 @@ lazy val doobieSettings = commonSettings ++ Seq(
)

lazy val macroUtilsSettings = commonMacroSettings ++ Seq(
libraryDependencies += (scalaCheck % "test").cross(CrossVersion.for3Use2_13),
libraryDependencies += (scalaCheck.value % "test").cross(CrossVersion.for3Use2_13),
libraryDependencies += optionalEnumeratum
)

Expand All @@ -191,7 +190,7 @@ lazy val playJsonSettings = commonSettings ++ Seq(
)

lazy val circeSettings = commonSettings ++ Seq(
libraryDependencies += circe,
libraryDependencies += circe.value,
libraryDependencies += circeAuto,
libraryDependencies += circeAutoExtras.cross(CrossVersion.for3Use2_13),
libraryDependencies += optionalEnumeratum.cross(CrossVersion.for3Use2_13),
Expand Down Expand Up @@ -226,7 +225,7 @@ lazy val scalacheckSettings = commonSettings ++ Seq(

lazy val taggedSettings = commonSettings ++ Seq(
libraryDependencies += optionalSlick.cross(CrossVersion.for3Use2_13),
libraryDependencies += optionalCirce
libraryDependencies += optional(circe.value)
)

lazy val opaqueSettings = commonSettings
Expand All @@ -241,19 +240,21 @@ lazy val examplesSettings = commonSettings ++ Seq(
)

lazy val benchmarkSettings = commonSettings ++ Seq(
libraryDependencies += scalaTest,
libraryDependencies += scalaTest.value,
libraryDependencies += enumeratum.cross(CrossVersion.for3Use2_13),
libraryDependencies ++= akkaHttpInBenchmarks
)

lazy val taggedMetaSettings = metaSettings ++ Seq(
libraryDependencies += optional(sprayJson.cross(CrossVersion.for3Use2_13)),
libraryDependencies += optional(circe)
libraryDependencies += optional(circe.value)
)

lazy val instancesSettings = commonSettings

lazy val macroUtils = project
lazy val macroUtils = crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("macro-utils"))
.settings(macroUtilsSettings: _*)
.settings(publishSettings: _*)
Expand All @@ -265,7 +266,7 @@ lazy val macroUtils = project

lazy val slickSupport = project
.in(file("slick"))
.dependsOn(macroUtils, instances)
.dependsOn(macroUtils.jvm, instances)
.settings(slickSettings: _*)
.settings(publishSettings: _*)
.settings(disableScala("3"))
Expand All @@ -278,7 +279,7 @@ lazy val slickSupport = project

lazy val doobieSupport = project
.in(file("doobie"))
.dependsOn(instances, opaque)
.dependsOn(instances, opaque.jvm)
.settings(doobieSettings: _*)
.settings(publishSettings: _*)
.settings(
Expand All @@ -290,7 +291,7 @@ lazy val doobieSupport = project

lazy val sprayJsonMacros = project
.in(file("spray-json-macros"))
.dependsOn(macroUtils)
.dependsOn(macroUtils.jvm)
.settings(sprayJsonMacroSettings: _*)
.settings(publishSettings: _*)
.settings(disableScala("3"))
Expand All @@ -316,7 +317,7 @@ lazy val sprayJsonSupport = project

lazy val playJsonSupport = project
.in(file("play-json"))
.dependsOn(macroUtils, instances)
.dependsOn(macroUtils.jvm, instances)
.settings(playJsonSettings: _*)
.settings(publishSettings: _*)
.settings(disableScala("3"))
Expand All @@ -329,7 +330,7 @@ lazy val playJsonSupport = project

lazy val circeSupport = project
.in(file("circe"))
.dependsOn(macroUtils, instances)
.dependsOn(macroUtils.jvm, instances)
.settings(circeSettings: _*)
.settings(crossBuildSettings: _*)
.settings(publishSettings: _*)
Expand All @@ -342,7 +343,7 @@ lazy val circeSupport = project

lazy val akkaHttpSupport = project
.in(file("akka-http"))
.dependsOn(macroUtils, instances, tagged % "test -> test", taggedMeta % "test -> test")
.dependsOn(macroUtils.jvm, instances, tagged.jvm % "test -> test", taggedMeta % "test -> test")
.settings(akkaHttpSettings: _*)
.settings(publishSettings: _*)
.settings(disableScala("3"))
Expand All @@ -355,7 +356,7 @@ lazy val akkaHttpSupport = project

lazy val http4sSupport = project
.in(file("http4s"))
.dependsOn(macroUtils, instances, opaque % "test -> test", tagged % "test -> test", taggedMeta % "test -> test")
.dependsOn(macroUtils.jvm, instances, opaque.jvm % "test -> test", tagged.jvm % "test -> test", taggedMeta % "test -> test")
.settings(http4sSettings: _*)
.settings(publishSettings: _*)
.settings(
Expand All @@ -367,7 +368,7 @@ lazy val http4sSupport = project

lazy val jsonschemaSupport = project
.in(file("jsonschema"))
.dependsOn(macroUtils)
.dependsOn(macroUtils.jvm)
.settings(jsonschemaSettings: _*)
.settings(publishSettings: _*)
.settings(disableScala("3"))
Expand All @@ -380,7 +381,7 @@ lazy val jsonschemaSupport = project

lazy val scalacheckSupport = project
.in(file("scalacheck"))
.dependsOn(macroUtils)
.dependsOn(macroUtils.jvm)
.settings(scalacheckSettings: _*)
.settings(publishSettings: _*)
.settings(disableScala("3"))
Expand All @@ -391,7 +392,9 @@ lazy val scalacheckSupport = project
crossScalaVersions := supportedScalaVersions
)

lazy val tagged = project
lazy val tagged = crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Full)
.in(file("tagged"))
.dependsOn(macroUtils)
.settings(taggedSettings: _*)
Expand All @@ -404,7 +407,9 @@ lazy val tagged = project
crossScalaVersions := supportedScalaVersions
)

lazy val opaque = project
lazy val opaque = crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("opaque"))
.dependsOn(macroUtils)
.settings(opaqueSettings: _*)
Expand All @@ -422,8 +427,8 @@ lazy val opaque = project
lazy val taggedMeta = project
.in(file("tagged-meta"))
.dependsOn(
macroUtils,
tagged,
macroUtils.jvm,
tagged.jvm,
sprayJsonSupport % "test -> test",
circeSupport % "test -> test",
jsonschemaSupport % "test -> test",
Expand Down Expand Up @@ -474,9 +479,12 @@ lazy val instances = project
lazy val kebs = project
.in(file("."))
.aggregate(
tagged,
opaque,
macroUtils,
tagged.jvm,
tagged.js,
opaque.jvm,
opaque.js,
macroUtils.jvm,
macroUtils.js,
slickSupport,
doobieSupport,
sprayJsonMacros,
Expand Down
34 changes: 21 additions & 13 deletions macro-utils/src/test/scala/EquivSupportSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,38 @@ object EquivSupportSpecification extends Properties("EquivSupport") {
import StringsDomain._
import pl.iterators.kebs.support._

private def isScalaJS = System.getProperty("java.vm.name") == "Scala.js"

private def areEquiv[A](e1: A, e2: A)(implicit E: Equiv[A]): Boolean =
E.equiv(e1, e2)

implicit private val equiv: Equiv[String] = Equiv.reference[String]

property("tagged string should be equivalent to reference of non tagged string") = forAll { (stringValue: String) =>
val string = new String(stringValue)
val stringTagged = TaggedString(string)
if (!isScalaJS) {
property("string should not be equivalent to other reference of same string") = forAll { (stringValue: String) =>
!areEquiv(stringValue, new String(stringValue))
}

areEquiv(stringTagged, TaggedString(string))
property("tagged string should not be equivalent to new instance of non tagged string") = forAll { (stringValue: String) =>
val string = new String(stringValue)
val stringTagged = TaggedString(string)

!areEquiv(stringTagged, TaggedString(new String(stringValue)))
}

property("boxed string should not be equivalent to new instance of non boxed string") = forAll { (stringValue: String) =>
val string = new String(stringValue)
val stringBoxed = BoxedString(string)

!areEquiv(stringBoxed, BoxedString(new String(stringValue)))
}
}

property("tagged string should not be equivalent to new instance of non tagged string") = forAll { (stringValue: String) =>
property("tagged string should be equivalent to reference of non tagged string") = forAll { (stringValue: String) =>
val string = new String(stringValue)
val stringTagged = TaggedString(string)

!areEquiv(stringTagged, TaggedString(new String(stringValue)))
areEquiv(stringTagged, TaggedString(string))
}

property("boxed string should be equivalent to reference of non boxed string") = forAll { (stringValue: String) =>
Expand All @@ -31,11 +46,4 @@ object EquivSupportSpecification extends Properties("EquivSupport") {

areEquiv(stringBoxed, BoxedString(string))
}

property("boxed string should not be equivalent to new instance of non boxed string") = forAll { (stringValue: String) =>
val string = new String(stringValue)
val stringBoxed = BoxedString(string)

!areEquiv(stringBoxed, BoxedString(new String(stringValue)))
}
}
5 changes: 4 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ logLevel := Level.Warn

addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.16")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.12.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")

0 comments on commit 7f3cade

Please sign in to comment.