(patch) Full test coverage, adding builds. #1
7 changed files with 63 additions and 1 deletions
|
@ -61,6 +61,7 @@ jobs:
|
||||||
if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then
|
if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then
|
||||||
echo "Skipping publish due to GS_RELEASE_TYPE=norelease"
|
echo "Skipping publish due to GS_RELEASE_TYPE=norelease"
|
||||||
else
|
else
|
||||||
|
sbtn coverageOff
|
||||||
sbtn clean
|
sbtn clean
|
||||||
sbtn publish
|
sbtn publish
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -68,6 +68,7 @@ jobs:
|
||||||
if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then
|
if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then
|
||||||
echo "Skipping publish for 'norelease' commit."
|
echo "Skipping publish for 'norelease' commit."
|
||||||
else
|
else
|
||||||
|
sbtn coverageOff
|
||||||
sbtn clean
|
sbtn clean
|
||||||
sbtn semVerWriteVersionToFile
|
sbtn semVerWriteVersionToFile
|
||||||
sbtn publish
|
sbtn publish
|
||||||
|
|
|
@ -30,6 +30,6 @@ lazy val `gs-blob` = project
|
||||||
.settings(name := s"${gsProjectName.value}-v${semVerMajor.value}")
|
.settings(name := s"${gsProjectName.value}-v${semVerMajor.value}")
|
||||||
.settings(
|
.settings(
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
"gs" %% "gs-hex-v0" % "0.1.1"
|
"gs" %% "gs-hex-v0" % "0.1.3"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,6 +23,11 @@ def selectCredentials(): Credentials =
|
||||||
|
|
||||||
credentials += selectCredentials()
|
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("org.scoverage" % "sbt-scoverage" % "2.0.11")
|
||||||
addSbtPlugin("gs" % "sbt-garrity-software" % "0.3.0")
|
addSbtPlugin("gs" % "sbt-garrity-software" % "0.3.0")
|
||||||
addSbtPlugin("gs" % "sbt-gs-semver" % "0.3.0")
|
addSbtPlugin("gs" % "sbt-gs-semver" % "0.3.0")
|
||||||
|
|
|
@ -49,12 +49,27 @@ object Blob:
|
||||||
def fromBase64(data: String): Option[Blob] =
|
def fromBase64(data: String): Option[Blob] =
|
||||||
scala.util.Try(Base64.getDecoder().decode(data)).toOption
|
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)
|
extension (blob: Blob)
|
||||||
/** @return
|
/** @return
|
||||||
* The underlying bytes of this [[Blob]].
|
* The underlying bytes of this [[Blob]].
|
||||||
*/
|
*/
|
||||||
def toByteArray(): Array[Byte] = blob
|
def toByteArray(): Array[Byte] = blob
|
||||||
|
|
||||||
|
/** @return
|
||||||
|
* Hexadecimal string representation of this [[Blob]].
|
||||||
|
*/
|
||||||
|
def toHex(): String = HexEncode[Blob].toHexString(blob)
|
||||||
|
|
||||||
/** @return
|
/** @return
|
||||||
* The base64 representation of this [[Blob]].
|
* The base64 representation of this [[Blob]].
|
||||||
*/
|
*/
|
||||||
|
@ -65,4 +80,14 @@ object Blob:
|
||||||
*/
|
*/
|
||||||
def length(): Int = blob.length
|
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
|
end Blob
|
||||||
|
|
30
src/test/scala/gs/blob/v0/BlobTests.scala
Normal file
30
src/test/scala/gs/blob/v0/BlobTests.scala
Normal 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))
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue