From 87c9e6b94fb6b7479c52c4e9e72f1629bec4b3a3 Mon Sep 17 00:00:00 2001 From: Pat Garrity Date: Sat, 23 Mar 2024 22:54:29 -0500 Subject: [PATCH] (patch) Enable pre-commit. --- README.md | 4 +-- src/main/scala/gs/slug/v0/Slug.scala | 34 +++++++++++------------ src/test/scala/gs/slug/v0/SlugTests.scala | 1 + 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 89773f8..9dfa7b8 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ val GsSlug: ModuleID = ## Slug Type -`Slug` is the type exposed by this library. It is an extremely small, -restricted, opaque type (`String`) that adheres to the following regular +`Slug` is the type exposed by this library. It is an extremely small, +restricted, opaque type (`String`) that adheres to the following regular expression: ``` diff --git a/src/main/scala/gs/slug/v0/Slug.scala b/src/main/scala/gs/slug/v0/Slug.scala index 2e634a2..0d1d882 100644 --- a/src/main/scala/gs/slug/v0/Slug.scala +++ b/src/main/scala/gs/slug/v0/Slug.scala @@ -2,16 +2,15 @@ package gs.slug.v0 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 * adheres to the regular expression: `^[a-z0-9]+(?:\-[a-z0-9]+)*$` * * Essentially, Slugs follow these rules: * - * - Segments are defined as lowercase alphanumeric ASCII strings. - * - Segments are separated by exactly one `-` character. - * - At least one segment is required. + * - Segments are defined as lowercase alphanumeric ASCII strings. + * - Segments are separated by exactly one `-` character. + * - At least one segment is required. * * If you need full unicode support, more characters, fewer constraints, etc. * don't use this type. @@ -22,21 +21,22 @@ object Slug: val SlugPattern: Regex = "^[a-z0-9]+(?:\\-[a-z0-9]+)*$".r - /** - * Instantiate a [[Slug]] by validating the candidate input. - * - * @param candidate The candidate string used to create the [[Slug]]. - * @return The [[Slug]], or `None` if the candidate is invalid. - */ - def validate(candidate: String): Option[Slug] = + /** Instantiate a [[Slug]] by validating the candidate input. + * + * @param candidate + * The candidate string used to create the [[Slug]]. + * @return + * The [[Slug]], or `None` if the candidate is invalid. + */ + def validate(candidate: String): Option[Slug] = if SlugPattern.matches(candidate) then Some(candidate) else None given CanEqual[Slug, Slug] = CanEqual.derived extension (slug: Slug) - /** - * Render this [[Slug]] as a string. - * - * @return The string representation of this [[Slug]]. - */ + /** Render this [[Slug]] as a string. + * + * @return + * The string representation of this [[Slug]]. + */ def str(): String = slug diff --git a/src/test/scala/gs/slug/v0/SlugTests.scala b/src/test/scala/gs/slug/v0/SlugTests.scala index 5fbf7e5..e15a238 100644 --- a/src/test/scala/gs/slug/v0/SlugTests.scala +++ b/src/test/scala/gs/slug/v0/SlugTests.scala @@ -1,6 +1,7 @@ package gs.slug.v0 class SlugTests extends munit.FunSuite: + test("should instantiate valid slugs") { ('a' to 'z').foreach(c => assertValidSlug(c.toString())) ('0' to '9').foreach(c => assertValidSlug(c.toString()))