(patch) Enable pre-commit.
Some checks failed
/ Build and Test Library Snapshot (pull_request) Failing after 43s

This commit is contained in:
Pat Garrity 2024-03-23 22:54:29 -05:00
parent 117f9fa6e6
commit 87c9e6b94f
Signed by: pfm
GPG key ID: 5CA5D21BAB7F3A76
3 changed files with 20 additions and 19 deletions

View file

@ -2,16 +2,15 @@ package gs.slug.v0
import scala.util.matching.Regex import scala.util.matching.Regex
/** /** Restricted string intended to be used as a unique, URL-safe identifier
* Restricted string intended to be used as a unique, URL-safe identifier
* within some specific context (not a globally unique identifier). This type * within some specific context (not a globally unique identifier). This type
* adheres to the regular expression: `^[a-z0-9]+(?:\-[a-z0-9]+)*$` * adheres to the regular expression: `^[a-z0-9]+(?:\-[a-z0-9]+)*$`
* *
* Essentially, Slugs follow these rules: * Essentially, Slugs follow these rules:
* *
* - Segments are defined as lowercase alphanumeric ASCII strings. * - Segments are defined as lowercase alphanumeric ASCII strings.
* - Segments are separated by exactly one `-` character. * - Segments are separated by exactly one `-` character.
* - At least one segment is required. * - At least one segment is required.
* *
* If you need full unicode support, more characters, fewer constraints, etc. * If you need full unicode support, more characters, fewer constraints, etc.
* don't use this type. * don't use this type.
@ -22,21 +21,22 @@ object Slug:
val SlugPattern: Regex = "^[a-z0-9]+(?:\\-[a-z0-9]+)*$".r val SlugPattern: Regex = "^[a-z0-9]+(?:\\-[a-z0-9]+)*$".r
/** /** Instantiate a [[Slug]] by validating the candidate input.
* Instantiate a [[Slug]] by validating the candidate input. *
* * @param candidate
* @param candidate The candidate string used to create the [[Slug]]. * The candidate string used to create the [[Slug]].
* @return The [[Slug]], or `None` if the candidate is invalid. * @return
*/ * The [[Slug]], or `None` if the candidate is invalid.
*/
def validate(candidate: String): Option[Slug] = def validate(candidate: String): Option[Slug] =
if SlugPattern.matches(candidate) then Some(candidate) else None if SlugPattern.matches(candidate) then Some(candidate) else None
given CanEqual[Slug, Slug] = CanEqual.derived given CanEqual[Slug, Slug] = CanEqual.derived
extension (slug: Slug) extension (slug: Slug)
/** /** Render this [[Slug]] as a string.
* Render this [[Slug]] as a string. *
* * @return
* @return The string representation of this [[Slug]]. * The string representation of this [[Slug]].
*/ */
def str(): String = slug def str(): String = slug

View file

@ -1,6 +1,7 @@
package gs.slug.v0 package gs.slug.v0
class SlugTests extends munit.FunSuite: class SlugTests extends munit.FunSuite:
test("should instantiate valid slugs") { test("should instantiate valid slugs") {
('a' to 'z').foreach(c => assertValidSlug(c.toString())) ('a' to 'z').foreach(c => assertValidSlug(c.toString()))
('0' to '9').foreach(c => assertValidSlug(c.toString())) ('0' to '9').foreach(c => assertValidSlug(c.toString()))