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
DataFormatenum should be created to hold all supported data formats~~ (#109) -
[x] ~~
as_bytesshould be renamed toto_bytesand it should outputVec<u8>~~ (#110) -
[x] ~~A function should be created, that outputs the current
DataFormatof theDatait is called on (format(&self) -> DataFormat). Usage:expected.format()~~ (#111) -
[x] ~~A
try_coercefunction should be created that takes in aDataFormatthat theDatawill 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_textinassert.rsandpath.rsshould be updated to usetry_coerce~~ (#111) -
[X] ~~
schema.rsshould change calls toDatatostd::fs::read_string+ normalize the newlines~~ (#122) -
[x] ~~rename
map_texttonormalize. It should then take in a normalization operation / algorithm (NormalizeNewlines,NormalizeMatches, etc)~~ (#122) -
[x] ~~calls to
map_textinassert.rsandpath.rsshould instead callnormalize~~ (#122) -
[x] ~~
as_strshould be renamed torenderand it should outputOption<String>. The original intent of as_str was for outputting Diffs. This should be changed toStringsince there are some formats that have borrowing issues with &str.~~ (#122) -
[ ] A function to detect the format of the given
Datashould be created (detect(&self, supported_formats: Vec<DataFormat>) -> DataFormat), wheresupported_formatsis runtime coerced formats, controlled by user). Usage:expected.detect(supported_formats)