niceeval/expect provides a set of composable matchers, passed to t.check() or t.require(). A matcher returns an Assertion with a default severity: gate or soft.
How matchers are used
Matchers
The signature and description of each matcher below is generated from theniceeval/expect source, and stays in sync with the current implementation.
includes
String(value) contains the substring / matches the regex, otherwise 0. A hard gate by default. With opts.stripComments, only real code is examined.
excludes
includes: 1 if it does not contain the substring / does not match the regex, otherwise 0. A hard gate by default. With opts.stripComments, only real code is examined.
equals
matches
value against a schema — this is not regex matching, it’s Standard Schema / zod-style structural validation.
Prefers Standard Schema (schema['~standard'].validate), otherwise falls back to zod-style
.safeParse / .parse. 1 if validation passes, otherwise 0; any exception → 0. A hard gate by default.
similarity
includesUrl
hasSections
satisfies
label is added to the name for easier identification in reports.
isDefined
value is not null / not undefined, otherwise 0. Saves the boilerplate of x !== undefined + isTrue. A hard gate by default.
isTrue
value === true, otherwise 0. A boolean assertion with a label (for checks like fileExists). A hard gate by default.
commandSucceeded
CommandResult.exitCode === 0, otherwise 0. A hard gate by default.
isFalse
value === false, otherwise 0. A boolean assertion with a label. A hard gate by default.
makeAssertion
ValueAssertion —
unlike gate()/atLeast(), it does not need a second chained call to set the level. severity defaults to gate when omitted.
Common usage examples
gate and soft
Assertion (i.e. ValueAssertion) returned by a matcher has these members; .gate() turns it into a hard gate, .atLeast() turns it into a soft threshold:
name
severity
threshold
isOptional
.optional(): when this assertion can’t be scored, it is only recorded as unavailable, without dragging the attempt into errored.
expected
contains "Brooklyn"), included in AssertionResult.expected on failure.
score
gate
threshold judges by score > 0), the whole eval is marked failed. Returns a new instance, does not mutate the original.
atLeast
threshold isn’t met, this assertion is recorded as failed, but by default it does not drag down the whole eval’s verdict;
under --strict, a soft-threshold failure also makes the whole eval’s verdict count as failed. Returns a new instance, does not mutate the original.
optional
outcome: "unavailable", without affecting the verdict.
Orthogonal to severity (severity determines whether it affects the quality verdict; optional determines whether evidence is allowed to be absent). Returns a new instance, does not mutate the original.
Custom matchers
makeAssertion takes a single spec object (name, optional severity/threshold, and score) and returns an Assertion directly; by convention you wrap it in a function of the same name and call that, rather than calling makeAssertion itself as the factory at the call site.