Skip to content

Commit 4e639c1

Browse files
authored
Merge branch 'main' into update/sbt-scala-native-crossproject-1.3.1
2 parents d26fe01 + fdc4a4c commit 4e639c1

7 files changed

Lines changed: 61 additions & 20 deletions

File tree

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = 3.7.1
1+
version = 3.7.3
22

33
runner.dialect = Scala213Source3
44

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ lazy val testing = crossProject(JSPlatform, JVMPlatform, NativePlatform)
8383
}
8484
)
8585
.platformsSettings(JSPlatform, NativePlatform)(
86-
libraryDependencies += "io.github.cquiroz" %%% "scala-java-locales" % "1.5.0"
86+
libraryDependencies += "io.github.cquiroz" %%% "scala-java-locales" % "1.5.1"
8787
)
8888
.nativeSettings(
8989
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "1.3.0").toMap

core/src/main/scala/org/typelevel/ci/CIString.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import scala.math.Ordered
4141
* val x: org.typelevel.ci.CIString = woof
4242
* scala> val y = CIString("WOOF")
4343
* val y: org.typelevel.ci.CIString = WOOF
44-
* scala> def f(ci: String): CIString = ci.toString
45-
* def f(s: String): org.typelevel.ci.CIString
44+
* scala> def f(ci: CIString): String = ci.toString
45+
* def f(ci: org.typelevel.ci.CIString): String
4646
* scala> x == y
4747
* val res0: Boolean = true
4848
* scala> f(x) == f(y)
@@ -98,6 +98,17 @@ final class CIString private (override val toString: String)
9898

9999
def length: Int = toString.length
100100

101+
def contains(needle: CIString): Boolean = {
102+
val needleLength = needle.toString.length
103+
val haystack = toString
104+
// There's no point searching haystack indexes beyond which the substring is too small to ever match the needle
105+
val maxHaystackStartingIndex = haystack.length - needleLength
106+
107+
(0 to maxHaystackStartingIndex).exists { i =>
108+
haystack.regionMatches(true, i, needle.toString, 0, needleLength)
109+
}
110+
}
111+
101112
@deprecated("Use toString", "0.1.0")
102113
def value: String = toString
103114
}

flake.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

project/plugins.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
val sbtTypelevelVersion = "0.4.19"
1+
val sbtTypelevelVersion = "0.4.20"
22
addSbtPlugin("org.typelevel" % "sbt-typelevel" % sbtTypelevelVersion)
33
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % sbtTypelevelVersion)
44
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.4")
5-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.11.0")
6-
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.9")
5+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.1")
6+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.12")
77
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.1")

tests/shared/src/test/scala/org/typelevel/ci/CIStringSuite.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,31 @@ class CIStringSuite extends DisciplineSuite {
183183
})
184184
}
185185

186+
test("contains lowercase to lowercase is true if matching") {
187+
assert(CIString("hello there").contains(CIString("hello there")))
188+
assert(CIString("hello there").contains(CIString("hello")))
189+
}
190+
191+
test("contains lowercase to lowercase is false if not matching") {
192+
assertEquals(CIString("hello there").contains(CIString("guten arben")), false)
193+
}
194+
195+
test("contains lowercase to mixed case is false if not matching") {
196+
assertEquals(CIString("hello there").contains(CIString("GUTEN ARBEN")), false)
197+
}
198+
199+
test("contains mixed to mixed case is true if matching") {
200+
assert(CIString("HELLO there").contains(CIString("hellO ThErE")))
201+
}
202+
203+
test("contains uppercase to mixed case is true if matching") {
204+
assert(CIString("HELLO THERE").contains(CIString("hellO ThErE")))
205+
}
206+
207+
test("contains uppercase to mixed case is false if not matching") {
208+
assertEquals(CIString("HELLO THERE").contains(CIString("GUTEN arben")), false)
209+
}
210+
186211
checkAll("Order[CIString]", OrderTests[CIString].order)
187212
checkAll("Hash[CIString]", HashTests[CIString].hash)
188213
checkAll("LowerBounded[CIString]", LowerBoundedTests[CIString].lowerBounded)

tests/shared/src/test/scala/org/typelevel/ci/TurkeySuite.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ package org.typelevel.ci
1919
import munit.FunSuite
2020

2121
class TurkeySuite extends FunSuite {
22-
test("passes the Turkey test") {
22+
test("equals passes the Turkey test") {
2323
assertEquals(CIString("i"), CIString("I"))
2424
}
25+
26+
test("contains passes the Turkey test") {
27+
assert(CIString("i").contains(CIString("I")))
28+
assert(CIString("I").contains(CIString("i")))
29+
}
2530
}

0 commit comments

Comments
 (0)