(patch) Full test coverage, adding builds. (#1)
All checks were successful
/ Build and Release Library (push) Successful in 1m20s

Reviewed-on: #1
This commit is contained in:
Pat Garrity 2024-04-27 02:13:01 +00:00
parent 831f773e3a
commit e43294c13d
7 changed files with 63 additions and 1 deletions

View file

@ -61,6 +61,7 @@ jobs:
if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then
echo "Skipping publish due to GS_RELEASE_TYPE=norelease"
else
sbtn coverageOff
sbtn clean
sbtn publish
fi

View file

@ -68,6 +68,7 @@ jobs:
if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then
echo "Skipping publish for 'norelease' commit."
else
sbtn coverageOff
sbtn clean
sbtn semVerWriteVersionToFile
sbtn publish

View file

View file

@ -30,6 +30,6 @@ lazy val `gs-blob` = project
.settings(name := s"${gsProjectName.value}-v${semVerMajor.value}")
.settings(
libraryDependencies ++= Seq(
"gs" %% "gs-hex-v0" % "0.1.1"
"gs" %% "gs-hex-v0" % "0.1.3"
)
)

View file

@ -23,6 +23,11 @@ def selectCredentials(): Credentials =
credentials += selectCredentials()
externalResolvers := Seq(
"Garrity Software Mirror" at "https://maven.garrity.co/releases",
"Garrity Software Releases" at "https://maven.garrity.co/gs"
)
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")
addSbtPlugin("gs" % "sbt-garrity-software" % "0.3.0")
addSbtPlugin("gs" % "sbt-gs-semver" % "0.3.0")

View file

@ -49,12 +49,27 @@ object Blob:
def fromBase64(data: String): Option[Blob] =
scala.util.Try(Base64.getDecoder().decode(data)).toOption
/** Convert the given hex string to a [[Blob]].
*
* @param data
* The candidate data.
* @return
* The parsed [[Blob]], or `None` if the input is not valid base64.
*/
def fromHex(data: String): Option[Blob] =
HexDecode[Blob].fromHexString(data)
extension (blob: Blob)
/** @return
* The underlying bytes of this [[Blob]].
*/
def toByteArray(): Array[Byte] = blob
/** @return
* Hexadecimal string representation of this [[Blob]].
*/
def toHex(): String = HexEncode[Blob].toHexString(blob)
/** @return
* The base64 representation of this [[Blob]].
*/
@ -65,4 +80,14 @@ object Blob:
*/
def length(): Int = blob.length
/** Compare this blob to another in O(N) time. Determines if the bytes are
* identical.
*
* @param other
* The blob to compare against.
* @return
* True if the blobs are identical, false otherwise.
*/
def sameBytesAs(other: Blob): Boolean = blob.sameElements(other)
end Blob

View file

@ -0,0 +1,30 @@
package gs.blob.v0
class BlobTests extends munit.FunSuite:
test("should manage arrays of bytes") {
val a1: Array[Byte] = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
val b1: Blob = Blob(a1)
val b2: Blob = Blob(a1)
val b3: Blob = Blob(Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
assert(b1.sameBytesAs(b2))
assert(!b1.sameBytesAs(b3))
assert(b1.length() == 10)
assert(b1.length() == b2.length())
assert(b1.toByteArray().sameElements(a1))
}
test("should support from/to base64") {
val blob: Blob = Blob(Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
val encoded = blob.toBase64()
val decoded = Blob.fromBase64(encoded)
assert(decoded.map(_.sameBytesAs(blob)) == Some(true))
}
test("should support from/to hex") {
val blob: Blob = Blob(Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
val encoded = blob.toHex()
val decoded = Blob.fromHex(encoded)
assert(decoded.map(_.sameBytesAs(blob)) == Some(true))
}