Junctions¶
expect(actual).to.be(expected) uses Raku smartmatch (~~) through the built-in BeMatcher. Junctions on the right-hand side of a smartmatch are first-class, so every junction form composes with expect without any extra DSL.
any — match any one alternative¶
1 2 | |
Passes when $x smartmatches at least one of the alternatives.
1 2 | |
all — match every alternative¶
1 2 | |
Passes when $x smartmatches every alternative. Mixing distinct literal values (1 & 2) is effectively unsatisfiable because a single value cannot equal two different literals — combine all with type checks, ranges, or predicates instead.
1 2 | |
one — match exactly one alternative¶
1 2 | |
Passes when exactly one alternative matches. Useful for mutually exclusive states.
none — match no alternative¶
1 | |
Passes when $x matches none of the listed values.
Negation¶
.not flips the outer result; the junction collapses to a Bool first, then .not negates it:
1 2 | |
Failure metadata¶
When a junction expectation fails, Failure.expected carries the Junction itself and Failure.given carries the actual value:
1 2 3 | |
Junction-aware diffs¶
When a junction expectation fails, the Diff: section collapses the junction to its constituent alternatives, marking each with ✓ (matched) or ✗ (didn't match), so the reader sees exactly which alternatives didn't line up with the given value:
1 2 3 4 5 6 7 8 9 | |
Each junction kind reports its own summary line:
any—none of N matched; expected at least oneall—K of N matched; expected allone—K of N matched; expected exactly onenone—K of N matched; expected zero
Under .not, the summary phrases the inverted intent (e.g. expected none under negation for negated any, expected at least one under negation for negated none), so the diff stays useful when the matcher fires through negation.
Type-object alternatives (Int | Rat) render by name; values render via .raku.
See also¶
- Matchers — the matcher role and built-ins.
- Diff Output — how the
Diff:section is constructed for non-junction shapes. - Composable Matchers —
.and/.oronMatcherobjects (object-level alternative to Raku's literal junctions).