-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for type and constraint defined outside of source
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
integrations/iron/src/test/scala-3/com/example/RefinedString.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example | ||
|
||
import io.github.iltotore.iron.* | ||
import sttp.tapir.Validator | ||
import sttp.tapir.codec.iron.PrimitiveValidatorForPredicate | ||
import sttp.tapir.codec.iron.ValidatorForPredicate | ||
|
||
final class RefinedStringConstraint | ||
|
||
object RefinedStringConstraint { | ||
|
||
given Constraint[String, RefinedStringConstraint] with { | ||
|
||
override inline def test(value: String): Boolean = value.nonEmpty | ||
|
||
override inline def message: String = "Should not be empty" | ||
} | ||
|
||
given PrimitiveValidatorForPredicate[String, RefinedStringConstraint] = | ||
ValidatorForPredicate.fromPrimitiveValidator(Validator.pattern[String]("^.+")) | ||
} | ||
|
||
opaque type RefinedString = String :| RefinedStringConstraint | ||
|
||
object RefinedString extends RefinedTypeOps[String, RefinedStringConstraint, RefinedString] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters