trycmd
trycmd copied to clipboard
Structured data (like json, ndjson, toml, yaml) asserts in snapbox
Like the value from special handling of text vs binary, asserting with knowledge of structured data would help gloss over irrelevant details and allow smarter wildcards
- [x] json (#106)
- [x] jsonlines (#277)
- [ ] toml
A basic way of doing this is
- Have feature flags per file format
- Have path asserts check for file type and deserialize the file according to any enabled formats
- For matches, instead of equality, create structured wildcards (wildcards that match entire subsets of the data). See cargo-test-support for ideas
Besides a {..}
, should we have {VAR}
s that we deserialize and substitute?
After some discussion with @epage, we found the following blockers:
-
[x] ~~A
DataFormat
enum should be created to hold all supported data formats~~ (#109) -
[x] ~~
as_bytes
should be renamed toto_bytes
and it should outputVec<u8>
~~ (#110) -
[x] ~~A function should be created, that outputs the current
DataFormat
of theData
it is called on (format(&self) -> DataFormat
). Usage:expected.format()
~~ (#111) -
[x] ~~A
try_coerce
function should be created that takes in aDataFormat
that theData
will try to be turned into (try_coerce(self, format: DataFormat) -> Self
). If it fails to coerce into the expected data format the old one should be returned. Usage:actual.try_coerce(expected.format())
~~ (#111) -
[x] ~~calls to
try_text
inassert.rs
andpath.rs
should be updated to usetry_coerce
~~ (#111) -
[X] ~~
schema.rs
should change calls toData
tostd::fs::read_string
+ normalize the newlines~~ (#122) -
[x] ~~rename
map_text
tonormalize
. It should then take in a normalization operation / algorithm (NormalizeNewlines
,NormalizeMatches
, etc)~~ (#122) -
[x] ~~calls to
map_text
inassert.rs
andpath.rs
should instead callnormalize
~~ (#122) -
[x] ~~
as_str
should be renamed torender
and it should outputOption<String>
. The original intent of as_str was for outputting Diffs. This should be changed toString
since there are some formats that have borrowing issues with &str.~~ (#122) -
[ ] A function to detect the format of the given
Data
should be created (detect(&self, supported_formats: Vec<DataFormat>) -> DataFormat
), wheresupported_formats
is runtime coerced formats, controlled by user). Usage:expected.detect(supported_formats)