From d0ff2f4b5bc2bdb4cf48e3aa2fafe9ba42d343bf Mon Sep 17 00:00:00 2001 From: mpilquist Date: Tue, 17 Jan 2023 20:34:16 -0500 Subject: [PATCH] Fix JS build --- build.sbt | 1 + .../shared/src/main/scala/data/LTree.scala | 24 +++++++++---------- .../src/test/scala/data/LTreeTest.scala | 10 ++++---- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/build.sbt b/build.sbt index 4a7e6b1d..18f3d33a 100644 --- a/build.sbt +++ b/build.sbt @@ -199,6 +199,7 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform) } ) .jsSettings( + scalaJSLinkerConfig ~= { _.withESFeatures(_.withESVersion(org.scalajs.linker.interface.ESVersion.ES2018)) }, Test / scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)), ) .nativeEnablePlugins(ScalaNativeBrewedConfigPlugin) diff --git a/modules/core/shared/src/main/scala/data/LTree.scala b/modules/core/shared/src/main/scala/data/LTree.scala index 34d10183..f81df6a7 100644 --- a/modules/core/shared/src/main/scala/data/LTree.scala +++ b/modules/core/shared/src/main/scala/data/LTree.scala @@ -12,26 +12,26 @@ sealed abstract case class LTree (labels: List[String]) { other.labels.startsWith(labels) def isDescendantOf(other: LTree): Boolean = other.isAncestorOf(this) - + override def toString: String = labels.mkString(LTree.Separator.toString()) } object LTree { val Empty = new LTree(Nil) {} - + def fromLabels(s: String*): Either[String, LTree] = fromString(s.toList.mkString(Separator.toString())) - + def fromString(s: String): Either[String, LTree] = { - if(s.isEmpty()) { + if (s.isEmpty()) { Right(new LTree(Nil){}) } else { // We have a failure sentinal and a helper to set it. var failure: String = null def fail(msg: String): Unit = failure = s"ltree parse error: $msg" - + val labels = s.split(Separator).toList if(labels.length > MaxTreeLength) @@ -49,11 +49,11 @@ object LTree { } } - val MaxLabelLength = 255 - val MaxTreeLength = 65535 - - private val Separator = '.' - private val ValidLabelRegex = s"""^[\\p{L}0-9_]{1,$MaxLabelLength}$$""".r - + final val MaxLabelLength = 255 + final val MaxTreeLength = 65535 + + private final val Separator = '.' + private final val ValidLabelRegex = s"""^[\\p{L}0-9_]{1,$MaxLabelLength}$$""".r + implicit val ltreeEq: Eq[LTree] = Eq.fromUniversalEquals[LTree] -} \ No newline at end of file +} diff --git a/modules/tests/shared/src/test/scala/data/LTreeTest.scala b/modules/tests/shared/src/test/scala/data/LTreeTest.scala index 661f5ae5..96f299c8 100644 --- a/modules/tests/shared/src/test/scala/data/LTreeTest.scala +++ b/modules/tests/shared/src/test/scala/data/LTreeTest.scala @@ -7,11 +7,11 @@ package data import skunk.data.LTree -class LTreeTest extends munit.FunSuite { +class LTreeTest extends ffstest.FTest { + + lazy val foo = LTree.fromLabels("foo").toOption.get + lazy val foobar = LTree.fromLabels("foo", "bar").toOption.get - val foo = LTree.fromLabels("foo").toOption.get - val foobar = LTree.fromLabels("foo", "bar").toOption.get - test("LTree parsing") { assertEquals(LTree.fromString("").getOrElse(fail("Failed to parse empty LTree")), LTree.Empty) @@ -23,7 +23,7 @@ class LTreeTest extends munit.FunSuite { assert(LTree.fromString(List.fill(LTree.MaxTreeLength)("a").mkString(".")).isRight, "max tree len failed") assert(LTree.fromString(List.fill(LTree.MaxTreeLength + 1)("a").mkString(".")).isLeft, "max tree len failed") - + assert(LTree.fromString(List.fill(3)("a" * LTree.MaxLabelLength).mkString(".")).isRight, "max label len failed") assert(LTree.fromString(List.fill(3)("a" * LTree.MaxLabelLength + 1).mkString(".")).isLeft, "max label len failed") }