Skip to content

Commit

Permalink
Merge pull request #1002 from andreamarcolin/topic/matches-regex-non-…
Browse files Browse the repository at this point in the history
…empty-inference

Add MatchesRegex ==> NonEmpty inference
  • Loading branch information
fthomas authored Aug 6, 2021
2 parents 853fffd + 3faf9c4 commit 0e2654d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ private[refined] trait StringInference {
): StartsWith[A] ==> StartsWith[B] =
Inference(wa.value.startsWith(wb.value), s"startsWithInference(${wa.value}, ${wb.value})")

implicit def matchesRegexNonEmptyInference[A <: String](implicit
wa: ValueOf[A]
): MatchesRegex[A] ==> NonEmpty =
Inference(!wa.value.r.matches(""), s"matchesRegexNonEmptyInference(${wa.value})")

implicit def urlNonEmptyInference: Url ==> NonEmpty =
Inference.alwaysValid("urlNonEmptyInference")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ private[refined] trait StringInference {
): StartsWith[A] ==> StartsWith[B] =
Inference(wa.value.startsWith(wb.value), s"startsWithInference(${wa.value}, ${wb.value})")

implicit def matchesRegexNonEmptyInference[A <: String](implicit
wa: Witness.Aux[A]
): MatchesRegex[A] ==> NonEmpty =
Inference(wa.value.r.findFirstIn("").isEmpty, s"matchesRegexNonEmptyInference(${wa.value})")

implicit def urlNonEmptyInference: Url ==> NonEmpty =
Inference.alwaysValid("urlNonEmptyInference")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class StringInferenceSpec extends Properties("StringInference") {
Inference[StartsWith[W.`"cde"`.T], StartsWith[W.`"de"`.T]].notValid
}

property("MatchesRegex ==> NonEmpty") = secure {
Inference[MatchesRegex[W.`".+"`.T], NonEmpty].isValid
}

property("MatchesRegex =!> NonEmpty") = secure {
Inference[MatchesRegex[W.`".*"`.T], NonEmpty].notValid
}

property("UUID ==> NonEmpty ") = secure {
Inference[Uuid, NonEmpty].isValid
}
Expand Down

0 comments on commit 0e2654d

Please sign in to comment.