Skip to content

Commit

Permalink
Fix JS build
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilquist committed Jan 18, 2023
1 parent 1cd96ce commit d0ff2f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions modules/core/shared/src/main/scala/data/LTree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
}
}
10 changes: 5 additions & 5 deletions modules/tests/shared/src/test/scala/data/LTreeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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")
}
Expand Down

0 comments on commit d0ff2f4

Please sign in to comment.