Skip to content

Commit

Permalink
Merge pull request #918 from matwojcik/scalacheck-validlong
Browse files Browse the repository at this point in the history
Add arbitraries for numeric string
  • Loading branch information
fthomas authored Mar 7, 2021
2 parents b09a8f3 + f905cf8 commit 32ce56f
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 32ce56f

Please sign in to comment.