(patch) Enable pre-commit.
Some checks failed
/ Build and Test Library Snapshot (pull_request) Failing after 43s
Some checks failed
/ Build and Test Library Snapshot (pull_request) Failing after 43s
This commit is contained in:
parent
117f9fa6e6
commit
87c9e6b94f
3 changed files with 20 additions and 19 deletions
|
@ -2,8 +2,7 @@ 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]+)*$`
|
||||||
*
|
*
|
||||||
|
@ -22,11 +21,12 @@ 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 The candidate string used to create the [[Slug]].
|
* @param candidate
|
||||||
* @return The [[Slug]], or `None` if the candidate is invalid.
|
* The candidate string used to create the [[Slug]].
|
||||||
|
* @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
|
||||||
|
@ -34,9 +34,9 @@ object Slug:
|
||||||
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 The string representation of this [[Slug]].
|
* @return
|
||||||
|
* The string representation of this [[Slug]].
|
||||||
*/
|
*/
|
||||||
def str(): String = slug
|
def str(): String = slug
|
||||||
|
|
|
@ -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()))
|
||||||
|
|
Loading…
Add table
Reference in a new issue