From db18338596f4dc48fc401ed3452629f8e4e4c07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABras=20=C5=A0lajus?= Date: Wed, 3 Jul 2024 11:32:39 +0300 Subject: [PATCH] Ran `scalafmtAll` in `sbt`. --- .../scala/urldsl/url/JSUrlStringParser.scala | 2 +- .../.js/src/main/scala/urldsl/url/URL.scala | 9 +- .../vocabulary/FromStringWithNumeric.scala | 15 +- .../main/scala/urldsl/errors/DummyError.scala | 3 +- .../urldsl/errors/ErrorFromThrowable.scala | 6 +- .../urldsl/errors/ParamMatchingError.scala | 10 +- .../urldsl/errors/PathMatchingError.scala | 8 +- .../errors/SimpleParamMatchingError.scala | 3 +- .../main/scala/urldsl/language/AllImpl.scala | 6 +- .../main/scala/urldsl/language/Fragment.scala | 91 +++++----- .../scala/urldsl/language/FragmentImpl.scala | 22 +-- .../language/PathQueryFragmentRepr.scala | 21 ++- .../scala/urldsl/language/PathSegment.scala | 157 ++++++++---------- .../urldsl/language/PathSegmentImpl.scala | 15 +- .../language/PathSegmentWithQueryParams.scala | 3 +- .../urldsl/language/QueryParameters.scala | 81 +++++---- .../main/scala/urldsl/language/UrlPart.scala | 14 +- .../scala/urldsl/url/UrlStringParser.scala | 2 +- .../main/scala/urldsl/vocabulary/Codec.scala | 6 +- .../scala/urldsl/vocabulary/FromString.scala | 28 ++-- .../urldsl/vocabulary/MaybeFragment.scala | 3 +- .../main/scala/urldsl/vocabulary/Param.scala | 2 +- .../urldsl/vocabulary/PathMatchOutput.scala | 9 +- .../PathQueryFragmentMatching.scala | 4 +- .../urldsl/vocabulary/CodecSpecFor3.scala | 1 - .../urldsl/vocabulary/FromString213Spec.scala | 18 +- .../urldsl/examples/CombinedExamples.scala | 19 +-- .../urldsl/examples/FragmentExamples.scala | 15 +- .../urldsl/examples/PathSegmentExamples.scala | 50 +++--- .../urldsl/examples/QueryParamsExamples.scala | 32 ++-- .../examples/RouterUseCaseExample.scala | 28 ++-- .../test/scala/urldsl/examples/package.scala | 25 ++- .../urldsl/language/FragmentProperties.scala | 48 ++++-- .../PathSegmentDummyErrorProperties.scala | 5 +- .../language/PathSegmentProperties.scala | 34 ++-- .../PathSegmentSimpleErrorProperties.scala | 9 +- .../PathSegmentWithQueryParamsChecks.scala | 2 +- ...gmentWithQueryParamsDummyErrorChecks.scala | 7 +- ...mentWithQueryParamsSimpleErrorChecks.scala | 5 +- .../language/QueryParameterProperties.scala | 6 +- .../urldsl/language/QueryParameterSpec.scala | 5 +- .../urldsl/language/QueryParamsUrlSpec.scala | 2 +- .../urldsl/vocabulary/FromStringChecks.scala | 3 +- .../urldsl/vocabulary/PrinterChecks.scala | 18 +- 44 files changed, 415 insertions(+), 437 deletions(-) diff --git a/url-dsl/.js/src/main/scala/urldsl/url/JSUrlStringParser.scala b/url-dsl/.js/src/main/scala/urldsl/url/JSUrlStringParser.scala index e51567d..c2d41b3 100644 --- a/url-dsl/.js/src/main/scala/urldsl/url/JSUrlStringParser.scala +++ b/url-dsl/.js/src/main/scala/urldsl/url/JSUrlStringParser.scala @@ -12,7 +12,7 @@ final class JSUrlStringParser(val rawUrl: String) extends UrlStringParser { def maybeFragment: Option[String] = Option(urlParser.hash) - /* + /* * Empty fragment are considered to have no fragment at all */ .filter(_.nonEmpty) diff --git a/url-dsl/.js/src/main/scala/urldsl/url/URL.scala b/url-dsl/.js/src/main/scala/urldsl/url/URL.scala index b239f05..2cc92e0 100644 --- a/url-dsl/.js/src/main/scala/urldsl/url/URL.scala +++ b/url-dsl/.js/src/main/scala/urldsl/url/URL.scala @@ -8,22 +8,19 @@ import scala.scalajs.js.annotation.JSGlobal @JSGlobal private[url] final class URL(url: String) extends js.Object { - /** - * Is a DOMString containing an initial '/' followed by the path of the URL. + /** Is a DOMString containing an initial '/' followed by the path of the URL. * * MDN */ var pathname: String = js.native - /** - * Is a DOMString containing a '?' followed by the parameters of the URL. + /** Is a DOMString containing a '?' followed by the parameters of the URL. * * MDN */ var search: String = js.native - /** - * Is a DOMString containing a '#' followed by the fragment identifier of the URL. + /** Is a DOMString containing a '#' followed by the fragment identifier of the URL. * * MDN */ diff --git a/url-dsl/src/main/scala-3/urldsl/vocabulary/FromStringWithNumeric.scala b/url-dsl/src/main/scala-3/urldsl/vocabulary/FromStringWithNumeric.scala index 54e564a..54dca5b 100644 --- a/url-dsl/src/main/scala-3/urldsl/vocabulary/FromStringWithNumeric.scala +++ b/url-dsl/src/main/scala-3/urldsl/vocabulary/FromStringWithNumeric.scala @@ -4,15 +4,14 @@ import urldsl.errors.ErrorFromThrowable trait FromStringWithNumeric { - implicit def numericFromString[T, A]( - implicit num: Numeric[T], + implicit def numericFromString[T, A](implicit + num: Numeric[T], fromThrowable: ErrorFromThrowable[A] - ): FromString[T, A] = FromString.factory( - s => - num.parseString(s) match { - case Some(t) => Right(t) - case None => Left(fromThrowable.fromThrowable(new Exception(s"$s is not numeric"))) - } + ): FromString[T, A] = FromString.factory(s => + num.parseString(s) match { + case Some(t) => Right(t) + case None => Left(fromThrowable.fromThrowable(new Exception(s"$s is not numeric"))) + } ) } diff --git a/url-dsl/src/main/scala/urldsl/errors/DummyError.scala b/url-dsl/src/main/scala/urldsl/errors/DummyError.scala index 57b658f..8b7762c 100644 --- a/url-dsl/src/main/scala/urldsl/errors/DummyError.scala +++ b/url-dsl/src/main/scala/urldsl/errors/DummyError.scala @@ -1,8 +1,7 @@ package urldsl.errors import urldsl.vocabulary.Segment -/** - * Error type with only one instance, for when you only care about knowing whether the error exists. +/** Error type with only one instance, for when you only care about knowing whether the error exists. */ sealed trait DummyError diff --git a/url-dsl/src/main/scala/urldsl/errors/ErrorFromThrowable.scala b/url-dsl/src/main/scala/urldsl/errors/ErrorFromThrowable.scala index 590cb51..a0b03e0 100644 --- a/url-dsl/src/main/scala/urldsl/errors/ErrorFromThrowable.scala +++ b/url-dsl/src/main/scala/urldsl/errors/ErrorFromThrowable.scala @@ -1,10 +1,10 @@ package urldsl.errors -/** - * You can implement this trait for your own error type A, and give a implicit instance in order to use the +/** You can implement this trait for your own error type A, and give a implicit instance in order to use the * functionality requiring it, e.g., in [[urldsl.vocabulary.FromString]]. * - * @tparam A tye type of your error. + * @tparam A + * tye type of your error. */ trait ErrorFromThrowable[A] { diff --git a/url-dsl/src/main/scala/urldsl/errors/ParamMatchingError.scala b/url-dsl/src/main/scala/urldsl/errors/ParamMatchingError.scala index 229bb5e..97ec8bf 100644 --- a/url-dsl/src/main/scala/urldsl/errors/ParamMatchingError.scala +++ b/url-dsl/src/main/scala/urldsl/errors/ParamMatchingError.scala @@ -1,13 +1,13 @@ package urldsl.errors -/** - * You can implement this trait for your own error type `A`, and provide an implicit instance in the companion object of - * `A` in order to use all pre-defined [[urldsl.language.QueryParameters]]. +/** You can implement this trait for your own error type `A`, and provide an implicit instance in the companion object + * of `A` in order to use all pre-defined [[urldsl.language.QueryParameters]]. * * @example - * See implementations of [[DummyError]] and [[SimpleParamMatchingError]] + * See implementations of [[DummyError]] and [[SimpleParamMatchingError]] * - * @tparam A the type of your error. + * @tparam A + * the type of your error. */ trait ParamMatchingError[A] { def missingParameterError(paramName: String): A diff --git a/url-dsl/src/main/scala/urldsl/errors/PathMatchingError.scala b/url-dsl/src/main/scala/urldsl/errors/PathMatchingError.scala index 83ccbe5..7a351c8 100644 --- a/url-dsl/src/main/scala/urldsl/errors/PathMatchingError.scala +++ b/url-dsl/src/main/scala/urldsl/errors/PathMatchingError.scala @@ -2,14 +2,14 @@ package urldsl.errors import urldsl.vocabulary.Segment -/** - * You can implement this trait for your own error type `A`, a giving an implicit instance in the companion object of +/** You can implement this trait for your own error type `A`, a giving an implicit instance in the companion object of * `A` so that it is available for all pre-defined [[urldsl.language.PathSegment]]. * * @example - * See implementations of [[DummyError]] or [[SimpleParamMatchingError]] + * See implementations of [[DummyError]] or [[SimpleParamMatchingError]] * - * @tparam A type of the error. + * @tparam A + * type of the error. */ trait PathMatchingError[+A] { diff --git a/url-dsl/src/main/scala/urldsl/errors/SimpleParamMatchingError.scala b/url-dsl/src/main/scala/urldsl/errors/SimpleParamMatchingError.scala index bdccb49..2840194 100644 --- a/url-dsl/src/main/scala/urldsl/errors/SimpleParamMatchingError.scala +++ b/url-dsl/src/main/scala/urldsl/errors/SimpleParamMatchingError.scala @@ -2,8 +2,7 @@ package urldsl.errors sealed trait SimpleParamMatchingError -/** - * An implementation of [[ParamMatchingError]] that simply wraps the trigger of the error inside its components. +/** An implementation of [[ParamMatchingError]] that simply wraps the trigger of the error inside its components. */ object SimpleParamMatchingError { diff --git a/url-dsl/src/main/scala/urldsl/language/AllImpl.scala b/url-dsl/src/main/scala/urldsl/language/AllImpl.scala index a649f2a..2cbf110 100644 --- a/url-dsl/src/main/scala/urldsl/language/AllImpl.scala +++ b/url-dsl/src/main/scala/urldsl/language/AllImpl.scala @@ -2,8 +2,7 @@ package urldsl.language import urldsl.errors.{FragmentMatchingError, ParamMatchingError, PathMatchingError} -final class AllImpl[P, Q, F] private ( - implicit +final class AllImpl[P, Q, F] private (implicit protected val pathError: PathMatchingError[P], protected val queryError: ParamMatchingError[Q], protected val fragmentError: FragmentMatchingError[F] @@ -12,8 +11,7 @@ final class AllImpl[P, Q, F] private ( with FragmentImpl[F] object AllImpl { - def apply[P, Q, F]( - implicit + def apply[P, Q, F](implicit pathError: PathMatchingError[P], queryError: ParamMatchingError[Q], fragmentError: FragmentMatchingError[F] diff --git a/url-dsl/src/main/scala/urldsl/language/Fragment.scala b/url-dsl/src/main/scala/urldsl/language/Fragment.scala index a7e2ae1..d5dcea5 100644 --- a/url-dsl/src/main/scala/urldsl/language/Fragment.scala +++ b/url-dsl/src/main/scala/urldsl/language/Fragment.scala @@ -7,29 +7,30 @@ import urldsl.vocabulary.{Codec, FromString, MaybeFragment, Printer} import scala.language.implicitConversions import scala.reflect.ClassTag -/** - * Represents the fragment (or ref) of an URL, containing an information of type T, or an error of type E. +/** Represents the fragment (or ref) of an URL, containing an information of type T, or an error of type E. * - * @tparam T type represented by this PathSegment - * @tparam E type of the error that this PathSegment produces on "illegal" url paths. + * @tparam T + * type represented by this PathSegment + * @tparam E + * type of the error that this PathSegment produces on "illegal" url paths. */ trait Fragment[T, +E] extends UrlPart[T, E] { import Fragment.factory - /** - * Extract the information contained in this fragment, as an instance of T. + /** Extract the information contained in this fragment, as an instance of T. * - * @param maybeFragment raw fragment information from the URL - * @return Right a T when the extraction was successful, and Left an error otherwise. + * @param maybeFragment + * raw fragment information from the URL + * @return + * Right a T when the extraction was successful, and Left an error otherwise. */ def matchFragment(maybeFragment: MaybeFragment): Either[E, T] def matchRawUrl(url: String, urlStringParserGenerator: UrlStringParserGenerator): Either[E, T] = matchFragment(urlStringParserGenerator.parser(url).maybeFragmentObj) - /** - * Creates a fragment information from an instance of T. + /** Creates a fragment information from an instance of T. */ def createFragment(t: T): MaybeFragment @@ -51,9 +52,8 @@ trait Fragment[T, +E] extends UrlPart[T, E] { def as[U](implicit codec: Codec[T, U]): Fragment[U, E] = as[U](codec.leftToRight _, codec.rightToLeft _) - /** - * Turns this fragment matching a `T` into a fragment matching an [[Option]] of T. - * It will return Some(t) if t could be extracted, and None otherwise. + /** Turns this fragment matching a `T` into a fragment matching an [[Option]] of T. It will return Some(t) if t could + * be extracted, and None otherwise. * * The failure that happened and led to an error does not matter: it will result in None, no matter what. */ @@ -61,21 +61,24 @@ trait Fragment[T, +E] extends UrlPart[T, E] { matchFragment(_) match { case Left(_) => Right(None) case Right(value) => Right(Some(value)) - }, { + }, + { case Some(t) => createFragment(t) case None => MaybeFragment(None) } ) - /** - * Adds an extra satisfying criteria to the de-serialized output of this [[Fragment]]. - * When the output of this [[Fragment]] does not satisfy the given predicate, the given error is returned - * instead. + /** Adds an extra satisfying criteria to the de-serialized output of this [[Fragment]]. When the output of this + * [[Fragment]] does not satisfy the given predicate, the given error is returned instead. * - * @param predicate criteria that the output has to verify - * @param error error happening when it's not the case - * @tparam E1 new type of the error - * @return a new [[Fragment]] matching the same fragment information, but only when the predicate is satisfied + * @param predicate + * criteria that the output has to verify + * @param error + * error happening when it's not the case + * @tparam E1 + * new type of the error + * @return + * a new [[Fragment]] matching the same fragment information, but only when the predicate is satisfied */ final def filter[E1 >: E](predicate: T => Boolean, error: MaybeFragment => E1): Fragment[T, E1] = Fragment.factory[T, E1]( @@ -91,19 +94,20 @@ trait Fragment[T, +E] extends UrlPart[T, E] { this.asInstanceOf[Fragment[T, DummyError]].filter(predicate, _ => DummyError.dummyError) } - /** - * Returns a [[Fragment]] which outputs the contents of this [[Fragment]] when result is a [[Some]] and the - * specified `default` value otherwise. - * When generating the path, it will only generate paths corresponding to the [[Some]] case. + /** Returns a [[Fragment]] which outputs the contents of this [[Fragment]] when result is a [[Some]] and the specified + * `default` value otherwise. When generating the path, it will only generate paths corresponding to the [[Some]] + * case. * - * @note This method is only available when `T =:= Option[U]`. + * @note + * This method is only available when `T =:= Option[U]`. * - * @param default default value when output is empty + * @param default + * default value when output is empty */ final def getOrElse[U](default: => U)(implicit ev: T =:= Option[U]): Fragment[U, E] = factory[U, E]( (maybeFragment: MaybeFragment) => matchFragment(maybeFragment).map(ev(_).getOrElse(default)), - //(u: U) => createFragment(ev.flip(Some(u))) + // (u: U) => createFragment(ev.flip(Some(u))) // we keep the ugliness below while supporting 2.12 todo[scala3] remove (u: U) => createFragment(Some(u).asInstanceOf[T]) ) @@ -118,14 +122,13 @@ object Fragment { def createFragment(t: T): MaybeFragment = generator(t) } - /** - * Creates a fragment matching any element of type `T`, as long as the [[urldsl.vocabulary.FromString]] can + /** Creates a fragment matching any element of type `T`, as long as the [[urldsl.vocabulary.FromString]] can * de-serialize it. * * If the fragment is missing, returns an error. */ - def fragment[T, A]( - implicit fromString: FromString[T, A], + def fragment[T, A](implicit + fromString: FromString[T, A], printer: Printer[T], fragmentMatchingError: FragmentMatchingError[A] ): Fragment[T, A] = factory[T, A]( @@ -136,14 +139,13 @@ object Fragment { (printer.apply _).andThen(Some(_)).andThen(MaybeFragment.apply) ) - /** - * Creates a fragment matching any element of type `T`, as long as the [[urldsl.vocabulary.FromString]] can + /** Creates a fragment matching any element of type `T`, as long as the [[urldsl.vocabulary.FromString]] can * de-serialize it. * * If the fragment is missing, returns None. */ - final def maybeFragment[T, A]( - implicit fromString: FromString[T, A], + final def maybeFragment[T, A](implicit + fromString: FromString[T, A], printer: Printer[T], fragmentMatchingError: FragmentMatchingError[A] ): Fragment[Option[T], A] = factory[Option[T], A]( @@ -163,8 +165,8 @@ object Fragment { (_: Unit) => MaybeFragment(None) ) - implicit def asFragment[T, A](t: T)( - implicit fromString: FromString[T, A], + implicit def asFragment[T, A](t: T)(implicit + fromString: FromString[T, A], printer: Printer[T], fragmentMatchingError: FragmentMatchingError[A], classTag: ClassTag[T] @@ -173,11 +175,12 @@ object Fragment { case MaybeFragment(None) => Left(fragmentMatchingError.missingFragmentError) case MaybeFragment(Some(fragment)) => fromString(fragment) match { - case Left(value) => Left(value) - case Right(decodedValue) => decodedValue match { - case value: T if value == t => Right(()) - case _ => Left(fragmentMatchingError.wrongValue(decodedValue, t)) - } + case Left(value) => Left(value) + case Right(decodedValue) => + decodedValue match { + case value: T if value == t => Right(()) + case _ => Left(fragmentMatchingError.wrongValue(decodedValue, t)) + } } }, _ => MaybeFragment(Some(printer.print(t))) diff --git a/url-dsl/src/main/scala/urldsl/language/FragmentImpl.scala b/url-dsl/src/main/scala/urldsl/language/FragmentImpl.scala index 2e22269..2906142 100644 --- a/url-dsl/src/main/scala/urldsl/language/FragmentImpl.scala +++ b/url-dsl/src/main/scala/urldsl/language/FragmentImpl.scala @@ -6,40 +6,36 @@ import urldsl.vocabulary.{FromString, Printer} import scala.reflect.ClassTag import scala.language.implicitConversions -/** - * This is the analogue of [[PathSegmentImpl]] for the [[Fragment]] trait. It "pre-applies" the error type based on the +/** This is the analogue of [[PathSegmentImpl]] for the [[Fragment]] trait. It "pre-applies" the error type based on the * provided [[FragmentMatchingError]]. * - * @tparam E type of the "pre-applied" errors + * @tparam E + * type of the "pre-applied" errors */ trait FragmentImpl[E] { /** implementation of [[FragmentMatchingError]] for generating relevant matching errors. */ implicit protected val fragmentError: FragmentMatchingError[E] - /** - * Returns a [[Fragment]] matching an element of type T. - * If the fragment is missing, it fails with a missing fragment error. + /** Returns a [[Fragment]] matching an element of type T. If the fragment is missing, it fails with a missing fragment + * error. */ final def fragment[T](implicit fromString: FromString[T, E], printer: Printer[T]): Fragment[T, E] = Fragment.fragment[T, E] - /** - * Returns a [[Fragment]] matching an element of type T. - * If the fragment is missing, it succeeds with None. + /** Returns a [[Fragment]] matching an element of type T. If the fragment is missing, it succeeds with None. */ final def maybeFragment[T](implicit fromString: FromString[T, E], printer: Printer[T]): Fragment[Option[T], E] = Fragment.maybeFragment[T, E] - /** - * Returns a [[Fragment]] imposing that the URL does not contain any fragment. + /** Returns a [[Fragment]] imposing that the URL does not contain any fragment. * * Note that a URL ending with "#" is considered having no fragment. */ final def emptyFragment: Fragment[Unit, E] = Fragment.empty - implicit final def asFragment[T](t: T)( - implicit fromString: FromString[T, E], + implicit final def asFragment[T](t: T)(implicit + fromString: FromString[T, E], printer: Printer[T], classTag: ClassTag[T] ): Fragment[Unit, E] = Fragment.asFragment(t) diff --git a/url-dsl/src/main/scala/urldsl/language/PathQueryFragmentRepr.scala b/url-dsl/src/main/scala/urldsl/language/PathQueryFragmentRepr.scala index eb51420..771aab0 100644 --- a/url-dsl/src/main/scala/urldsl/language/PathQueryFragmentRepr.scala +++ b/url-dsl/src/main/scala/urldsl/language/PathQueryFragmentRepr.scala @@ -11,7 +11,14 @@ import urldsl.vocabulary.{ Segment } -final class PathQueryFragmentRepr[PathType, +PathError, ParamsType, +ParamsError, FragmentType, +FragmentError] private[language] ( +final class PathQueryFragmentRepr[ + PathType, + +PathError, + ParamsType, + +ParamsError, + FragmentType, + +FragmentError +] private[language] ( pathSegment: PathSegment[PathType, PathError], queryParams: QueryParameters[ParamsType, ParamsError], fragment: Fragment[FragmentType, FragmentError] @@ -73,8 +80,8 @@ final class PathQueryFragmentRepr[PathType, +PathError, ParamsType, +ParamsError } /** If this instance actually only bear path information, retrieves that information only. */ - def pathOnly( - implicit ev1: Unit =:= ParamsType, + def pathOnly(implicit + ev1: Unit =:= ParamsType, ev2: Unit =:= FragmentType ): UrlPart[PathType, PathQueryFragmentError[PathError, ParamsError, FragmentError]] = UrlPart.factory( @@ -83,8 +90,8 @@ final class PathQueryFragmentRepr[PathType, +PathError, ParamsType, +ParamsError ) /** If this instance actually only bear query information, retrieves that information only. */ - def queryOnly( - implicit ev1: Unit =:= PathType, + def queryOnly(implicit + ev1: Unit =:= PathType, ev2: Unit =:= FragmentType ): UrlPart[ParamsType, PathQueryFragmentError[PathError, ParamsError, FragmentError]] = UrlPart.factory( @@ -93,8 +100,8 @@ final class PathQueryFragmentRepr[PathType, +PathError, ParamsType, +ParamsError ) /** If this instance actually only bear fragment information, retrieves that information only. */ - def fragmentOnly( - implicit ev1: Unit =:= ParamsType, + def fragmentOnly(implicit + ev1: Unit =:= ParamsType, ev2: Unit =:= PathType ): UrlPart[FragmentType, PathQueryFragmentError[PathError, ParamsError, FragmentError]] = UrlPart.factory( diff --git a/url-dsl/src/main/scala/urldsl/language/PathSegment.scala b/url-dsl/src/main/scala/urldsl/language/PathSegment.scala index 83bfb98..ffad3d1 100644 --- a/url-dsl/src/main/scala/urldsl/language/PathSegment.scala +++ b/url-dsl/src/main/scala/urldsl/language/PathSegment.scala @@ -8,44 +8,45 @@ import app.tulz.tuplez.Composition import scala.language.implicitConversions -/** - * Represents a part of the path string of an URL, containing an information of type T, or an error of type A. - * @tparam T type represented by this PathSegment - * @tparam A type of the error that this PathSegment produces on "illegal" url paths. +/** Represents a part of the path string of an URL, containing an information of type T, or an error of type A. + * @tparam T + * type represented by this PathSegment + * @tparam A + * type of the error that this PathSegment produces on "illegal" url paths. */ trait PathSegment[T, +A] extends UrlPart[T, A] { - /** - * Tries to match the list of [[urldsl.vocabulary.Segment]]s to create an instance of `T`. - * If it can not, it returns an error indicating the reason of the failure. - * If it could, it returns the value of `T`, as well as the list of unused segments. + /** Tries to match the list of [[urldsl.vocabulary.Segment]]s to create an instance of `T`. If it can not, it returns + * an error indicating the reason of the failure. If it could, it returns the value of `T`, as well as the list of + * unused segments. * * @example - * For example, a segment that matches simply a String in the first segment, when giving segments like - * List(Segment("hello"), Segment("3")) - * will return - * Right(PathMatchOutput("hello", List(Segment("3"))) + * For example, a segment that matches simply a String in the first segment, when giving segments like + * List(Segment("hello"), Segment("3")) will return Right(PathMatchOutput("hello", List(Segment("3"))) * - * @param segments The list of [[urldsl.vocabulary.Segment]] to match this path segment again. - * @return The "de-serialized" element with unused segment, if successful. + * @param segments + * The list of [[urldsl.vocabulary.Segment]] to match this path segment again. + * @return + * The "de-serialized" element with unused segment, if successful. */ def matchSegments(segments: List[Segment]): Either[A, PathMatchOutput[T]] - /** - * Matches the given raw `url` using the given [[urldsl.url.UrlStringParserGenerator]] for creating a + /** Matches the given raw `url` using the given [[urldsl.url.UrlStringParserGenerator]] for creating a * [[urldsl.url.UrlStringParser]]. * * This method doesn't return the information about the remaining unused segments. The thought leading to this is * that [[urldsl.vocabulary.PathMatchOutput]] are supposed to be internal mechanics, while this method is supposed to * be the exposed interface of this [[urldsl.language.PathSegment]]. * - * @param url the url to parse. It has to be a well formed URL, otherwise this could raise an - * exception, depending on the provided [[urldsl.url.UrlStringParserGenerator]]. - * @param urlStringParserGenerator the [[urldsl.url.UrlStringParserGenerator]] used to create the - * [[urldsl.url.UrlStringParser]] that will actually parse the url to create the - * segments. The default one is usually a good choice. It has different - * implementations in JVM and JS, but they *should* behave the same way. - * @return the output contained in the url, or the error if something fails. + * @param url + * the url to parse. It has to be a well formed URL, otherwise this could raise an exception, depending on the + * provided [[urldsl.url.UrlStringParserGenerator]]. + * @param urlStringParserGenerator + * the [[urldsl.url.UrlStringParserGenerator]] used to create the [[urldsl.url.UrlStringParser]] that will actually + * parse the url to create the segments. The default one is usually a good choice. It has different implementations + * in JVM and JS, but they *should* behave the same way. + * @return + * the output contained in the url, or the error if something fails. */ def matchRawUrl( url: String, @@ -56,27 +57,23 @@ trait PathSegment[T, +A] extends UrlPart[T, A] { def matchPath(path: String, decoder: UrlStringDecoder = UrlStringDecoder.defaultDecoder): Either[A, T] = matchSegments(decoder.decodePath(path)).map(_.output) - /** - * Generate a list of segments representing the argument `t`. + /** Generate a list of segments representing the argument `t`. * * `matchSegments` and `createSegments` should be (functional) inverse of each other. That is, * `this.matchSegments(this.createSegments(t)) == Right(PathMathOutput(t, Nil))` */ def createSegments(t: T): List[Segment] - /** - * Sugar when `T =:= Unit` + /** Sugar when `T =:= Unit` */ final def createSegments()(implicit ev: Unit =:= T): List[Segment] = createSegments(ev(())) - /** - * Concatenates the segments generated by `createSegments` + /** Concatenates the segments generated by `createSegments` */ def createPath(t: T, encoder: UrlStringGenerator = UrlStringGenerator.default): String = encoder.makePath(createSegments(t)) - /** - * Sugar when `T =:= Unit` + /** Sugar when `T =:= Unit` */ final def createPath()(implicit ev: Unit =:= T): String = createPath(()) @@ -85,8 +82,7 @@ trait PathSegment[T, +A] extends UrlPart[T, A] { final def createPart(t: T, encoder: UrlStringGenerator): String = createPath(t, encoder) - /** - * Concatenates `this` [[urldsl.language.PathSegment]] with `that` one, "tupling" the types with the [[Composition]] + /** Concatenates `this` [[urldsl.language.PathSegment]] with `that` one, "tupling" the types with the [[Composition]] * rules. */ final def /[U, A1 >: A](that: PathSegment[U, A1])(implicit c: Composition[T, U]): PathSegment[c.Composed, A1] = @@ -110,18 +106,17 @@ trait PathSegment[T, +A] extends UrlPart[T, A] { ): PathSegmentWithQueryParams[T, A, ParamsType, QPError] = new PathSegmentWithQueryParams(this, params) - /** - * Adds an extra satisfying criteria to the de-serialized output of this [[urldsl.language.PathSegment]]. + /** Adds an extra satisfying criteria to the de-serialized output of this [[urldsl.language.PathSegment]]. * * The new de-serialization works as follows: - * - if the initial de-serialization fails, then it returns the generated error - * - otherwise, if the de-serialized element satisfies the predicate, then it returns the element - * - if the predicate is false, generates the given `error` by feeding it the segments that it tried to match. + * - if the initial de-serialization fails, then it returns the generated error + * - otherwise, if the de-serialized element satisfies the predicate, then it returns the element + * - if the predicate is false, generates the given `error` by feeding it the segments that it tried to match. * * This can be useful in, among others, two scenarios: - * - enforce bigger restriction on a segment (e.g., from integers to positive integer, regex match...) - * - in a multi-part segment, ensure consistency between the different component (e.g., a range of two integers that - * should not be too large...) + * - enforce bigger restriction on a segment (e.g., from integers to positive integer, regex match...) + * - in a multi-part segment, ensure consistency between the different component (e.g., a range of two integers + * that should not be too large...) */ final def filter[A1 >: A](predicate: T => Boolean, error: List[Segment] => A1): PathSegment[T, A1] = PathSegment.factory[T, A1]( @@ -139,9 +134,8 @@ trait PathSegment[T, +A] extends UrlPart[T, A] { this.asInstanceOf[PathSegment[T, DummyError]].filter(predicate, _ => DummyError.dummyError) } - /** - * Builds a [[PathSegment]] that first tries to match with this one, then tries to match with `that` one. - * If both fail, the error of the second is returned (todo[behaviour]: should that change?) + /** Builds a [[PathSegment]] that first tries to match with this one, then tries to match with `that` one. If both + * fail, the error of the second is returned (todo[behaviour]: should that change?) */ final def ||[U, A1 >: A](that: PathSegment[U, A1]): PathSegment[Either[T, U], A1] = PathSegment.factory[Either[T, U], A1]( @@ -154,14 +148,12 @@ trait PathSegment[T, +A] extends UrlPart[T, A] { _.fold(this.createSegments, that.createSegments) ) - /** - * Casts this [[PathSegment]] to the new type U. Note that the [[urldsl.vocabulary.Codec]] must be an exception-free + /** Casts this [[PathSegment]] to the new type U. Note that the [[urldsl.vocabulary.Codec]] must be an exception-free * bijection between T and U (or at least an embedding, if you know that you are doing). */ final def as[U](implicit codec: Codec[T, U]): PathSegment[U, A] = as[U](codec.leftToRight _, codec.rightToLeft _) - /** - * Casts this [[PathSegment]] to the new type U. The conversion functions should form an exception-free bijection + /** Casts this [[PathSegment]] to the new type U. The conversion functions should form an exception-free bijection * between T and U (or at least an embedding, if you know that you are doing). */ final def as[U](fromTToU: T => U, fromUToT: U => T): PathSegment[U, A] = PathSegment.factory[U, A]( @@ -169,18 +161,16 @@ trait PathSegment[T, +A] extends UrlPart[T, A] { fromUToT.andThen(createSegments) ) - /** - * Matches using this [[PathSegment]], and then forgets its content. - * Uses the `default` value when creating the path to go back. + /** Matches using this [[PathSegment]], and then forgets its content. Uses the `default` value when creating the path + * to go back. */ final def ignore(default: => T): PathSegment[Unit, A] = PathSegment.factory[Unit, A]( matchSegments(_).map(_.map(_ => ())), (_: Unit) => createSegments(default) ) - /** - * Forgets the information contained in the path parameter by injecting one. - * This turn this "dynamic" [[PathSegment]] into a fix one. + /** Forgets the information contained in the path parameter by injecting one. This turn this "dynamic" [[PathSegment]] + * into a fix one. */ final def provide[A1 >: A]( t: T @@ -190,15 +180,15 @@ trait PathSegment[T, +A] extends UrlPart[T, A] { for { tMatch <- matchSegments(segments) PathMatchOutput(tOutput, unusedSegments) = tMatch - unitMatched <- if (tOutput != t) Left(pathMatchingError.wrongValue(printer(t), printer(tOutput))) - else Right(PathMatchOutput((), unusedSegments)) + unitMatched <- + if (tOutput != t) Left(pathMatchingError.wrongValue(printer(t), printer(tOutput))) + else Right(PathMatchOutput((), unusedSegments)) } yield unitMatched, (_: Unit) => createSegments(t) ) - /** - * Associates this [[PathSegment]] with the given [[Fragment]] in order to match raw urls satisfying both - * conditions, and returning the outputs from both. + /** Associates this [[PathSegment]] with the given [[Fragment]] in order to match raw urls satisfying both conditions, + * and returning the outputs from both. * * The query part of the url will be *ignored* (and will return Unit). */ @@ -213,8 +203,7 @@ object PathSegment { type PathSegmentSimpleError[T] = PathSegment[T, SimplePathMatchingError] - /** - * A Type of path segment where we don't care about the error. + /** A Type of path segment where we don't care about the error. */ type PathSegmentNoError[T] = PathSegment[T, DummyError] @@ -237,13 +226,12 @@ object PathSegment { final def noMatch[A](implicit pathMatchingError: PathMatchingError[A]): PathSegment[Unit, A] = factory[Unit, A](_ => Left(pathMatchingError.unit), _ => Nil) - /** - * Simple trait factory for "single segment"-oriented path Segments. + /** Simple trait factory for "single segment"-oriented path Segments. * * This can be used to match a simple String, or a simple Int, etc... */ - final def simplePathSegment[T, A](matching: Segment => Either[A, T], creating: T => Segment)( - implicit pathMatchingError: PathMatchingError[A] + final def simplePathSegment[T, A](matching: Segment => Either[A, T], creating: T => Segment)(implicit + pathMatchingError: PathMatchingError[A] ): PathSegment[T, A] = factory( (_: Seq[Segment]) match { @@ -258,23 +246,21 @@ object PathSegment { segment[String, A] /** Matches a simple Int and tries to convert it to an Int. */ - final def intSegment[A]( - implicit pathMatchingError: PathMatchingError[A], + final def intSegment[A](implicit + pathMatchingError: PathMatchingError[A], fromThrowable: ErrorFromThrowable[A] ): PathSegment[Int, A] = segment[Int, A] - /** - * Creates a segment matching any element of type `T`, as long as the [[urldsl.vocabulary.FromString]] can + /** Creates a segment matching any element of type `T`, as long as the [[urldsl.vocabulary.FromString]] can * de-serialize it. */ - final def segment[T, A]( - implicit fromString: FromString[T, A], + final def segment[T, A](implicit + fromString: FromString[T, A], printer: Printer[T], error: PathMatchingError[A] ): PathSegment[T, A] = simplePathSegment[T, A]((fromString.apply _).compose(_.content), printer.print) - /** - * Check that the segments ends at this point. + /** Check that the segments ends at this point. */ final def endOfSegments[A](implicit pathMatchingError: PathMatchingError[A]): PathSegment[Unit, A] = factory[Unit, A]( (_: List[Segment]) match { @@ -284,8 +270,7 @@ object PathSegment { _ => Nil ) - /** - * Consumes all the remaining segments. + /** Consumes all the remaining segments. * * This can be useful for static resources. */ @@ -294,14 +279,13 @@ object PathSegment { _.map(Segment.apply) ) - /** - * [[PathSegment]] that matches one of the given different possibilities. + /** [[PathSegment]] that matches one of the given different possibilities. * - * This can be useful in a Router, when you want to delegate the final decision to an inner router. - * Since all possibilities are good, the creation of segment simply takes the first one. + * This can be useful in a Router, when you want to delegate the final decision to an inner router. Since all + * possibilities are good, the creation of segment simply takes the first one. */ - final def oneOf[T, A](t: T, ts: T*)( - implicit fromString: FromString[T, A], + final def oneOf[T, A](t: T, ts: T*)(implicit + fromString: FromString[T, A], printer: Printer[T], pathMatchingError: PathMatchingError[A] ): PathSegment[Unit, A] = { @@ -318,18 +302,15 @@ object PathSegment { ) } - /** - * Returns a [[urldsl.language.PathSegment]] which matches exactly the argument `t`. + /** Returns a [[urldsl.language.PathSegment]] which matches exactly the argument `t`. * * This conversion is implicit if you can provide a [[urldsl.vocabulary.FromString]] and a - * [[urldsl.vocabulary.Printer]], so that it enables writing, - * e.g., - * `root / "hello" / true` + * [[urldsl.vocabulary.Printer]], so that it enables writing, e.g., `root / "hello" / true` */ implicit final def unaryPathSegment[T, A]( t: T - )( - implicit fromString: FromString[T, A], + )(implicit + fromString: FromString[T, A], printer: Printer[T], pathMatchingError: PathMatchingError[A] ): PathSegment[Unit, A] = diff --git a/url-dsl/src/main/scala/urldsl/language/PathSegmentImpl.scala b/url-dsl/src/main/scala/urldsl/language/PathSegmentImpl.scala index 04dc2b3..8a0054d 100644 --- a/url-dsl/src/main/scala/urldsl/language/PathSegmentImpl.scala +++ b/url-dsl/src/main/scala/urldsl/language/PathSegmentImpl.scala @@ -5,12 +5,10 @@ import urldsl.vocabulary.{FromString, Printer, Segment} import scala.language.implicitConversions -/** - * Using the pre-defined path segments in [[PathSegment]] can be cumbersome if you have to constantly specify the error +/** Using the pre-defined path segments in [[PathSegment]] can be cumbersome if you have to constantly specify the error * type A, for example in the [[PathSegment.segment]] or [[PathSegment.root]] methods. Therefore, you can invoke an - * implementation of this class and import its members instead. - * We don't redefine [[PathSegment.intSegment]] and [[PathSegment.stringSegment]] since they can be easily and - * conveniently invoked using the `segment` method below. + * implementation of this class and import its members instead. We don't redefine [[PathSegment.intSegment]] and + * [[PathSegment.stringSegment]] since they can be easily and conveniently invoked using the `segment` method below. * * @example * {{{ @@ -22,7 +20,8 @@ import scala.language.implicitConversions * [[PathSegment]] companion object) * }}} * - * @tparam A type of error. + * @tparam A + * type of error. */ trait PathSegmentImpl[A] { @@ -43,8 +42,8 @@ trait PathSegmentImpl[A] { /* I think this should not be necessary but the compiler has difficulties finding the correct error due to covariance */ implicit def unaryPathSegment[T]( t: T - )( - implicit fromString: FromString[T, A], + )(implicit + fromString: FromString[T, A], printer: Printer[T] ): PathSegment[Unit, A] = PathSegment.simplePathSegment( diff --git a/url-dsl/src/main/scala/urldsl/language/PathSegmentWithQueryParams.scala b/url-dsl/src/main/scala/urldsl/language/PathSegmentWithQueryParams.scala index a3d3e7c..771aecd 100644 --- a/url-dsl/src/main/scala/urldsl/language/PathSegmentWithQueryParams.scala +++ b/url-dsl/src/main/scala/urldsl/language/PathSegmentWithQueryParams.scala @@ -74,8 +74,7 @@ final class PathSegmentWithQueryParams[PathType, +PathError, ParamsType, +Params pathSegment.createPath(path, generator) ++ "?" ++ queryParams.createParamsString(params, generator) def &[OtherParamsType, ParamsError1 >: ParamsError](otherParams: QueryParameters[OtherParamsType, ParamsError1])( - implicit - c: Composition[ParamsType, OtherParamsType] + implicit c: Composition[ParamsType, OtherParamsType] ): PathSegmentWithQueryParams[PathType, PathError, c.Composed, ParamsError1] = new PathSegmentWithQueryParams[PathType, PathError, c.Composed, ParamsError1]( pathSegment, diff --git a/url-dsl/src/main/scala/urldsl/language/QueryParameters.scala b/url-dsl/src/main/scala/urldsl/language/QueryParameters.scala index 387b6d1..ff6d367 100644 --- a/url-dsl/src/main/scala/urldsl/language/QueryParameters.scala +++ b/url-dsl/src/main/scala/urldsl/language/QueryParameters.scala @@ -9,19 +9,19 @@ trait QueryParameters[Q, +A] extends UrlPart[Q, A] { import QueryParameters._ - /** - * Tries to match the map of [[urldsl.vocabulary.Param]]s to create an instance of `Q`. - * If it can not, it returns an error indicating the reason of the failure. - * If it could, it returns the value of `Q`, as well as the list of unused parameters. + /** Tries to match the map of [[urldsl.vocabulary.Param]]s to create an instance of `Q`. If it can not, it returns an + * error indicating the reason of the failure. If it could, it returns the value of `Q`, as well as the list of + * unused parameters. * * @example - * For example, if you try to match a param "name" as String and "age" as Int, calling matchParams on - * Map("name" -> Param(List("Alice")), "age" -> Param(List("24"), "year" -> Param(List("2020"))) - * will return - * Right(ParamMatchOutput(("Alice", 24), Map("year" -> Param(List("2020"))) + * For example, if you try to match a param "name" as String and "age" as Int, calling matchParams on Map("name" -> + * Param(List("Alice")), "age" -> Param(List("24"), "year" -> Param(List("2020"))) will return + * Right(ParamMatchOutput(("Alice", 24), Map("year" -> Param(List("2020"))) * - * @param params The map of [[urldsl.vocabulary.Param]] to match this path segment again. - * @return The "de-serialized" element with unused parameters, if successful. + * @param params + * The map of [[urldsl.vocabulary.Param]] to match this path segment again. + * @return + * The "de-serialized" element with unused parameters, if successful. */ def matchParams(params: Map[String, Param]): Either[A, ParamMatchOutput[Q]] @@ -34,8 +34,7 @@ trait QueryParameters[Q, +A] extends UrlPart[Q, A] { def matchQueryString(queryString: String, decoder: UrlStringDecoder = UrlStringDecoder.defaultDecoder): Either[A, Q] = matchParams(decoder.decodeParams(queryString)).map(_.output) - /** - * Generate a map of parameters representing the argument `q`. + /** Generate a map of parameters representing the argument `q`. * * `matchParams` and `createParams` should be (functional) inverse of each other. That is, * `this.matchParams(this.createParams(q)) == Right(ParamMathOutput(q, Map()))` (this property is called @@ -43,15 +42,13 @@ trait QueryParameters[Q, +A] extends UrlPart[Q, A] { */ def createParams(q: Q): Map[String, Param] - /** - * Generates a Map of parameters representing the argument `q`. The keys are not encoded, but the values are lists of + /** Generates a Map of parameters representing the argument `q`. The keys are not encoded, but the values are lists of * encoded strings. */ final def createParamsMap(q: Q, encoder: UrlStringGenerator = UrlStringGenerator.default): Map[String, List[String]] = encoder.makeParamsMap(createParams(q)) - /** - * Generates the query string representing the argument `q`. This String can be used to be part of a URL. + /** Generates the query string representing the argument `q`. This String can be used to be part of a URL. */ final def createParamsString(q: Q, encoder: UrlStringGenerator = UrlStringGenerator.default): String = encoder.makeParams(createParams(q)) @@ -59,15 +56,16 @@ trait QueryParameters[Q, +A] extends UrlPart[Q, A] { final def createPart(q: Q, encoder: UrlStringGenerator = UrlStringGenerator.default): String = createParamsString(q, encoder) - /** - * Adds `that` QueryParameters to `this` one, "tupling" the returned type with the implicit [[Composition]] + /** Adds `that` QueryParameters to `this` one, "tupling" the returned type with the implicit [[Composition]] * * The matching and writing of strings is functionally commutative under `&`, but the returned type `Q` is not. So, * if you have two parameters, one matching an Int and the other one a String, depending on the order in which `&` is * called, you can end up with "Q = (Int, String)" or "Q = (String, Int)". This property is called * "QuasiCommutativity" in the tests. */ - final def &[R, A1 >: A](that: QueryParameters[R, A1])(implicit c: Composition[Q, R]): QueryParameters[c.Composed, A1] = + final def &[R, A1 >: A](that: QueryParameters[R, A1])(implicit + c: Composition[Q, R] + ): QueryParameters[c.Composed, A1] = factory[c.Composed, A1]( (params: Map[String, Param]) => for { @@ -82,8 +80,7 @@ trait QueryParameters[Q, +A] extends UrlPart[Q, A] { } ) - /** - * When these query parameters return an error, transform it to None instead. + /** When these query parameters return an error, transform it to None instead. * * This should be used to represent (possibly) missing parameters. */ @@ -96,21 +93,21 @@ trait QueryParameters[Q, +A] extends UrlPart[Q, A] { _.map(createParams).getOrElse(Map()) ) - /** - * Adds an extra satisfying criteria to the output of this [[QueryParameters]]. - * If the output satisfies the given `predicate`, then it is left unchanged. Otherwise, it returns the given - * `error`. + /** Adds an extra satisfying criteria to the output of this [[QueryParameters]]. If the output satisfies the given + * `predicate`, then it is left unchanged. Otherwise, it returns the given `error`. * - * Note that it doesn't check that arguments given to `createParams` satisfy this predicate - * // todo[behaviour]: should that change? + * Note that it doesn't check that arguments given to `createParams` satisfy this predicate // todo[behaviour]: + * should that change? * - * @example {{{ - * param[Int]("age").filter(_ >= 0, (params: Map[String, Param]) => someError(params)) - * }}} + * @example + * {{{ param[Int]("age").filter(_ >= 0, (params: Map[String, Param]) => someError(params)) }}} * - * @param predicate the additional predicate that the output must satisfy - * @param error the generated error in case it does not satisfy it - * @return a new [[QueryParameters]] instance with the same types + * @param predicate + * the additional predicate that the output must satisfy + * @param error + * the generated error in case it does not satisfy it + * @return + * a new [[QueryParameters]] instance with the same types */ final def filter[A1 >: A](predicate: Q => Boolean, error: Map[String, Param] => A1): QueryParameters[Q, A1] = factory( (params: Map[String, Param]) => @@ -126,8 +123,7 @@ trait QueryParameters[Q, +A] extends UrlPart[Q, A] { this.asInstanceOf[QueryParameters[Q, DummyError]].filter(predicate, _ => DummyError.dummyError) } - /** - * Casts this [[QueryParameters]] to the new type R. Note that the [[urldsl.vocabulary.Codec]] must be an + /** Casts this [[QueryParameters]] to the new type R. Note that the [[urldsl.vocabulary.Codec]] must be an * exception-free bijection between Q and R. */ final def as[R](implicit codec: Codec[Q, R]): QueryParameters[R, A] = factory( @@ -135,8 +131,7 @@ trait QueryParameters[Q, +A] extends UrlPart[Q, A] { (codec.rightToLeft _).andThen(createParams) ) - /** - * Associates this [[QueryParameters]] with the given [[Fragment]] in order to match raw urls satisfying both + /** Associates this [[QueryParameters]] with the given [[Fragment]] in order to match raw urls satisfying both * conditions, and returning the outputs from both. * * The path part of the url will be *ignored* (and will return Unit). @@ -179,7 +174,7 @@ object QueryParameters { .map(_.map(ParamMatchOutput(_, params - paramName))) // consumes that param .getOrElse(onParameterNotFound(params)), creating.andThen(paramName -> _).andThen(Map(_)) -) + ) final def simpleQueryParam[Q, A]( paramName: String, @@ -191,12 +186,12 @@ object QueryParameters { matching, creating, onParameterNotFound = _ => Left(paramMatchingError.missingParameterError(paramName)) - ) + ) final def param[Q, A]( paramName: String - )( - implicit fromString: FromString[Q, A], + )(implicit + fromString: FromString[Q, A], printer: Printer[Q], paramMatchingError: ParamMatchingError[A] ): QueryParameters[Q, A] = @@ -211,8 +206,8 @@ object QueryParameters { final def listParam[Q, A]( paramName: String - )( - implicit fromString: FromString[Q, A], + )(implicit + fromString: FromString[Q, A], printer: Printer[Q], paramMatchingError: ParamMatchingError[A] ): QueryParameters[List[Q], A] = diff --git a/url-dsl/src/main/scala/urldsl/language/UrlPart.scala b/url-dsl/src/main/scala/urldsl/language/UrlPart.scala index 443fe52..e2419e2 100644 --- a/url-dsl/src/main/scala/urldsl/language/UrlPart.scala +++ b/url-dsl/src/main/scala/urldsl/language/UrlPart.scala @@ -2,10 +2,9 @@ package urldsl.language import urldsl.url.{UrlStringGenerator, UrlStringParserGenerator} -/** - * A [[UrlPart]] represents a part of (or the entire) URL and is able to extract some information out of it. - * When it succeeds to extract information, it returns an element of type T (wrapped in a [[Right]]). When it fails - * to extract such information, it returns an error type E (wrapped in a [[Left]]. +/** A [[UrlPart]] represents a part of (or the entire) URL and is able to extract some information out of it. When it + * succeeds to extract information, it returns an element of type T (wrapped in a [[Right]]). When it fails to extract + * such information, it returns an error type E (wrapped in a [[Left]]. * * A [[UrlPart]] is also able to generate its corresponding part of the URL by ingesting an element of type T. When * doing that, it outputs a String (whose semantic may vary depending on the type of [[UrlPart]] you are dealing with). @@ -41,10 +40,9 @@ object UrlPart { def createPart(t: T, encoder: UrlStringGenerator): String = generator(t, encoder) } - /** - * Type alias when you don't care about what kind of error is issued. - * [[Any]] can seem weird, but it has to be understood as "since it can fail with anything, I won't be able to do - * anything with the error, which means that I can only check whether it failed or not". + /** Type alias when you don't care about what kind of error is issued. [[Any]] can seem weird, but it has to be + * understood as "since it can fail with anything, I won't be able to do anything with the error, which means that I + * can only check whether it failed or not". */ type SimpleUrlPart[T] = UrlPart[T, Any] diff --git a/url-dsl/src/main/scala/urldsl/url/UrlStringParser.scala b/url-dsl/src/main/scala/urldsl/url/UrlStringParser.scala index a63b7a3..b8abd83 100644 --- a/url-dsl/src/main/scala/urldsl/url/UrlStringParser.scala +++ b/url-dsl/src/main/scala/urldsl/url/UrlStringParser.scala @@ -15,7 +15,7 @@ trait UrlStringParser extends UrlStringDecoder { /** Returns the raw content of the fragment (sometimes called ref), or None if there is no fragment */ def maybeFragment: Option[String] - /** Alias for [[maybeFragment]]. */ + /** Alias for [[maybeFragment]]. */ final def maybeRef: Option[String] = maybeFragment final def segments: List[Segment] = decodePath(path) diff --git a/url-dsl/src/main/scala/urldsl/vocabulary/Codec.scala b/url-dsl/src/main/scala/urldsl/vocabulary/Codec.scala index 21c1429..0f09e11 100644 --- a/url-dsl/src/main/scala/urldsl/vocabulary/Codec.scala +++ b/url-dsl/src/main/scala/urldsl/vocabulary/Codec.scala @@ -1,7 +1,6 @@ package urldsl.vocabulary -/** - * Represents a bijection between `Left` and `Right`. +/** Represents a bijection between `Left` and `Right`. * * This bijection is supposed to be "exception-free", and be an actual bijection. */ @@ -26,8 +25,7 @@ object Codec { def rightToLeft(right: U): T = uToT(right) } - implicit def composeCodecs[Left, Middle, Right]( - implicit + implicit def composeCodecs[Left, Middle, Right](implicit leftCodec: Codec[Left, Middle], rightCodec: Codec[Middle, Right] ): Codec[Left, Right] = leftCodec ++ rightCodec diff --git a/url-dsl/src/main/scala/urldsl/vocabulary/FromString.scala b/url-dsl/src/main/scala/urldsl/vocabulary/FromString.scala index c18925f..c76462d 100644 --- a/url-dsl/src/main/scala/urldsl/vocabulary/FromString.scala +++ b/url-dsl/src/main/scala/urldsl/vocabulary/FromString.scala @@ -19,26 +19,24 @@ object FromString extends FromStringWithNumeric { def factory[T, A](read: String => Either[A, T]): FromString[T, A] = (str: String) => read(str) implicit def stringFromString[A]: FromString[String, A] = factory(Right(_)) - implicit def intFromString[A](implicit fromThrowable: ErrorFromThrowable[A]): FromString[Int, A] = factory( - s => - Try(s.toInt) match { - case Success(int) => Right(int) - case Failure(exception) => Left(fromThrowable.fromThrowable(exception)) - } + implicit def intFromString[A](implicit fromThrowable: ErrorFromThrowable[A]): FromString[Int, A] = factory(s => + Try(s.toInt) match { + case Success(int) => Right(int) + case Failure(exception) => Left(fromThrowable.fromThrowable(exception)) + } ) - implicit def doubleFromString[A](implicit fromThrowable: ErrorFromThrowable[A]): FromString[Double, A] = factory( - s => - Try(s.toDouble) match { - case Success(double) => Right(double) - case Failure(exception) => Left(fromThrowable.fromThrowable(exception)) - } + implicit def doubleFromString[A](implicit fromThrowable: ErrorFromThrowable[A]): FromString[Double, A] = factory(s => + Try(s.toDouble) match { + case Success(double) => Right(double) + case Failure(exception) => Left(fromThrowable.fromThrowable(exception)) + } ) - implicit def booleanFromString[A](implicit fromThrowable: ErrorFromThrowable[A]): FromString[Boolean, A] = factory( - s => + implicit def booleanFromString[A](implicit fromThrowable: ErrorFromThrowable[A]): FromString[Boolean, A] = + factory(s => Try(s.toBoolean) match { case Success(bool) => Right(bool) case Failure(_) => Left(fromThrowable.fromThrowable(new Exception(s"$s is not a Boolean"))) } - ) + ) } diff --git a/url-dsl/src/main/scala/urldsl/vocabulary/MaybeFragment.scala b/url-dsl/src/main/scala/urldsl/vocabulary/MaybeFragment.scala index 6fa56ce..66fa0c0 100644 --- a/url-dsl/src/main/scala/urldsl/vocabulary/MaybeFragment.scala +++ b/url-dsl/src/main/scala/urldsl/vocabulary/MaybeFragment.scala @@ -1,7 +1,6 @@ package urldsl.vocabulary -/** - * Wrapper around the raw fragment part of the URL. +/** Wrapper around the raw fragment part of the URL. * * None when the URL does not contain any fragment. */ diff --git a/url-dsl/src/main/scala/urldsl/vocabulary/Param.scala b/url-dsl/src/main/scala/urldsl/vocabulary/Param.scala index c5a0869..2296310 100644 --- a/url-dsl/src/main/scala/urldsl/vocabulary/Param.scala +++ b/url-dsl/src/main/scala/urldsl/vocabulary/Param.scala @@ -14,7 +14,7 @@ object Param { .map(_.split("=").toList) .toList .collect { - case first :: Nil if first.nonEmpty => first -> "" + case first :: Nil if first.nonEmpty => first -> "" case first :: second :: Nil if first.nonEmpty => first -> second } .groupBy(_._1) diff --git a/url-dsl/src/main/scala/urldsl/vocabulary/PathMatchOutput.scala b/url-dsl/src/main/scala/urldsl/vocabulary/PathMatchOutput.scala index 9f2da0b..23416dc 100644 --- a/url-dsl/src/main/scala/urldsl/vocabulary/PathMatchOutput.scala +++ b/url-dsl/src/main/scala/urldsl/vocabulary/PathMatchOutput.scala @@ -1,12 +1,13 @@ package urldsl.vocabulary -/** - * Returned type of matching segments against a [[urldsl.language.PathSegment]]. +/** Returned type of matching segments against a [[urldsl.language.PathSegment]]. * * This is used to avoid returning an ugly tuple. * - * @param output the de-serialized element from the matching - * @param unusedSegments the segments that were not used to generate the output + * @param output + * the de-serialized element from the matching + * @param unusedSegments + * the segments that were not used to generate the output */ final case class PathMatchOutput[T](output: T, unusedSegments: List[Segment]) { def map[U](f: T => U): PathMatchOutput[U] = PathMatchOutput(f(output), unusedSegments) diff --git a/url-dsl/src/main/scala/urldsl/vocabulary/PathQueryFragmentMatching.scala b/url-dsl/src/main/scala/urldsl/vocabulary/PathQueryFragmentMatching.scala index 11e8928..d01a84a 100644 --- a/url-dsl/src/main/scala/urldsl/vocabulary/PathQueryFragmentMatching.scala +++ b/url-dsl/src/main/scala/urldsl/vocabulary/PathQueryFragmentMatching.scala @@ -2,8 +2,8 @@ package urldsl.vocabulary final case class PathQueryFragmentMatching[P, Q, F](path: P, query: Q, fragment: F) { - def extractInfo[P1, Q1]( - implicit ev1: P =:= PathMatchOutput[P1], + def extractInfo[P1, Q1](implicit + ev1: P =:= PathMatchOutput[P1], ev2: Q =:= ParamMatchOutput[Q1] ): PathQueryFragmentMatching[P1, Q1, F] = PathQueryFragmentMatching(ev1(path).output, ev2(query).output, fragment) diff --git a/url-dsl/src/test/scala-3/urldsl/vocabulary/CodecSpecFor3.scala b/url-dsl/src/test/scala-3/urldsl/vocabulary/CodecSpecFor3.scala index 253634e..6dd496a 100644 --- a/url-dsl/src/test/scala-3/urldsl/vocabulary/CodecSpecFor3.scala +++ b/url-dsl/src/test/scala-3/urldsl/vocabulary/CodecSpecFor3.scala @@ -40,4 +40,3 @@ final class CodecSpecFor3 extends munit.FunSuite { } } - diff --git a/url-dsl/src/test/scala-3/urldsl/vocabulary/FromString213Spec.scala b/url-dsl/src/test/scala-3/urldsl/vocabulary/FromString213Spec.scala index ca51851..b3c2e7e 100644 --- a/url-dsl/src/test/scala-3/urldsl/vocabulary/FromString213Spec.scala +++ b/url-dsl/src/test/scala-3/urldsl/vocabulary/FromString213Spec.scala @@ -6,18 +6,18 @@ import urldsl.errors.DummyError final class FromString3Spec extends AnyFlatSpec with Matchers { - def getTheT[T](s: String)(using fromString: FromString[T, DummyError]): Either[DummyError, T] = fromString(s) + def getTheT[T](s: String)(using fromString: FromString[T, DummyError]): Either[DummyError, T] = fromString(s) - "The FromString implicit for Numeric" should "be correctly called" in { + "The FromString implicit for Numeric" should "be correctly called" in { - getTheT[BigInt]("123456789012345678901234567890") should be( - Right(BigInt("123456789012345678901234567890")) - ) + getTheT[BigInt]("123456789012345678901234567890") should be( + Right(BigInt("123456789012345678901234567890")) + ) - getTheT[BigDecimal]("123.4") should be (Right(BigDecimal(123.4))) + getTheT[BigDecimal]("123.4") should be(Right(BigDecimal(123.4))) - getTheT[BigInt]("Hi") should be (Left(DummyError.dummyError)) + getTheT[BigInt]("Hi") should be(Left(DummyError.dummyError)) - } + } -} \ No newline at end of file +} diff --git a/url-dsl/src/test/scala/urldsl/examples/CombinedExamples.scala b/url-dsl/src/test/scala/urldsl/examples/CombinedExamples.scala index 56671f3..80194b8 100644 --- a/url-dsl/src/test/scala/urldsl/examples/CombinedExamples.scala +++ b/url-dsl/src/test/scala/urldsl/examples/CombinedExamples.scala @@ -4,16 +4,15 @@ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers import urldsl.vocabulary.{PathQueryFragmentMatching, UrlMatching} -/** - * In this class, we showcase examples of combining: - * - [[urldsl.language.PathSegment]] - * - [[urldsl.language.QueryParameters]], and - * - [[urldsl.language.Fragment]]. +/** In this class, we showcase examples of combining: + * - [[urldsl.language.PathSegment]] + * - [[urldsl.language.QueryParameters]], and + * - [[urldsl.language.Fragment]]. * * Unlike other examples, we will use the [[urldsl.errors.DummyError]] implementations. * - * When you combine these, you will end up manipulating objects that can seem nasty. However, the user experience - * of code that you actually have to write should stay pretty. + * When you combine these, you will end up manipulating objects that can seem nasty. However, the user experience of + * code that you actually have to write should stay pretty. */ //noinspection TypeAnnotation final class CombinedExamples extends AnyFlatSpec with Matchers { @@ -42,10 +41,8 @@ final class CombinedExamples extends AnyFlatSpec with Matchers { Right(PathQueryFragmentMatching((), ("stuff", List(2, 3)), "the-ref")) ) - /** - * Finally, we can combine everything. - * Note that we first have to combine a [[urldsl.language.PathSegment]] and the [[urldsl.language.QueryParameters]] - * and then add the [[urldsl.language.Fragment]]. + /** Finally, we can combine everything. Note that we first have to combine a [[urldsl.language.PathSegment]] and the + * [[urldsl.language.QueryParameters]] and then add the [[urldsl.language.Fragment]]. */ (pathPart ? queryPart).withFragment(fragmentPart).matchRawUrl(sampleUrl) should be( Right(PathQueryFragmentMatching(23, ("stuff", List(2, 3)), "the-ref")) diff --git a/url-dsl/src/test/scala/urldsl/examples/FragmentExamples.scala b/url-dsl/src/test/scala/urldsl/examples/FragmentExamples.scala index b79710c..1678194 100644 --- a/url-dsl/src/test/scala/urldsl/examples/FragmentExamples.scala +++ b/url-dsl/src/test/scala/urldsl/examples/FragmentExamples.scala @@ -5,8 +5,7 @@ import org.scalatest.matchers.should.Matchers import urldsl.errors.SimpleFragmentMatchingError import urldsl.language.Fragment -/** - * This class exposes some example of usage of the [[urldsl.language.Fragment]] class. +/** This class exposes some example of usage of the [[urldsl.language.Fragment]] class. * * The `sampleUrl` and `sampleUrlWithoutFragment` used throughout this example class is defined in the * [[urldsl.examples]] package object. @@ -17,19 +16,17 @@ final class FragmentExamples extends AnyFlatSpec with Matchers { "Some matching examples" should "work" in { - /** - * We can ask that the fragment should be some specific value. - * Note that unlike [[urldsl.language.PathSegment]], there is no "root" element and hence, we need to cast an - * element by hand into a [[urldsl.language.Fragment]]. There is still an implicit conversion, but it will be - * called only in a place where you ask for a [[urldsl.language.Fragment]] (see below) + /** We can ask that the fragment should be some specific value. Note that unlike [[urldsl.language.PathSegment]], + * there is no "root" element and hence, we need to cast an element by hand into a [[urldsl.language.Fragment]]. + * There is still an implicit conversion, but it will be called only in a place where you ask for a + * [[urldsl.language.Fragment]] (see below) */ asFragment("the-ref").matchRawUrl(sampleUrl) should be(Right(())) /** We can also ask that the fragment is present and of the desired type. */ fragment[String].matchRawUrl(sampleUrl) should be(Right("the-ref")) - /** - * We can require that the fragment is not there (which would also be the case if the url ends with #!) + /** We can require that the fragment is not there (which would also be the case if the url ends with #!) */ emptyFragment.matchRawUrl(sampleUrl) should be(Left(SimpleFragmentMatchingError.FragmentWasPresent("the-ref"))) emptyFragment.matchRawUrl(sampleUrlWithoutFragment) should be(Right(())) diff --git a/url-dsl/src/test/scala/urldsl/examples/PathSegmentExamples.scala b/url-dsl/src/test/scala/urldsl/examples/PathSegmentExamples.scala index cf1d9b2..a4dd9bc 100644 --- a/url-dsl/src/test/scala/urldsl/examples/PathSegmentExamples.scala +++ b/url-dsl/src/test/scala/urldsl/examples/PathSegmentExamples.scala @@ -5,8 +5,7 @@ import org.scalatest.matchers.should.Matchers import urldsl.errors.SimplePathMatchingError import urldsl.vocabulary.{Codec, Segment} -/** - * This class exposes some example of usage of the [[urldsl.language.PathSegment]] class. +/** This class exposes some example of usage of the [[urldsl.language.PathSegment]] class. * * The `sampleUrl` used throughout this example class is defined in the [[urldsl.examples]] package object. */ @@ -20,14 +19,12 @@ final class PathSegmentExamples extends AnyFlatSpec with Matchers { /** `root` is a "dummy" matcher which matches anything. It returns [[Unit]] when matching. */ root.matchRawUrl(sampleUrl) should be(Right(())) - /** - * Appending a specific segment value to the root in order to match the first segment. - * It returns Unit when matching, since we assume that the information is already known (it's "foo"). + /** Appending a specific segment value to the root in order to match the first segment. It returns Unit when + * matching, since we assume that the information is already known (it's "foo"). */ (root / "foo").matchRawUrl(sampleUrl) should be(Right(())) - /** - * Appending a [[String]] segmennt in order to retrieve the information contained in the first segment. + /** Appending a [[String]] segmennt in order to retrieve the information contained in the first segment. */ (root / segment[String]).matchRawUrl(sampleUrl) should be(Right("foo")) @@ -44,13 +41,12 @@ final class PathSegmentExamples extends AnyFlatSpec with Matchers { Right(("foo", 23, true)) ) - /** - * You can compose things the way you like, "pre-computing" segments. + /** You can compose things the way you like, "pre-computing" segments. * - * The `/` operator is *associative*, which means that the "place where you put parenthesis" doesn't matter. In - * the same way that (3+4)+5 = 3+(4+5), you have that `(s1 / s2) / s3 = s1 / (s2 / s3)`. Note that they won't be - * equal as Scala objects, but they will be for any (relevant) observable behaviour. (Technical note: it's not - * entirely true if you go crazy in tupling things.) + * The `/` operator is *associative*, which means that the "place where you put parenthesis" doesn't matter. In the + * same way that (3+4)+5 = 3+(4+5), you have that `(s1 / s2) / s3 = s1 / (s2 / s3)`. Note that they won't be equal + * as Scala objects, but they will be for any (relevant) observable behaviour. (Technical note: it's not entirely + * true if you go crazy in tupling things.) */ val s1 = segment[String] val s2 = segment[Int] @@ -60,7 +56,9 @@ final class PathSegmentExamples extends AnyFlatSpec with Matchers { /** You can also "group" several segments into a more meaningful class than a pair or a triplet. */ case class Stuff(str: String, j: Int) - (s1 / s2).as((t: (String, Int)) => Stuff(t._1, t._2), (s: Stuff) => s match { case Stuff(str, j) => (str, j) }).matchRawUrl(sampleUrl) should be( + (s1 / s2) + .as((t: (String, Int)) => Stuff(t._1, t._2), (s: Stuff) => s match { case Stuff(str, j) => (str, j) }) + .matchRawUrl(sampleUrl) should be( Right(Stuff("foo", 23)) ) @@ -80,21 +78,18 @@ final class PathSegmentExamples extends AnyFlatSpec with Matchers { ) ) - /** - * As you probably noticed, [[urldsl.language.PathSegment]] are immutable objects and hence, can be reused freely. + /** As you probably noticed, [[urldsl.language.PathSegment]] are immutable objects and hence, can be reused freely. */ (s1 / s1).matchRawUrl(sampleUrl) should be(Right("foo", "23")) - /** - * You also have the ability to compose [[urldsl.language.PathSegment]] "horizontally", by "branching" several + /** You also have the ability to compose [[urldsl.language.PathSegment]] "horizontally", by "branching" several * possibilities */ (root / (segment[Int] || segment[String])).matchRawUrl(sampleUrl) should be(Right(Right("foo"))) - /** - * The [[urldsl.language.PathSegment]] trait is also very general, and while part of its power comes from its - * great "composability", it also comes from its ability to make quite generic things. - * One example is imposing that the path has ended. + /** The [[urldsl.language.PathSegment]] trait is also very general, and while part of its power comes from its great + * "composability", it also comes from its ability to make quite generic things. One example is imposing that the + * path has ended. */ (root / "foo" / 23 / true / endOfSegments).matchRawUrl(sampleUrl) should be(Right(())) (root / "foo" / endOfSegments).matchRawUrl(sampleUrl) should be( @@ -133,16 +128,17 @@ final class PathSegmentExamples extends AnyFlatSpec with Matchers { ) /** Flattening of int-tuple segment with [[app.tulz.tuplez.Composition]] */ - (root / segment[String] / segment[(Int, Int)] / "hey").matchPath("hello/22-33/hey") should be(Right("hello", 22, 33)) + (root / segment[String] / segment[(Int, Int)] / "hey").matchPath("hello/22-33/hey") should be( + Right("hello", 22, 33) + ) } "Some generating examples" should "work" in { - /** - * You can also use [[urldsl.language.PathSegment]]s for generating paths. - * Note that the strength of urldsl is that the `createPart` method is typesafe and knows what the path expects - * as information in order to generate the path string. + /** You can also use [[urldsl.language.PathSegment]]s for generating paths. Note that the strength of urldsl is that + * the `createPart` method is typesafe and knows what the path expects as information in order to generate the path + * string. */ (root / segment[String] / segment[Int] / "hey").createPart(("hello", 22)) should be("hello/22/hey") diff --git a/url-dsl/src/test/scala/urldsl/examples/QueryParamsExamples.scala b/url-dsl/src/test/scala/urldsl/examples/QueryParamsExamples.scala index 0497803..63f8fb6 100644 --- a/url-dsl/src/test/scala/urldsl/examples/QueryParamsExamples.scala +++ b/url-dsl/src/test/scala/urldsl/examples/QueryParamsExamples.scala @@ -5,8 +5,7 @@ import org.scalatest.matchers.should.Matchers import urldsl.errors.SimpleParamMatchingError import urldsl.language.QueryParameters -/** - * This class exposes some example of usage of the [[urldsl.language.QueryParameters]] class. +/** This class exposes some example of usage of the [[urldsl.language.QueryParameters]] class. * * The `sampleUrl` used throughout this example class is defined in the [[urldsl.examples]] package object. */ @@ -16,9 +15,8 @@ final class QueryParamsExamples extends AnyFlatSpec with Matchers { "Some matching examples" should "work" in { - /** - * You can match a simple information from the query parameter. - * This param will look for the parameter "bar" in the query string. + /** You can match a simple information from the query parameter. This param will look for the parameter "bar" in the + * query string. */ param[String]("bar").matchRawUrl(sampleUrl) should be(Right("stuff")) @@ -34,10 +32,8 @@ final class QueryParamsExamples extends AnyFlatSpec with Matchers { /** Parameter encoding a tuple */ param[(Int, Int)]("tuple").matchRawUrl(sampleUrl) should be(Right((11, 22))) - /** - * Sometimes parameters are actually a list of parameters with the same key. You can read this as well. - * Note that we sort the list for the check, since the actual order is somewhat unpredictable (although - * deterministic). + /** Sometimes parameters are actually a list of parameters with the same key. You can read this as well. Note that + * we sort the list for the check, since the actual order is somewhat unpredictable (although deterministic). */ listParam[Int]("other").matchRawUrl(sampleUrl).map(_.sorted) should be(Right(List(2, 3))) @@ -57,9 +53,7 @@ final class QueryParamsExamples extends AnyFlatSpec with Matchers { Right(("other stuff", "stuff")) ) - - /** - * If you want your parameters to match optionally, you can ascribe your [[urldsl.language.QueryParameters]] with + /** If you want your parameters to match optionally, you can ascribe your [[urldsl.language.QueryParameters]] with * `.?`. */ param[String]("does-not-exist").?.matchRawUrl(sampleUrl) should be(Right(None)) @@ -72,8 +66,7 @@ final class QueryParamsExamples extends AnyFlatSpec with Matchers { param[Int]("bar").?.matchRawUrl(sampleUrl) should be(Right(None)) param[Int]("empty").?.matchRawUrl(sampleUrl) should be(Right(None)) - /** - * [[urldsl.language.QueryParameters]] have a filter method allowing to restrict the things it matches. + /** [[urldsl.language.QueryParameters]] have a filter method allowing to restrict the things it matches. */ param[String]("bar").filter(_.length > 3, _ => "too short").matchRawUrl(sampleUrl) should be( Right( @@ -87,9 +80,8 @@ final class QueryParamsExamples extends AnyFlatSpec with Matchers { ) ) - /** - * The filter and ? combinators can be conveniently combined together. - * This is because ? erases any previously encountered error and returns None. + /** The filter and ? combinators can be conveniently combined together. This is because ? erases any previously + * encountered error and returns None. */ param[String]("bar") .filter(_.length > 10, _ => SimpleParamMatchingError.FromThrowable(new RuntimeException("too short"))) @@ -114,8 +106,7 @@ final class QueryParamsExamples extends AnyFlatSpec with Matchers { Left(true) ) - /** - * [[urldsl.language.QueryParameters]] are immutable objects, but used in a single parameter search, this fact is + /** [[urldsl.language.QueryParameters]] are immutable objects, but used in a single parameter search, this fact is * probably often useless. However, you can re-use it to combine with other parameters. */ val p = param[Int]("other") @@ -142,7 +133,8 @@ final class QueryParamsExamples extends AnyFlatSpec with Matchers { listParam[String]("p1").createPart(Nil) should be("") /** Flatenning of tuple param */ - (param[String]("p1") & param[(Int, Int)]("p2") & listParam[String]("p3")).createPart(("hey", 11, 22, List("one", "two"))) should be( + (param[String]("p1") & param[(Int, Int)]("p2") & listParam[String]("p3")) + .createPart(("hey", 11, 22, List("one", "two"))) should be( """p1=hey&p2=11-22&p3=one&p3=two""" ) diff --git a/url-dsl/src/test/scala/urldsl/examples/RouterUseCaseExample.scala b/url-dsl/src/test/scala/urldsl/examples/RouterUseCaseExample.scala index ff858f7..6a2895c 100644 --- a/url-dsl/src/test/scala/urldsl/examples/RouterUseCaseExample.scala +++ b/url-dsl/src/test/scala/urldsl/examples/RouterUseCaseExample.scala @@ -5,13 +5,12 @@ import org.scalatest.matchers.should.Matchers import urldsl.language.UrlPart.SimpleUrlPart import urldsl.vocabulary.{PathQueryFragmentMatching, UrlMatching} -/** - * This class shows a possible implementation of a Router. This could be used in a web frontend (using Scala.js) for +/** This class shows a possible implementation of a Router. This could be used in a web frontend (using Scala.js) for * displaying the correct component, or in a web server for triggering the action corresponding to the calling route. * - * All abstract models are actually instances of [[urldsl.language.UrlPart]], which easily allows to abstract away - * the concrete choice the user could make as to how they want to match the URL. In this case, we will simply return - * a value based on what was extracted from the route. This value will be an instance of the + * All abstract models are actually instances of [[urldsl.language.UrlPart]], which easily allows to abstract away the + * concrete choice the user could make as to how they want to match the URL. In this case, we will simply return a + * value based on what was extracted from the route. This value will be an instance of the * [[urldsl.examples.RouterUseCaseExample#Output]], so that we can easily test that the correct route was called. * * We use the [[urldsl.errors.DummyError]] implementations since we really want to route correctly, we don't care about @@ -25,7 +24,9 @@ final class RouterUseCaseExample extends AnyFlatSpec with Matchers { import urldsl.language.dummyErrorImpl._ - /** Link a [[urldsl.language.UrlPart]] matching some routes, to an action using the information extracted from the route. */ + /** Link a [[urldsl.language.UrlPart]] matching some routes, to an action using the information extracted from the + * route. + */ sealed trait Route[T] { def urlPart: SimpleUrlPart[T] def action(t: T): Output @@ -43,14 +44,13 @@ final class RouterUseCaseExample extends AnyFlatSpec with Matchers { /** Collection of [[Route]] to be tried in order when calling with a given url. */ case class Router(routes: List[Route[_]]) { - /** - * Sequentially tries to match the given url with all the routes, and call the action of the first matching. + /** Sequentially tries to match the given url with all the routes, and call the action of the first matching. */ def maybeCallAction(rawUrl: String): Option[Output] = routes.view .map(_(rawUrl)) - .collectFirst { - case Some(output) => output + .collectFirst { case Some(output) => + output } /** Same as maybeCallAction with a default output when no match is found. */ @@ -70,14 +70,14 @@ final class RouterUseCaseExample extends AnyFlatSpec with Matchers { /** Definition of the router, with in-order defined routes. */ val theRouter = Router( Route(root / endOfSegments)(_ => Output("home")), - Route((root / "users").withFragment(fragment[String]).fragmentOnly)( - (ref: String) => Output(s"Users view with fragment $ref") + Route((root / "users").withFragment(fragment[String]).fragmentOnly)((ref: String) => + Output(s"Users view with fragment $ref") ), Route(((root / "admin") ? param[String]("username")).withFragment(fragment[String])) { case PathQueryFragmentMatching(_, query, f) => Output(s"Admin view for $query at $f") }, - Route((root / "admin") ? param[String]("username")) { - case UrlMatching(_, username) => Output(s"Welcome, $username") + Route((root / "admin") ? param[String]("username")) { case UrlMatching(_, username) => + Output(s"Welcome, $username") }, Route(root / "admin")(_ => Output("admin view.")), Route(notFound)(_ => Output("not found")) diff --git a/url-dsl/src/test/scala/urldsl/examples/package.scala b/url-dsl/src/test/scala/urldsl/examples/package.scala index c0910b2..b097ff8 100644 --- a/url-dsl/src/test/scala/urldsl/examples/package.scala +++ b/url-dsl/src/test/scala/urldsl/examples/package.scala @@ -5,35 +5,34 @@ import urldsl.vocabulary.{FromString, Printer} import scala.util.{Failure, Success, Try} -/** - * This package shows examples of usage of url-dsl. +/** This package shows examples of usage of url-dsl. * - * When using url-dsl, you are free to chose any error adt system that you want. There are two - * built-in for you, the [[urldsl.errors.SimplePathMatchingError]] (and siblings) and the - * [[urldsl.errors.DummyError]]. We will use the former in these example. The latter being perfect - * in cases where you don't care about what caused the error (for example a router) or when you use primarily - * url-dsl for generating urls, and not for parsing them. + * When using url-dsl, you are free to chose any error adt system that you want. There are two built-in for you, the + * [[urldsl.errors.SimplePathMatchingError]] (and siblings) and the [[urldsl.errors.DummyError]]. We will use the + * former in these example. The latter being perfect in cases where you don't care about what caused the error (for + * example a router) or when you use primarily url-dsl for generating urls, and not for parsing them. */ package object examples { - val sampleUrl = "http://www.some-domain.be/foo/23/true?bar=stuff&babar=other%20stuff&other=2&other=3&tuple=11-22&empty=&ok=true#the-ref" + val sampleUrl = + "http://www.some-domain.be/foo/23/true?bar=stuff&babar=other%20stuff&other=2&other=3&tuple=11-22&empty=&ok=true#the-ref" val sampleUrlWithoutFragment = "http://www.some-domain.be/foo/23/true?bar=stuff&babar=other%20stuff&other=2&other=3&ok=true" - implicit def intTupleFromDashedString[A]( - implicit fromThrowable: ErrorFromThrowable[A] + implicit def intTupleFromDashedString[A](implicit + fromThrowable: ErrorFromThrowable[A] ): FromString[(Int, Int), A] = FromString.factory { s => Try { val parts = s.split("-") (parts(0).toInt, parts(1).toInt) } match { case Success((int1, int2)) => Right((int1, int2)) - case Failure(exception) => Left(fromThrowable.fromThrowable(exception)) + case Failure(exception) => Left(fromThrowable.fromThrowable(exception)) } } - implicit def intTupleDashedPrinter: Printer[(Int, Int)] = Printer.factory { - case (int1, int2) => int1.toString + "-" + int2.toString + implicit def intTupleDashedPrinter: Printer[(Int, Int)] = Printer.factory { case (int1, int2) => + int1.toString + "-" + int2.toString } } diff --git a/url-dsl/src/test/scala/urldsl/language/FragmentProperties.scala b/url-dsl/src/test/scala/urldsl/language/FragmentProperties.scala index a96240d..8ccbb17 100644 --- a/url-dsl/src/test/scala/urldsl/language/FragmentProperties.scala +++ b/url-dsl/src/test/scala/urldsl/language/FragmentProperties.scala @@ -10,7 +10,7 @@ import scala.util.Try //noinspection TypeAnnotation abstract class FragmentProperties[E](val impl: FragmentImpl[E], val error: FragmentMatchingError[E], name: String)( - implicit errorFromThrowable: ErrorFromThrowable[E] + implicit errorFromThrowable: ErrorFromThrowable[E] ) extends Properties(name) { import impl._ @@ -42,7 +42,7 @@ abstract class FragmentProperties[E](val impl: FragmentImpl[E], val error: Fragm property("Generating maybeFragment when defined is the same as fragment") = forAll(Gen.option(Gen.asciiStr)) { (str: Option[String]) => maybeStringFragment.createPart(str) == (str match { - case None => "" + case None => "" case Some(s) => stringFragment.createPart(s) }) @@ -119,7 +119,10 @@ abstract class FragmentProperties[E](val impl: FragmentImpl[E], val error: Fragm Prop( intFragment - .filter(predicate, _ => ErrorFromThrowable[E].fromThrowable(new IllegalArgumentException("Non positive number"))) + .filter( + predicate, + _ => ErrorFromThrowable[E].fromThrowable(new IllegalArgumentException("Non positive number")) + ) .as[PosInt] .? .matchFragment(MaybeFragment(maybeX.map(_.toString))) == Right(maybeX.filter(predicate).map(PosInt.apply)) @@ -128,24 +131,33 @@ abstract class FragmentProperties[E](val impl: FragmentImpl[E], val error: Fragm ) } - property("Get or else on positive ints caps to 1") = forAll(Gen.option(Gen.choose(-1000, 1000))) { (maybeX: Option[Int]) => - case class PosInt(value: Int) - val one = PosInt(1) + property("Get or else on positive ints caps to 1") = forAll(Gen.option(Gen.choose(-1000, 1000))) { + (maybeX: Option[Int]) => + case class PosInt(value: Int) + val one = PosInt(1) - implicit def codec: Codec[Int, PosInt] = Codec.factory(PosInt.apply, _.value) + implicit def codec: Codec[Int, PosInt] = Codec.factory(PosInt.apply, _.value) - val predicate: Int => Boolean = _ > 0 + val predicate: Int => Boolean = _ > 0 - val fragment = intFragment - .filter(predicate, _ => ErrorFromThrowable[E].fromThrowable(new IllegalArgumentException("Non positive number"))) - .as[PosInt] - .?.getOrElse(one) - - Prop( - fragment.matchFragment(MaybeFragment(maybeX.map(_.toString))) == Right(maybeX.filter(predicate).map(PosInt.apply).getOrElse(one)) - ) && Prop( - fragment.createFragment(maybeX.fold(one)(PosInt.apply)) == MaybeFragment(maybeX.map(_.toString).orElse(Some("1"))) - ) + val fragment = intFragment + .filter( + predicate, + _ => ErrorFromThrowable[E].fromThrowable(new IllegalArgumentException("Non positive number")) + ) + .as[PosInt] + .? + .getOrElse(one) + + Prop( + fragment.matchFragment(MaybeFragment(maybeX.map(_.toString))) == Right( + maybeX.filter(predicate).map(PosInt.apply).getOrElse(one) + ) + ) && Prop( + fragment.createFragment(maybeX.fold(one)(PosInt.apply)) == MaybeFragment( + maybeX.map(_.toString).orElse(Some("1")) + ) + ) } } diff --git a/url-dsl/src/test/scala/urldsl/language/PathSegmentDummyErrorProperties.scala b/url-dsl/src/test/scala/urldsl/language/PathSegmentDummyErrorProperties.scala index 013a9f0..183d500 100644 --- a/url-dsl/src/test/scala/urldsl/language/PathSegmentDummyErrorProperties.scala +++ b/url-dsl/src/test/scala/urldsl/language/PathSegmentDummyErrorProperties.scala @@ -1,10 +1,10 @@ package urldsl.language - import org.scalacheck.Gen import org.scalacheck.Prop.forAll import urldsl.errors.DummyError.dummyErrorIsPathMatchingError -final class PathSegmentDummyErrorProperties extends PathSegmentProperties(dummyErrorImpl, dummyErrorIsPathMatchingError, "PathSegmentDummyError") { +final class PathSegmentDummyErrorProperties + extends PathSegmentProperties(dummyErrorImpl, dummyErrorIsPathMatchingError, "PathSegmentDummyError") { import dummyErrorImpl._ @@ -12,5 +12,4 @@ final class PathSegmentDummyErrorProperties extends PathSegmentProperties(dummyE segment[Int].filter(_ < 0).createPath(x) == x.toString } - } diff --git a/url-dsl/src/test/scala/urldsl/language/PathSegmentProperties.scala b/url-dsl/src/test/scala/urldsl/language/PathSegmentProperties.scala index d6ffc90..e3143e0 100644 --- a/url-dsl/src/test/scala/urldsl/language/PathSegmentProperties.scala +++ b/url-dsl/src/test/scala/urldsl/language/PathSegmentProperties.scala @@ -35,9 +35,16 @@ abstract class PathSegmentProperties[E](val impl: PathSegmentImpl[E], val error: property("generic unary path segment can be called") = forAll { (x: Int, s: String) => implicit def - : PathMatchingError[E] = error val path = PathSegment.unaryPathSegment[Int, E](x) / PathSegment.unaryPathSegment[String, E](s) - Prop(path.matchSegments(List( - Segment(x.toString), Segment(s) - )).map(_.output) == Right(())) && (Prop(s.nonEmpty) ==> Prop( + Prop( + path + .matchSegments( + List( + Segment(x.toString), + Segment(s) + ) + ) + .map(_.output) == Right(()) + ) && (Prop(s.nonEmpty) ==> Prop( path.createPath() == s"$x/${UrlStringGenerator.default.encode(s)}" )) :| s"""Expected: $x/${UrlStringGenerator.default.encode(s)} @@ -108,7 +115,9 @@ abstract class PathSegmentProperties[E](val impl: PathSegmentImpl[E], val error: property("oneOfValuesMatches") = forAllNoShrink(Gen.nonEmptyListOf(segmentGen)) { (ls: List[Segment]) => val path = $ / oneOf[String](ls.head.content, ls.tail.map(_.content): _*) - ls.forall(s => path.matchSegments(List(s)).isRight) && (Prop(path.createPath() == UrlStringGenerator.default.encode(ls.head.content)) :| + ls.forall(s => path.matchSegments(List(s)).isRight) && (Prop( + path.createPath() == UrlStringGenerator.default.encode(ls.head.content) + ) :| s"""Obtained: ${path.createPath()} |Expected: ${UrlStringGenerator.default.encode(ls.head.content)} |""".stripMargin) @@ -140,15 +149,16 @@ abstract class PathSegmentProperties[E](val impl: PathSegmentImpl[E], val error: segment[Int].filter(_ < 0, _ => error.malformed(s"$x should be negative")).createPath(x) == x.toString } - property("Or operator can target both types") = forAll(Gen.choose(-100, 100), Gen.alphaNumStr) { (x: Int, s: String) => - val path = segment[Int] || segment[String] + property("Or operator can target both types") = forAll(Gen.choose(-100, 100), Gen.alphaNumStr) { + (x: Int, s: String) => + val path = segment[Int] || segment[String] - Prop(Try(s.toInt).isFailure) ==> { - // noinspection ComparingUnrelatedTypes - Prop(path.matchSegments(List(x.toString)) == Right(PathMatchOutput(Left(x), Nil))) && Prop( - path.matchSegments(List(s)) == Right(PathMatchOutput(Right(s), Nil)) - ) && Prop(path.createPath(Left(x)) == x.toString) && Prop(path.createPath(Right(s)) == s) - } + Prop(Try(s.toInt).isFailure) ==> { + // noinspection ComparingUnrelatedTypes + Prop(path.matchSegments(List(x.toString)) == Right(PathMatchOutput(Left(x), Nil))) && Prop( + path.matchSegments(List(s)) == Right(PathMatchOutput(Right(s), Nil)) + ) && Prop(path.createPath(Left(x)) == x.toString) && Prop(path.createPath(Right(s)) == s) + } } property("Bijection works with container") = forAll { (x: Int) => diff --git a/url-dsl/src/test/scala/urldsl/language/PathSegmentSimpleErrorProperties.scala b/url-dsl/src/test/scala/urldsl/language/PathSegmentSimpleErrorProperties.scala index f856286..a904b66 100644 --- a/url-dsl/src/test/scala/urldsl/language/PathSegmentSimpleErrorProperties.scala +++ b/url-dsl/src/test/scala/urldsl/language/PathSegmentSimpleErrorProperties.scala @@ -3,6 +3,9 @@ package urldsl.language import urldsl.errors.DummyError.dummyErrorIsPathMatchingError import urldsl.errors.SimplePathMatchingError -final class PathSegmentSimpleErrorProperties extends PathSegmentProperties(simpleErrorImpl, SimplePathMatchingError.pathMatchingError, "PathSegmentSimpleError") { - -} +final class PathSegmentSimpleErrorProperties + extends PathSegmentProperties( + simpleErrorImpl, + SimplePathMatchingError.pathMatchingError, + "PathSegmentSimpleError" + ) {} diff --git a/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsChecks.scala b/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsChecks.scala index 56a072a..2eae9b7 100644 --- a/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsChecks.scala +++ b/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsChecks.scala @@ -13,7 +13,7 @@ abstract class PathSegmentWithQueryParamsChecks[P, Q, F]( pErrorFromThrowable: ErrorFromThrowable[P], qErrorFromThrowable: ErrorFromThrowable[Q], fErrorFromThrowable: ErrorFromThrowable[F], - pPathMatchingError: PathMatchingError[P] + pPathMatchingError: PathMatchingError[P] ) extends Properties(name) { import impl._ diff --git a/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsDummyErrorChecks.scala b/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsDummyErrorChecks.scala index 8d8d7fa..61a1d93 100644 --- a/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsDummyErrorChecks.scala +++ b/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsDummyErrorChecks.scala @@ -1,7 +1,4 @@ package urldsl.language -final class PathSegmentWithQueryParamsDummyErrorChecks extends PathSegmentWithQueryParamsChecks(dummyErrorImpl, "PathSegmentWithQueryParamsDummyErrorChecks") { - - - -} +final class PathSegmentWithQueryParamsDummyErrorChecks + extends PathSegmentWithQueryParamsChecks(dummyErrorImpl, "PathSegmentWithQueryParamsDummyErrorChecks") {} diff --git a/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsSimpleErrorChecks.scala b/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsSimpleErrorChecks.scala index 4c2390c..66094e0 100644 --- a/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsSimpleErrorChecks.scala +++ b/url-dsl/src/test/scala/urldsl/language/PathSegmentWithQueryParamsSimpleErrorChecks.scala @@ -1,5 +1,4 @@ package urldsl.language -final class PathSegmentWithQueryParamsSimpleErrorChecks extends PathSegmentWithQueryParamsChecks(simpleErrorImpl, "PathSegmentWithQueryParamsSimpleErrorChecks") { - -} +final class PathSegmentWithQueryParamsSimpleErrorChecks + extends PathSegmentWithQueryParamsChecks(simpleErrorImpl, "PathSegmentWithQueryParamsSimpleErrorChecks") {} diff --git a/url-dsl/src/test/scala/urldsl/language/QueryParameterProperties.scala b/url-dsl/src/test/scala/urldsl/language/QueryParameterProperties.scala index da52b0b..d81bfa1 100644 --- a/url-dsl/src/test/scala/urldsl/language/QueryParameterProperties.scala +++ b/url-dsl/src/test/scala/urldsl/language/QueryParameterProperties.scala @@ -44,8 +44,10 @@ final class QueryParameterProperties extends Properties("QueryParameters") { val intParam = param[Int]("x").filter(predicate) - Prop(intParam.matchParams(params) == - (if (predicate(x)) Right(ParamMatchOutput(x, Map())) else Left(DummyError.dummyError))) && Prop( + Prop( + intParam.matchParams(params) == + (if (predicate(x)) Right(ParamMatchOutput(x, Map())) else Left(DummyError.dummyError)) + ) && Prop( intParam.createParams(x) == params ) } diff --git a/url-dsl/src/test/scala/urldsl/language/QueryParameterSpec.scala b/url-dsl/src/test/scala/urldsl/language/QueryParameterSpec.scala index 773cf44..3c32096 100644 --- a/url-dsl/src/test/scala/urldsl/language/QueryParameterSpec.scala +++ b/url-dsl/src/test/scala/urldsl/language/QueryParameterSpec.scala @@ -11,7 +11,10 @@ final class QueryParameterSpec extends munit.FunSuite { import impl._ test("Matching the empty list works") { - assertEquals(listParam[Int]("my-list").matchParams(Map("my-list" -> Param(Nil))), Right(ParamMatchOutput(List.empty[Int], Map.empty))) + assertEquals( + listParam[Int]("my-list").matchParams(Map("my-list" -> Param(Nil))), + Right(ParamMatchOutput(List.empty[Int], Map.empty)) + ) } test("Matching single element when list of param is empty fails") { diff --git a/url-dsl/src/test/scala/urldsl/language/QueryParamsUrlSpec.scala b/url-dsl/src/test/scala/urldsl/language/QueryParamsUrlSpec.scala index ed7041d..b0da916 100644 --- a/url-dsl/src/test/scala/urldsl/language/QueryParamsUrlSpec.scala +++ b/url-dsl/src/test/scala/urldsl/language/QueryParamsUrlSpec.scala @@ -29,7 +29,7 @@ final class QueryParamsUrlSpec extends AnyFlatSpec with Matchers { (param[String]("name") & param[Int]("age").?).params("Hello", Some(1)) should be("name=Hello&age=1") (param[String]("name") & param[String]("cat").?).params("Hello", Some("")) should be("name=Hello&cat=") (param[String]("name") & param[String]("cat").?).params("Hello", Some("Fluffy")) should be("name=Hello&cat=Fluffy") - + // demonstrates quasi commutativity (listParam[Int]("ages") & param[String]("name")).params(List(32, 23), "Bob") should be( "ages=32&ages=23&name=Bob" diff --git a/url-dsl/src/test/scala/urldsl/vocabulary/FromStringChecks.scala b/url-dsl/src/test/scala/urldsl/vocabulary/FromStringChecks.scala index d166150..70cc6b1 100644 --- a/url-dsl/src/test/scala/urldsl/vocabulary/FromStringChecks.scala +++ b/url-dsl/src/test/scala/urldsl/vocabulary/FromStringChecks.scala @@ -14,7 +14,8 @@ object FromStringChecks extends Properties("FromStringChecks") { property("Decoding non-boolean string leads to error") = forAll(Gen.asciiStr) { (s: String) => Try(s.toBoolean) match { - case Failure(throwable) => FromString[Boolean, DummyError].fromString(s) == Left(ErrorFromThrowable[DummyError].fromThrowable(throwable)) + case Failure(throwable) => + FromString[Boolean, DummyError].fromString(s) == Left(ErrorFromThrowable[DummyError].fromThrowable(throwable)) case Success(_) => true } } diff --git a/url-dsl/src/test/scala/urldsl/vocabulary/PrinterChecks.scala b/url-dsl/src/test/scala/urldsl/vocabulary/PrinterChecks.scala index e008e35..19e9827 100644 --- a/url-dsl/src/test/scala/urldsl/vocabulary/PrinterChecks.scala +++ b/url-dsl/src/test/scala/urldsl/vocabulary/PrinterChecks.scala @@ -10,12 +10,18 @@ object PrinterChecks extends Properties("PrinterChecks") { def checkPrinterToString[T](t: T, printer: Printer[T]): Prop = Prop(t.toString == printer(t)) property("strings are printed as is") = forAll(someStringGen)(checkPrinterToString(_, Printer.stringPrinter)) - property("ints are printed with toString") = forAll(Arbitrary.arbitrary[Int])(checkPrinterToString(_, Printer.intPrinter)) - property("longs are printed with toString") = forAll(Arbitrary.arbitrary[Long])(checkPrinterToString(_, Printer.longPrinter)) - property("booleans are printed with toString") = forAll(Gen.oneOf(true, false))(checkPrinterToString(_, Printer.booleanPrinter)) - property("doubles are printed with toString") = forAll(Arbitrary.arbitrary[Double])(checkPrinterToString(_, Printer.doublePrinter)) - property("big intss are printed with toString") = forAll(Arbitrary.arbitrary[BigInt])(checkPrinterToString(_, Printer.bigIntPrinter)) - property("floats are printed with toString") = forAll(Arbitrary.arbitrary[Float])(checkPrinterToString(_, Printer.floatPrinter)) + property("ints are printed with toString") = + forAll(Arbitrary.arbitrary[Int])(checkPrinterToString(_, Printer.intPrinter)) + property("longs are printed with toString") = + forAll(Arbitrary.arbitrary[Long])(checkPrinterToString(_, Printer.longPrinter)) + property("booleans are printed with toString") = + forAll(Gen.oneOf(true, false))(checkPrinterToString(_, Printer.booleanPrinter)) + property("doubles are printed with toString") = + forAll(Arbitrary.arbitrary[Double])(checkPrinterToString(_, Printer.doublePrinter)) + property("big intss are printed with toString") = + forAll(Arbitrary.arbitrary[BigInt])(checkPrinterToString(_, Printer.bigIntPrinter)) + property("floats are printed with toString") = + forAll(Arbitrary.arbitrary[Float])(checkPrinterToString(_, Printer.floatPrinter)) property("summoner method is called") = forAll(Gen.const(()))(_ => Printer[String] != null)