Skip to content

Commit

Permalink
Add arbitraries for numeric string
Browse files Browse the repository at this point in the history
  • Loading branch information
matwojcik committed Mar 5, 2021
1 parent b9b027b commit f905cf8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package eu.timepit.refined.scalacheck

import eu.timepit.refined.api.{Refined, RefType}
import eu.timepit.refined.api.{RefType, Refined}
import eu.timepit.refined.collection.{NonEmpty, Size}
import eu.timepit.refined.string.{EndsWith, StartsWith, Trimmed, Uuid}
import eu.timepit.refined.string._
import eu.timepit.refined.types.string.TrimmedString
import org.scalacheck.Arbitrary
import shapeless.Witness
Expand Down Expand Up @@ -42,11 +42,54 @@ trait StringInstances {
rt: RefType[F]
): Arbitrary[F[String, Uuid]] =
arbitraryRefType(Arbitrary.arbUuid.arbitrary.map(_.toString))

implicit def validByteStringArbitrary[F[_, _]](implicit
rt: RefType[F]
): Arbitrary[F[String, ValidByte]] =
arbitraryRefType(Arbitrary.arbByte.arbitrary.map(_.toString))

implicit def validShortStringArbitrary[F[_, _]](implicit
rt: RefType[F]
): Arbitrary[F[String, ValidShort]] =
arbitraryRefType(Arbitrary.arbShort.arbitrary.map(_.toString))

implicit def validIntStringArbitrary[F[_, _]](implicit
rt: RefType[F]
): Arbitrary[F[String, ValidInt]] =
arbitraryRefType(Arbitrary.arbInt.arbitrary.map(_.toString))

implicit def validLongStringArbitrary[F[_, _]](implicit
rt: RefType[F]
): Arbitrary[F[String, ValidLong]] =
arbitraryRefType(Arbitrary.arbLong.arbitrary.map(_.toString))

implicit def validFloatStringArbitrary[F[_, _]](implicit
rt: RefType[F]
): Arbitrary[F[String, ValidFloat]] =
arbitraryRefType(Arbitrary.arbFloat.arbitrary.map(_.toString))

implicit def validDoubleStringArbitrary[F[_, _]](implicit
rt: RefType[F]
): Arbitrary[F[String, ValidDouble]] =
arbitraryRefType(Arbitrary.arbDouble.arbitrary.map(_.toString))

implicit def validBigIntStringArbitrary[F[_, _]](implicit
rt: RefType[F]
): Arbitrary[F[String, ValidBigInt]] =
arbitraryRefType(Arbitrary.arbBigInt.arbitrary.map(_.toString))

implicit def validBigDecimalStringArbitrary[F[_, _]](implicit
rt: RefType[F]
): Arbitrary[F[String, ValidBigDecimal]] =
arbitraryRefType(Arbitrary.arbBigDecimal.arbitrary.map(_.toString))

}

trait StringInstancesBinCompat1 {

implicit def trimmedStringArbitrary[F[_, _]](implicit
rt: RefType[F]
): Arbitrary[F[String, Trimmed]] =
arbitraryRefType(Arbitrary.arbString.arbitrary.map(TrimmedString.trim(_).value))

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,20 @@ class StringArbitrarySpec extends Properties("StringArbitrary") {
property("NonEmptyFiniteString[10]") = checkArbitraryRefinedType[NonEmptyFiniteString[W.`10`.T]]

property("Uuid") = checkArbitraryRefinedType[String Refined Uuid]

property("ValidByte") = checkArbitraryRefinedType[String Refined ValidByte]

property("ValidShort") = checkArbitraryRefinedType[String Refined ValidShort]

property("ValidInt") = checkArbitraryRefinedType[String Refined ValidInt]

property("ValidLong") = checkArbitraryRefinedType[String Refined ValidLong]

property("ValidFloat") = checkArbitraryRefinedType[String Refined ValidFloat]

property("ValidDouble") = checkArbitraryRefinedType[String Refined ValidDouble]

property("ValidBigInt") = checkArbitraryRefinedType[String Refined ValidBigInt]

property("ValidBigDecimal") = checkArbitraryRefinedType[String Refined ValidBigDecimal]
}

0 comments on commit f905cf8

Please sign in to comment.