bynk.val.needs_pin
Error A bare Val[T] cannot generate a value (e.g. a Matches string); pin one.
In a test, a bare Val[T] fabricates a valid value of T. It can do that for most refinements (Positive gives 1, MinLength(3) a string of length three) but not for a Matches pattern or IsoDate, so it refuses rather than guess; the same goes for a record or sum that reaches one. A for all over such a type is refused too. Pin a value, Val[Code]("abc"), which is checked against the refinement, or give the type an @example and use bare Val. See the bynk.val.* codes for pins that are not literals or do not satisfy the type.
Example
type Code = String where Matches("[a-z]+")
// tests/codes.test.bynklet c = Val[Code] // ✗ no value can be made from a patternlet c = Val[Code]("abc") // ✓ pin oneIn the Book
- Testing › Val[T] — value fabrication
- Testing › @example — a value for a pattern
- Testing
- Write tests, stub collaborators, and pin a `Val[T]`
See also
- The grammar rule it governs:
val_expr. - Every code in its category, Value fabrication, on the diagnostic index.
bynk explain bynk.val.needs_pinshows the same from the installed toolchain, without a network.