Crates.io | veritas |
lib.rs | veritas |
version | 0.0.0 |
source | src |
created_at | 2020-11-12 21:24:34.000899 |
updated_at | 2020-11-12 21:24:34.000899 |
description | A library of composable assertions with pretty output |
homepage | |
repository | |
max_upload_size | |
id | 311756 |
size | 5,055 |
The concepts in Veritas are heavily inspired by Google's truth library.
A leaf correspondence determines whether a value T
corresponds in some way to a Pattern
.
There are two main kinds of correspondences:
T
precisely corresponds to the Pattern
. Equal
and Matches
are examples of Exact correspondences.T
corresponds to the Pattern
, within some tolerance. CloseTo
is an example of a Tolerance correspondence.A Fact
is a key-value pair that can be presented to the user as a part of the explanation for a mismatch.
There are several built-in facts which are designed to help correspondence implementations present useful error messages for the supported reporters.
Present
correspondence fails, it produces a Basic fact that renders as "is not present".T
T
and a string representation of the expected T
that should be presented as a rich diff.If a Correspondence
is not satisfied, it produces a Mismatch
. A Mismatch
contains a number of Fact
s that, together, describe the reason for the mismatch.
A Mismatch
M2
can depend on another Mismatch
M1
, which means that M2
doesn't make sense unless M1
is fixed. Normal reporters will likely only present mismatches without dependencies, while verbose reporters could present all mismatches.
Unlike many other expectation systems, mismatches in String
s are modelled as compound mismatches in Veritas. Each Fact
about a String
specifies a Range
into the String
that it refers to.
Strings have a number of special kinds of Fact
s:
Basic
fact, but applied to a specific range in the stringKey-Value
fact, but applied to a specific range in the stringCorrespondences about String
values can use the Diffable String
fact to present differences between expected and actual values.
The collection of all Fact
s about a String
creates a set of all problematic ranges in the source string.
This library is inspired by [rspec][rspec], truth, and many other test frameworks in many languages focusing on producing good error output.